Skip to main content

Machine learning models for fMRI classification

Project description

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`
report = cvbench(DATA, LABELS, models='all', n_folds=5)

# Plot test AUC boxplots for all models
report.plot_scores()

# Save test and training dataframes as .csv, and metadata as .json
report.save()

# Access logs directly as variables
train_df = report.get_train_dataframe()
test_df  = report.get_test_dataframe()
meta     = report.get_meta()

# Inspect training curves
report.plot_training_curves()

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

Project details


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.0.7.tar.gz (92.3 kB view details)

Uploaded Source

Built Distribution

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

ml4fmri-1.0.7-py3-none-any.whl (61.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ml4fmri-1.0.7.tar.gz
  • Upload date:
  • Size: 92.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for ml4fmri-1.0.7.tar.gz
Algorithm Hash digest
SHA256 d994e4e6bbec91bffb1885926b13a1fd0ebc4e35dee6498a6336b86f05cc433a
MD5 da24120050f017cbcd57f9ba30369548
BLAKE2b-256 e18ba4425f81a1b6eaafcb1c8344ecb2808350415e2f9bf406f621bce5a938c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ml4fmri-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 61.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.11

File hashes

Hashes for ml4fmri-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e10f5af5c38e06d9c5aad102841a8a97c3b5f9bbc922e81d0f78f8e90726c33d
MD5 97bdd1db0c7c47bcabf289d3582aa594
BLAKE2b-256 d66838ad6e6433269574e817c0361a34c47228e3aef8ac4aa90f32db0ba6fe0c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page