Skip to main content

BrainPFN

BrainPFN

BrainPFN predicts behavioural, cognitive or demographic scores from resting-state functional connectivity (FC) in context. You give it a set of labelled subjects (the context) and it predicts new subjects in a single forward pass of a pretrained transformer. Nothing is trained or fine-tuned on your data, so it is fast and needs only a few labelled subjects to start with.

BrainPFN follows the scikit-learn API: fit stores the context, predict predicts.

Paper: BrainPFN: Amortized Brain-Behaviour Prediction via Prior-Data Fitted Networks (Barbano & Wassermann, 2026).

Installation

pip install brainpfn

It needs Python ≥ 3.10, PyTorch, NumPy and scikit-learn. The pretrained weights are downloaded the first time a model is fitted.

Quickstart

from brainpfn import BrainPFN

# fc_context: (n_context, 400, 400) FC matrices, y_context: (n_context,) scores
# fc_query:   (n_query, 400, 400) FC matrices of the subjects to predict
model = BrainPFN()
model.fit(fc_context, y_context)
y_pred = model.predict(fc_query)

examples/quickstart.py runs end to end on synthetic data. examples/predict_from_files.py runs on your own .npy files:

python examples/predict_from_files.py \
    --context-fc context_fc.npy --context-y context_y.npy \
    --query-fc query_fc.npy [--query-y query_y.npy]

Input data

BrainPFN expects one FC matrix per subject:

  • Parcellation: Schaefer 2018, 400 parcels. The model was pretrained with the parcels in the 7-network order.
  • Connectivity: Pearson correlation between parcel time series, as computed by nilearn's ConnectivityMeasure(kind="correlation").
from nilearn.connectome import ConnectivityMeasure

# time_series: list of (n_timepoints, 400) arrays, one per subject
fc = ConnectivityMeasure(kind="correlation").fit_transform(time_series)  # (n, 400, 400)

Pass the full (n, 400, 400) matrices, not nilearn's vectorize=True output. Internally each matrix is converted to its log-Cholesky vector (80,200 values). For large cohorts you can do the conversion once and pass the vectors instead:

from brainpfn import fc_to_logchol

X = fc_to_logchol(fc)    # (n, 80200)
model.fit(X_context, y_context).predict(X_query)

Pretrained models

variant parameters download size
"4.7M" (default) 4.7M 52 MB
"0.8M" 0.8M 36 MB
model = BrainPFN(variant="0.8M")

The weights are cached in ~/.cache/brainpfn. To use another location, set the BRAINPFN_CACHE_DIR environment variable. variant also accepts a local path to a downloaded .pt file, for machines without internet access.

Options

BrainPFN(
    variant="4.7M",       # pretrained model
    calibrate="cv",       # output calibration, see below; None to disable
    calibrate_folds=5,
    random_state=0,       # seed of the context PCA and of the calibration folds
    device=None,          # "cpu", "cuda", "mps"; default: CUDA if available, else CPU
)

Calibration. On real data, the raw network output tends to rank subjects well but shrink their predictions towards the context mean. With calibrate="cv" (the default), fit predicts each context subject from the others (5-fold) and learns a linear correction y ≈ a · ŷ + b that predict then applies. This uses the context only, and makes fit run 5 extra forward passes. It is skipped, with a warning, when the context has fewer than 2 × calibrate_folds subjects. How well it works depends on the context size: larger contexts give a more reliable correction.

Several targets. y can be (n, n_targets); predict then returns (n_query, n_targets). Missing labels (NaN) are allowed: each target is predicted from the context subjects that have a label for it.

Context size. Any context of at least 2 subjects works, but predictions get better with more context subjects.

scikit-learn. BrainPFN is a regular scikit-learn regressor, so it works with cross_val_score, cross_val_predict, GridSearchCV and so on. Each fold uses its own training split as the context:

from sklearn.model_selection import cross_val_score

scores = cross_val_score(BrainPFN(), fc, y, cv=5, scoring="r2")

Citation

If you use BrainPFN, please cite the paper:

@article{barbano2026brainpfn,
  title   = {BrainPFN: Amortized Brain-Behaviour Prediction via Prior-Data Fitted Networks},
  author  = {Barbano, Carlo Alberto and Wassermann, Demian},
  journal = {preprint},
  year    = {2026},
  month   = sep,
  url     = {https://inria.hal.science/hal-05767107}
}

License

CC BY-NC 4.0; see LICENSE.

Metadata

Release files for brainpfn 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for brainpfn 0.1.2
File Size Uploaded Provenance Actions
brainpfn-0.1.2.tar.gz 412.9 kB Without provenance Details for brainpfn-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for brainpfn 0.1.2
File Interpreter ABI Platform Actions
brainpfn-0.1.2-py3-none-any.whl Python 3 none any Details for brainpfn-0.1.2-py3-none-any.whl

Total release size: 433.9 kB

Release files / brainpfn-0.1.2.tar.gz

Download URL brainpfn-0.1.2.tar.gz
Size 412.9 kB
Tags Source
SHA-256 checksum
How to use checksums
5e537f53d5adbe70fae747927433d98d695b42e6feb612f129b67972452c480a
BLAKE2b-256 checksum
How to use checksums
752854a7f956dd93900ff48e9ac88afb12c809b0762e17d73c57a88ee7cd7671
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Release files / brainpfn-0.1.2-py3-none-any.whl

Download URL brainpfn-0.1.2-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c28196d8a26e7fef5c6606f13c737483588ac08fc673dc46361a2b1f4518af31
BLAKE2b-256 checksum
How to use checksums
283aeb7469874a69f55291ca969771f1ccc2cb2f66710364af5a193aee9c5c88
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.3

Security for brainpfn 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page