FREM on Jimura et al “mixed gambles” dataset

In this example, we use fast ensembling of regularized models (FREM) to solve a regression problem, predicting the gain level corresponding to each beta maps regressed from mixed gambles experiment. FREM uses an implicit spatial regularization through fast clustering and aggregates a high number of estimators trained on various splits of the training set, thus returning a very robust decoder at a lower computational cost than other spatially regularized methods.

To have more details, see: FREM: fast ensembling of regularized models for robust decoding.

See the dataset description for more information on the data used in this example.

Load the data from the Jimura mixed-gamble experiment

[get_dataset_dir] Dataset created in
/home/runner/nilearn_data/jimura_poldrack_2012_zmaps
[fetch_single_file] Downloading data from
https://www.nitrc.org/frs/download.php/7229/jimura_poldrack_2012_zmaps.zip ...
[_chunk_report_] Downloaded 14639104 of 104293434 bytes (14.0%%,    6.1s
remaining)
[_chunk_report_] Downloaded 29384704 of 104293434 bytes (28.2%%,    5.1s
remaining)
[_chunk_report_] Downloaded 43622400 of 104293434 bytes (41.8%%,    4.2s
remaining)
[_chunk_report_] Downloaded 58310656 of 104293434 bytes (55.9%%,    3.2s
remaining)
[_chunk_report_] Downloaded 73900032 of 104293434 bytes (70.9%%,    2.1s
remaining)
[_chunk_report_] Downloaded 89423872 of 104293434 bytes (85.7%%,    1.0s
remaining)
[_chunk_report_] Downloaded 103489536 of 104293434 bytes (99.2%%,    0.1s
remaining)
[fetch_single_file]  ...done. (9 seconds, 0 min)

[uncompress_file] Extracting data from
/home/runner/nilearn_data/jimura_poldrack_2012_zmaps/a4c8868ab5c651b8594da6f3204
ded3a/jimura_poldrack_2012_zmaps.zip...
[uncompress_file] .. done.

Fit FREM

We compare both of these models to a pipeline ensembling many models

from nilearn.decoding import FREMRegressor

frem = FREMRegressor("svr", cv=10, standardize="zscore_sample")

frem.fit(zmap_filenames, behavioral_target)
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning: Brain mask is bigger than the standard human brain. This object is probably not tuned to be used on such data.
  selector = check_feature_screening(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/sklearn/svm/_base.py:297: ConvergenceWarning: Solver terminated early (max_iter=10000).  Consider pre-processing your data with StandardScaler or MinMaxScaler.
  warnings.warn(

Visualize FREM weights

from nilearn.plotting import plot_stat_map

plot_stat_map(
    frem.coef_img_["beta"],
    title="FREM",
    display_mode="yz",
    cut_coords=[20, -2],
    threshold=0.2,
)
plot mixed gambles frem
<nilearn.plotting.displays._slicers.YZSlicer object at 0x7f7046ca0040>

We can observe that the coefficients map learnt by FREM is structured, due to the spatial regularity imposed by working on clusters and model ensembling. Although these maps have been thresholded for display, they are not sparse (i.e. almost all voxels have non-zero coefficients).

See also

other example using FREM, and related section of user guide.

Example use of TV-L1 SpaceNet

SpaceNet is another method available in Nilearn to decode with spatially sparse models. Depending on the penalty that is used, it yields either very structured maps (TV-L1) or unstructured maps (graph_net). Because of their heavy computational costs, these methods are not demonstrated on this example but you can try them easily if you have a few minutes. Example code is included below.

from nilearn.decoding import SpaceNetRegressor

# We use the regressor object since the task is to predict a continuous
# variable (gain of the gamble).

tv_l1 = SpaceNetRegressor(
    mask=mask_filename,
    penalty="tv-l1",
    eps=1e-1,  # prefer large alphas
    memory="nilearn_cache",
    n_jobs=2,
)
# tv_l1.fit(zmap_filenames, behavioral_target)
# plot_stat_map(tv_l1.coef_img_, title="TV-L1", display_mode="yz",
#               cut_coords=[20, -2])

Total running time of the script: (0 minutes 36.879 seconds)

Estimated memory usage: 2307 MB

Gallery generated by Sphinx-Gallery