Skip to main content

cvbench output example

ml4fmri

A one-line Python toolkit for fMRI classification that allows you to benchmark multiple deep learning models for fMRI analysis on your data with a single function call. While designed for fMRI time series, it can work with any temporal classification task.

Originally based on the codebase behind the NeuroImage paper "A simple but tough-to-beat baseline for fMRI time-series classification". This work was funded by the National Science Foundation grant 2112455, NIH grant R01MH123610, and in part by NIH grant R01MH129047.

Use example

You can install the package directly from PyPI:

pip install ml4fmri

Check out the 👉 Colab tutorial for a more detailed guide and ways to modify the default behavior.

# In Python, get fMRI time series DATA in shape (SAMPLES, TIME, FEATURES)
# and LABELS in shape (SAMPLES) (binary or multiclass)

from ml4fmri import cvbench  # runs CV experiments with implemented models on the given data

# Run cross-validation with all available models. See below for more info on available `models`
# Results are written to `save_dir` as the run proceeds; omit it to get a timestamped 
# ./cvbench_YYYYmmdd_HHMMSS/ directory or set to False to keep everything in memory.
report = cvbench(DATA, LABELS, models='all', n_folds=5, save_dir='my_cvbench_run')

# Plot test AUC boxplots and confusion matrices for all models
report.plot_scores()
report.plot_confusion()

# Access logs directly as variables
train_df = report.get_train_dataframe()
test_df  = report.get_test_dataframe()
pred_df  = report.get_predictions_dataframe()  # raw test-fold probabilities
meta     = report.get_meta()

# Inspect training curves
report.plot_training_curves()

Results on disk

Everything is written as the run proceeds.

my_cvbench_run/
├── cvbench_meta.json            # run configuration, seeds, environment, status
├── cvbench_train.csv            # model,fold,epoch,... per-epoch training log
├── cvbench_test.csv             # model,fold,... one row per (model, fold)
├── cvbench_predictions.csv      # model,fold,sample_id,y_true,y_pred,p_0,...,p_{C-1}
└── fold_records/
    ├── sample_order.csv         # pos,sample_id -- only written if sample_ids= was passed
    ├── fold_00/
    │   ├── indices.json         # positional train/val/test indices
    │   └── checkpoints/         # best-validation weights per model
    │       ├── meanMLP.pt
    │       └── LR.joblib
    └── fold_01/ ...
  • cvbench_predictions.csv – the raw probability for every test sample under every model, so any probability- or threshold-based metric can be recomputed afterwards.
  • cvbench_test.csv – final test metrics per model and fold, plus confusion counts, training time and parameter count. Confusion counts are named cm_true{i}_pred{j} for any number of classes.
  • cvbench_train.csv – train and validation metrics at every epoch; this is what plot_training_curves() draws.
  • cvbench_meta.json – the run's configuration, seeds and timing, plus a status field recording whether it finished.
  • fold_records/sample_order.csv – generated if you pass sample_ids= to cvbench; it maps row positions to your sample_ids in the fold records.

Set save_checkpoints=False to skip storing weights, or save_dir=False to keep results in memory only.

Available Models

You can set models input in cvbench to:

  • 'all' - (default for non-CPU) run all models,
  • 'lite' (default for CPU) – use only faster models, better for quick tests
  • 'ts' – run only time series models
  • 'fnc' – run only FNC models; FNC data is derived from input time series
  • '<model_name>' – run only the specified model (e.g. 'meanMLP'); see below for full model list
  • ['<model_name_1>', '<model_name_2>'] – run only the listed models

Time Series Models

  • "meanMLP" (Time Series)
    A simple MLP model for time series classification, surprisingly good for fMRi time series. Paper
    Code and bib item

  • "LSTM" (Time Series)
    Standard LSTM recurrent network for sequence classification.
    Paper
    Code and bib item

  • "meanLSTM" (Time Series)
    A variant of LSTM where outputs are mean-aggregated across time.
    Paper
    Code and bib item

  • "Transformer" (Time Series)
    Vanilla transformer encoder for modeling temporal dependencies in fMRI time series.
    Paper
    Code and bib item

  • "meanTransformer" (Time Series)
    Transformer with temporal mean pooling for classification.
    Paper
    Code and bib item

  • "MILC" (Time Series)
    CNN+LSTM model for fMRI time series.
    Paper
    Code and bib item

  • "BolT" (Time Series) Fused window Transformer for fMRI time series; slow but good, outperformed meanMLP on larger datasets. Paper Code and bib item

  • "DICE" (Time Series) LSTM-based connectivity estimator and classifier, works with time series. Paper Code and bib item

  • "Glacier" (Time Series) Transformer-based connectivity estimator and classifier, works with time series. Paper Code and bib item

FNC Models

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ml4fmri-1.1.0.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ml4fmri-1.1.0-py3-none-any.whl (67.7 kB view details)

Uploaded Python 3

File details

Details for the file ml4fmri-1.1.0.tar.gz.

File metadata

  • Download URL: ml4fmri-1.1.0.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ml4fmri-1.1.0.tar.gz
Algorithm Hash digest
SHA256 4748cb7994f236f24a95ede20f3fef6c9b382eb0c3be175a80a88851223e02bd
MD5 0616dd037137bd9335dfb4cb3521287f
BLAKE2b-256 41545c89176828a2457cc8b938c0e8584c720e0a28a6aae1150365373eed8bd3

See more details on using hashes here.

File details

Details for the file ml4fmri-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: ml4fmri-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 67.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for ml4fmri-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64b1b030adb77f746b64873a6567eed2a5ff72b3153299ba79b36c38264c7659
MD5 551781344d087cfc091241f6db72ae74
BLAKE2b-256 cbd3ac1a20c66d186a57203dbba2bd47ba6684127f1fdbf0f9bdbd7b36311e55

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

1.0.7

2 files

1.0.6

2 files

1.0.5

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

1.0.1

2 files

1.0.0

2 files

0.2.0

2 files

0.1.0

2 files

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