.. only:: html
.. note::
:class: sphx-glr-download-link-note
Click :ref:`here ` to download the full example code or to run this example in your browser via Binder
.. rst-class:: sphx-glr-example-title
.. _sphx_glr_auto_examples_07_advanced_plot_age_group_prediction_cross_val.py:
Functional connectivity predicts age group
==========================================
This example compares different kinds of functional connectivity between
regions of interest : correlation, partial correlation, and tangent space
embedding.
The resulting connectivity coefficients can be used to
discriminate children from adults. In general, the tangent space embedding
**outperforms** the standard correlations: see `Dadi et al 2019
`_
for a careful study.
Load brain development fMRI dataset and MSDL atlas
-------------------------------------------------------------------
We study only 60 subjects from the dataset, to save computation time.
.. code-block:: default
from nilearn import datasets
development_dataset = datasets.fetch_development_fmri(n_subjects=60)
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
Downloading data from https://osf.io/download/5c8ff3eb2286e80019c3c198/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3ed2286e80017c41b56/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3ee2286e80016c3c379/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3ee4712b400183b70c3/ ...
Downloaded 360448 of 5642114 bytes (6.4%, 14.7s remaining)
Downloaded 655360 of 5642114 bytes (11.6%, 15.3s remaining)
Downloaded 753664 of 5642114 bytes (13.4%, 20.1s remaining)
Downloaded 827392 of 5642114 bytes (14.7%, 24.4s remaining)
Downloaded 901120 of 5642114 bytes (16.0%, 27.9s remaining)
Downloaded 974848 of 5642114 bytes (17.3%, 30.7s remaining)
Downloaded 1024000 of 5642114 bytes (18.1%, 33.6s remaining)
Downloaded 1081344 of 5642114 bytes (19.2%, 37.3s remaining)
Downloaded 1146880 of 5642114 bytes (20.3%, 39.5s remaining)
Downloaded 1228800 of 5642114 bytes (21.8%, 39.9s remaining)
Downloaded 1310720 of 5642114 bytes (23.2%, 40.2s remaining)
Downloaded 1400832 of 5642114 bytes (24.8%, 40.1s remaining)
Downloaded 1499136 of 5642114 bytes (26.6%, 39.5s remaining)
Downloaded 1646592 of 5642114 bytes (29.2%, 37.1s remaining)
Downloaded 1835008 of 5642114 bytes (32.5%, 33.8s remaining)
Downloaded 2097152 of 5642114 bytes (37.2%, 29.3s remaining)
Downloaded 2449408 of 5642114 bytes (43.4%, 23.9s remaining)
Downloaded 2801664 of 5642114 bytes (49.7%, 19.6s remaining)
Downloaded 3162112 of 5642114 bytes (56.0%, 16.0s remaining)
Downloaded 3719168 of 5642114 bytes (65.9%, 11.0s remaining)
Downloaded 4489216 of 5642114 bytes (79.6%, 5.7s remaining)
Downloaded 5619712 of 5642114 bytes (99.6%, 0.1s remaining) ...done. (26 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3efa743a9001660a0d5/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f14712b4001a3b560e/ ...
Downloaded 655360 of 6081959 bytes (10.8%, 8.3s remaining)
Downloaded 1163264 of 6081959 bytes (19.1%, 8.6s remaining)
Downloaded 1376256 of 6081959 bytes (22.6%, 10.6s remaining)
Downloaded 1835008 of 6081959 bytes (30.2%, 9.5s remaining)
Downloaded 2899968 of 6081959 bytes (47.7%, 5.6s remaining)
Downloaded 4800512 of 6081959 bytes (78.9%, 1.6s remaining)
Downloaded 5275648 of 6081959 bytes (86.7%, 1.1s remaining)
Downloaded 5750784 of 6081959 bytes (94.6%, 0.5s remaining) ...done. (11 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f1a743a90017608164/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f12286e80016c3c37e/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f34712b4001a3b5612/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f7a743a90019606cdf/ ...
Downloaded 557056 of 6432694 bytes (8.7%, 10.8s remaining)
Downloaded 720896 of 6432694 bytes (11.2%, 16.3s remaining)
Downloaded 778240 of 6432694 bytes (12.1%, 22.4s remaining)
Downloaded 827392 of 6432694 bytes (12.9%, 28.6s remaining)
Downloaded 868352 of 6432694 bytes (13.5%, 33.9s remaining)
Downloaded 917504 of 6432694 bytes (14.3%, 39.4s remaining)
Downloaded 958464 of 6432694 bytes (14.9%, 44.4s remaining)
Downloaded 999424 of 6432694 bytes (15.5%, 48.0s remaining)
Downloaded 1048576 of 6432694 bytes (16.3%, 50.6s remaining)
Downloaded 1105920 of 6432694 bytes (17.2%, 52.6s remaining)
Downloaded 1171456 of 6432694 bytes (18.2%, 54.0s remaining)
Downloaded 1245184 of 6432694 bytes (19.4%, 54.4s remaining)
Downloaded 1327104 of 6432694 bytes (20.6%, 54.4s remaining)
Downloaded 1417216 of 6432694 bytes (22.0%, 53.6s remaining)
Downloaded 1507328 of 6432694 bytes (23.4%, 53.0s remaining)
Downloaded 1622016 of 6432694 bytes (25.2%, 51.1s remaining)
Downloaded 1761280 of 6432694 bytes (27.4%, 48.5s remaining)
Downloaded 1933312 of 6432694 bytes (30.1%, 45.0s remaining)
Downloaded 2113536 of 6432694 bytes (32.9%, 41.5s remaining)
Downloaded 2334720 of 6432694 bytes (36.3%, 37.5s remaining)
Downloaded 2555904 of 6432694 bytes (39.7%, 33.9s remaining)
Downloaded 2818048 of 6432694 bytes (43.8%, 30.0s remaining)
Downloaded 3121152 of 6432694 bytes (48.5%, 25.9s remaining)
Downloaded 3465216 of 6432694 bytes (53.9%, 21.8s remaining)
Downloaded 3784704 of 6432694 bytes (58.8%, 18.6s remaining)
Downloaded 4210688 of 6432694 bytes (65.5%, 14.6s remaining)
Downloaded 4702208 of 6432694 bytes (73.1%, 10.5s remaining)
Downloaded 5275648 of 6432694 bytes (82.0%, 6.5s remaining)
Downloaded 5898240 of 6432694 bytes (91.7%, 2.8s remaining) ...done. (33 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f6a743a90017608171/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f64712b400183b70d8/ ...
Downloaded 688128 of 5606383 bytes (12.3%, 7.2s remaining)
Downloaded 876544 of 5606383 bytes (15.6%, 11.3s remaining)
Downloaded 966656 of 5606383 bytes (17.2%, 15.3s remaining)
Downloaded 1032192 of 5606383 bytes (18.4%, 19.2s remaining)
Downloaded 1081344 of 5606383 bytes (19.3%, 22.6s remaining)
Downloaded 1163264 of 5606383 bytes (20.7%, 25.3s remaining)
Downloaded 1245184 of 5606383 bytes (22.2%, 27.0s remaining)
Downloaded 1343488 of 5606383 bytes (24.0%, 27.9s remaining)
Downloaded 1458176 of 5606383 bytes (26.0%, 28.0s remaining)
Downloaded 1695744 of 5606383 bytes (30.2%, 25.0s remaining)
Downloaded 2473984 of 5606383 bytes (44.1%, 15.0s remaining)
Downloaded 3637248 of 5606383 bytes (64.9%, 7.0s remaining)
Downloaded 5177344 of 5606383 bytes (92.3%, 1.1s remaining) ...done. (16 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f72286e80019c3c1af/ ...
...done. (1 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3f92286e80018c3e463/ ...
Downloaded 909312 of 6274191 bytes (14.5%, 6.0s remaining)
Downloaded 1540096 of 6274191 bytes (24.5%, 6.2s remaining)
Downloaded 1802240 of 6274191 bytes (28.7%, 7.5s remaining)
Downloaded 2015232 of 6274191 bytes (32.1%, 8.7s remaining)
Downloaded 2949120 of 6274191 bytes (47.0%, 5.8s remaining)
Downloaded 5128192 of 6274191 bytes (81.7%, 1.4s remaining) ...done. (9 seconds, 0 min)
Downloading data from https://osf.io/download/5cb47057f2be3c0019030a1f/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e63f2be3c0017056ba9/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4704af2be3c001705703b/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e7a353c58001a9b3324/ ...
Downloaded 3653632 of 6203305 bytes (58.9%, 0.7s remaining) ...done. (4 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3952286e80016c3c2e7/ ...
...done. (1 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3954712b400193b5b79/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb47016a3bc970018f1fc88/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e6ba3bc970019f07152/ ...
Downloaded 622592 of 6168810 bytes (10.1%, 8.9s remaining)
Downloaded 811008 of 6168810 bytes (13.1%, 13.5s remaining)
Downloaded 925696 of 6168810 bytes (15.0%, 17.3s remaining)
Downloaded 991232 of 6168810 bytes (16.1%, 22.4s remaining)
Downloaded 1048576 of 6168810 bytes (17.0%, 26.5s remaining)
Downloaded 1097728 of 6168810 bytes (17.8%, 30.8s remaining)
Downloaded 1146880 of 6168810 bytes (18.6%, 34.4s remaining)
Downloaded 1196032 of 6168810 bytes (19.4%, 37.6s remaining)
Downloaded 1253376 of 6168810 bytes (20.3%, 39.6s remaining)
Downloaded 1310720 of 6168810 bytes (21.2%, 41.4s remaining)
Downloaded 1376256 of 6168810 bytes (22.3%, 42.5s remaining)
Downloaded 1449984 of 6168810 bytes (23.5%, 43.1s remaining)
Downloaded 1540096 of 6168810 bytes (25.0%, 43.0s remaining)
Downloaded 1646592 of 6168810 bytes (26.7%, 42.1s remaining)
Downloaded 1753088 of 6168810 bytes (28.4%, 41.2s remaining)
Downloaded 1884160 of 6168810 bytes (30.5%, 39.5s remaining)
Downloaded 2056192 of 6168810 bytes (33.3%, 36.8s remaining)
Downloaded 2269184 of 6168810 bytes (36.8%, 33.4s remaining)
Downloaded 2547712 of 6168810 bytes (41.3%, 29.1s remaining)
Downloaded 2916352 of 6168810 bytes (47.3%, 23.9s remaining)
Downloaded 3284992 of 6168810 bytes (53.3%, 19.7s remaining)
Downloaded 3555328 of 6168810 bytes (57.6%, 17.3s remaining)
Downloaded 3833856 of 6168810 bytes (62.1%, 15.0s remaining)
Downloaded 4079616 of 6168810 bytes (66.1%, 13.1s remaining)
Downloaded 4259840 of 6168810 bytes (69.1%, 11.9s remaining)
Downloaded 4538368 of 6168810 bytes (73.6%, 9.9s remaining)
Downloaded 4898816 of 6168810 bytes (79.4%, 7.4s remaining)
Downloaded 5218304 of 6168810 bytes (84.6%, 5.4s remaining)
Downloaded 5464064 of 6168810 bytes (88.6%, 4.0s remaining)
Downloaded 5849088 of 6168810 bytes (94.8%, 1.7s remaining) ...done. (35 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff395a743a900176080af/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3964712b400193b5b7d/ ...
Downloaded 4202496 of 6287468 bytes (66.8%, 0.6s remaining) ...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff399a743a9001660a031/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3982286e80017c41a29/ ...
Downloaded 557056 of 6146235 bytes (9.1%, 10.4s remaining)
Downloaded 811008 of 6146235 bytes (13.2%, 13.6s remaining)
Downloaded 925696 of 6146235 bytes (15.1%, 17.7s remaining)
Downloaded 1015808 of 6146235 bytes (16.5%, 21.0s remaining)
Downloaded 1097728 of 6146235 bytes (17.9%, 24.4s remaining)
Downloaded 1982464 of 6146235 bytes (32.3%, 13.3s remaining) ...done. (10 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff39aa743a90018606e21/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff39aa743a900176080ba/ ...
Downloaded 4202496 of 6358784 bytes (66.1%, 0.6s remaining) ...done. (4 seconds, 0 min)
Downloading data from https://osf.io/download/5cb470153992690018133d3b/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e793992690017108eb9/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb47038353c5800199ac9a2/ ...
...done. (1 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e85a3bc97001aeff750/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4701c3992690018133d49/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e1c3992690018133a9e/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff39aa743a900176080bf/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff39d4712b400193b5b89/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4703039926900160f6b3e/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e4d353c58001b9cb325/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4700af2be3c0017056f69/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e0cf2be3c001801f757/ ...
Downloaded 958464 of 5527830 bytes (17.3%, 4.9s remaining)
Downloaded 1179648 of 5527830 bytes (21.3%, 7.7s remaining)
Downloaded 1343488 of 5527830 bytes (24.3%, 10.0s remaining)
Downloaded 1458176 of 5527830 bytes (26.4%, 12.0s remaining)
Downloaded 1654784 of 5527830 bytes (29.9%, 12.5s remaining)
Downloaded 2252800 of 5527830 bytes (40.8%, 9.2s remaining)
Downloaded 3276800 of 5527830 bytes (59.3%, 5.0s remaining)
Downloaded 3538944 of 5527830 bytes (64.0%, 4.7s remaining)
Downloaded 3751936 of 5527830 bytes (67.9%, 4.5s remaining)
Downloaded 3981312 of 5527830 bytes (72.0%, 4.1s remaining)
Downloaded 4349952 of 5527830 bytes (78.7%, 3.1s remaining)
Downloaded 4595712 of 5527830 bytes (83.1%, 2.5s remaining)
Downloaded 4800512 of 5527830 bytes (86.8%, 2.1s remaining)
Downloaded 5029888 of 5527830 bytes (91.0%, 1.4s remaining)
Downloaded 5275648 of 5527830 bytes (95.4%, 0.7s remaining) ...done. (19 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4702b39926900171090e4/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e35f2be3c00190305ff/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff39ca743a90019606c50/ ...
...done. (1 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a2a743a9001660a048/ ...
Downloaded 4202496 of 6131100 bytes (68.5%, 0.6s remaining) ...done. (4 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4701ff2be3c0017056fad/ ...
...done. (1 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e0339926900160f6930/ ...
Downloaded 778240 of 5344522 bytes (14.6%, 6.0s remaining)
Downloaded 1048576 of 5344522 bytes (19.6%, 8.3s remaining)
Downloaded 1245184 of 5344522 bytes (23.3%, 10.1s remaining)
Downloaded 1785856 of 5344522 bytes (33.4%, 8.1s remaining)
Downloaded 2105344 of 5344522 bytes (39.4%, 7.8s remaining)
Downloaded 2375680 of 5344522 bytes (44.5%, 7.6s remaining)
Downloaded 2596864 of 5344522 bytes (48.6%, 7.5s remaining)
Downloaded 2859008 of 5344522 bytes (53.5%, 7.1s remaining)
Downloaded 3153920 of 5344522 bytes (59.0%, 6.4s remaining)
Downloaded 3670016 of 5344522 bytes (68.7%, 4.6s remaining)
Downloaded 4145152 of 5344522 bytes (77.6%, 3.2s remaining)
Downloaded 4603904 of 5344522 bytes (86.1%, 2.0s remaining)
Downloaded 4964352 of 5344522 bytes (92.9%, 1.0s remaining) ...done. (16 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a12286e80017c41a48/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a12286e80016c3c2fc/ ...
Downloaded 4202496 of 6235792 bytes (67.4%, 0.5s remaining) ...done. (4 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff39fa743a90018606e2f/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a34712b4001a3b55a3/ ...
Downloaded 4202496 of 5622722 bytes (74.7%, 0.5s remaining) ...done. (5 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4703439926900160f6b43/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e40f2be3c001801f77f/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a34712b400193b5b92/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a84712b400183b7048/ ...
...done. (3 seconds, 0 min)
Downloading data from https://osf.io/download/5cb47020f2be3c0019030968/ ...
...done. (1 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e6f353c58001a9b3311/ ...
Downloaded 4202496 of 6178036 bytes (68.0%, 0.5s remaining) ...done. (4 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a72286e80017c41a54/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5c8ff3a7a743a90018606e42/ ...
Downloaded 4202496 of 5978758 bytes (70.3%, 0.7s remaining) ...done. (5 seconds, 0 min)
Downloading data from https://osf.io/download/5cb4702639926900190faf1d/ ...
...done. (2 seconds, 0 min)
Downloading data from https://osf.io/download/5cb46e3f353c5800199ac787/ ...
Downloaded 1097728 of 5920556 bytes (18.5%, 4.4s remaining)
Downloaded 1507328 of 5920556 bytes (25.5%, 6.1s remaining)
Downloaded 1687552 of 5920556 bytes (28.5%, 8.0s remaining)
Downloaded 1835008 of 5920556 bytes (31.0%, 9.3s remaining)
Downloaded 2015232 of 5920556 bytes (34.0%, 10.2s remaining)
Downloaded 2146304 of 5920556 bytes (36.3%, 11.2s remaining)
Downloaded 2236416 of 5920556 bytes (37.8%, 12.3s remaining)
Downloaded 2310144 of 5920556 bytes (39.0%, 13.5s remaining)
Downloaded 2375680 of 5920556 bytes (40.1%, 14.5s remaining)
Downloaded 2441216 of 5920556 bytes (41.2%, 15.3s remaining)
Downloaded 2547712 of 5920556 bytes (43.0%, 15.5s remaining)
Downloaded 2752512 of 5920556 bytes (46.5%, 14.7s remaining)
Downloaded 3055616 of 5920556 bytes (51.6%, 12.9s remaining)
Downloaded 4128768 of 5920556 bytes (69.7%, 6.4s remaining)
Downloaded 4587520 of 5920556 bytes (77.5%, 4.6s remaining)
Downloaded 4784128 of 5920556 bytes (80.8%, 4.0s remaining)
Downloaded 4964352 of 5920556 bytes (83.8%, 3.4s remaining)
Downloaded 5144576 of 5920556 bytes (86.9%, 2.8s remaining)
Downloaded 5357568 of 5920556 bytes (90.5%, 2.1s remaining)
Downloaded 5545984 of 5920556 bytes (93.7%, 1.4s remaining)
Downloaded 5750784 of 5920556 bytes (97.1%, 0.6s remaining)
Downloaded 5890048 of 5920556 bytes (99.5%, 0.1s remaining) ...done. (25 seconds, 0 min)
We use probabilistic regions of interest (ROIs) from the MSDL atlas.
.. code-block:: default
from nilearn.input_data import NiftiMapsMasker
msdl_data = datasets.fetch_atlas_msdl()
msdl_coords = msdl_data.region_coords
masker = NiftiMapsMasker(
msdl_data.maps, resampling_target="data", t_r=2, detrend=True,
low_pass=.1, high_pass=.01, memory='nilearn_cache', memory_level=1).fit()
masked_data = [masker.transform(func, confounds) for
(func, confounds) in zip(
development_dataset.func, development_dataset.confounds)]
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
/usr/lib/python3/dist-packages/numpy/lib/npyio.py:2358: VisibleDeprecationWarning: Reading unicode strings without specifying the encoding argument is deprecated. Set the encoding, use None for the system default.
output = genfromtxt(fname, **kwargs)
What kind of connectivity is most powerful for classification?
--------------------------------------------------------------
we will use connectivity matrices as features to distinguish children from
adults. We use cross-validation and measure classification accuracy to
compare the different kinds of connectivity matrices.
.. code-block:: default
# prepare the classification pipeline
from sklearn.pipeline import Pipeline
from nilearn.connectome import ConnectivityMeasure
from sklearn.svm import LinearSVC
from sklearn.dummy import DummyClassifier
from sklearn.model_selection import GridSearchCV
kinds = ['correlation', 'partial correlation', 'tangent']
pipe = Pipeline(
[('connectivity', ConnectivityMeasure(vectorize=True)),
('classifier', GridSearchCV(LinearSVC(), {'C': [.1, 1., 10.]}, cv=5))])
param_grid = [
{'classifier': [DummyClassifier('most_frequent')]},
{'connectivity__kind': kinds}
]
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
/home/varoquau/dev/scikit-learn/sklearn/utils/validation.py:68: FutureWarning: Pass strategy=most_frequent as keyword args. From version 0.25 passing these as positional arguments will result in an error
warnings.warn("Pass {} as keyword args. From version 0.25 "
We use random splits of the subjects into training/testing sets.
StratifiedShuffleSplit allows preserving the proportion of children in the
test set.
.. code-block:: default
from sklearn.model_selection import GridSearchCV, StratifiedShuffleSplit
from sklearn.preprocessing import LabelEncoder
groups = [pheno['Child_Adult'] for pheno in development_dataset.phenotypic]
classes = LabelEncoder().fit_transform(groups)
cv = StratifiedShuffleSplit(n_splits=30, random_state=0, test_size=10)
gs = GridSearchCV(pipe, param_grid, scoring='accuracy', cv=cv, verbose=1,
refit=False, n_jobs=8)
gs.fit(masked_data, classes)
mean_scores = gs.cv_results_['mean_test_score']
scores_std = gs.cv_results_['std_test_score']
.. rst-class:: sphx-glr-script-out
Out:
.. code-block:: none
Fitting 30 folds for each of 4 candidates, totalling 120 fits
display the results
.. code-block:: default
from matplotlib import pyplot as plt
plt.figure(figsize=(6, 4))
positions = [.1, .2, .3, .4]
plt.barh(positions, mean_scores, align='center', height=.05, xerr=scores_std)
yticks = ['dummy'] + list(gs.cv_results_['param_connectivity__kind'].data[1:])
yticks = [t.replace(' ', '\n') for t in yticks]
plt.yticks(positions, yticks)
plt.xlabel('Classification accuracy')
plt.gca().grid(True)
plt.gca().set_axisbelow(True)
plt.tight_layout()
.. image:: /auto_examples/07_advanced/images/sphx_glr_plot_age_group_prediction_cross_val_001.png
:alt: plot age group prediction cross val
:class: sphx-glr-single-img
This is a small example to showcase nilearn features. In practice such
comparisons need to be performed on much larger cohorts and several
datasets.
`Dadi et al 2019
`_
Showed that across many cohorts and clinical questions, the tangent
kind should be preferred.
.. code-block:: default
plt.show()
.. rst-class:: sphx-glr-timing
**Total running time of the script:** ( 9 minutes 59.244 seconds)
.. _sphx_glr_download_auto_examples_07_advanced_plot_age_group_prediction_cross_val.py:
.. only :: html
.. container:: sphx-glr-footer
:class: sphx-glr-footer-example
.. container:: binder-badge
.. image:: https://mybinder.org/badge_logo.svg
:target: https://mybinder.org/v2/gh/nilearn/nilearn.github.io/master?filepath=examples/auto_examples/07_advanced/plot_age_group_prediction_cross_val.ipynb
:width: 150 px
.. container:: sphx-glr-download sphx-glr-download-python
:download:`Download Python source code: plot_age_group_prediction_cross_val.py `
.. container:: sphx-glr-download sphx-glr-download-jupyter
:download:`Download Jupyter notebook: plot_age_group_prediction_cross_val.ipynb `
.. only:: html
.. rst-class:: sphx-glr-signature
`Gallery generated by Sphinx-Gallery `_