ROI-based decoding analysis in Haxby et al. dataset

In this script we reproduce the data analysis conducted by Haxby et al.[1].

Specifically, we look at decoding accuracy for different objects in three different masks: the full ventral stream (mask_vt), the house selective areas (mask_house) and the face selective areas (mask_face), that have been defined via a standard GLM-based analysis.

Note

If you are using Nilearn with a version older than 0.9.0, then you should either upgrade your version or import maskers from the input_data module instead of the maskers module.

That is, you should manually replace in the following example all occurrences of:

from nilearn.maskers import NiftiMasker

with:

from nilearn.input_data import NiftiMasker
# Fetch data using nilearn dataset fetcher
from nilearn import datasets
from nilearn.plotting import show

Load and prepare the data

# by default we fetch 2nd subject data for analysis
haxby_dataset = datasets.fetch_haxby()
func_filename = haxby_dataset.func[0]

# Print basic information on the dataset
print(
    "First subject anatomical nifti image (3D) located is "
    f"at: {haxby_dataset.anat[0]}"
)
print(
    "First subject functional nifti image (4D) is located "
    f"at: {func_filename}"
)

# load labels
import pandas as pd

# Load nilearn NiftiMasker, the practical masking and unmasking tool
from nilearn.maskers import NiftiMasker

labels = pd.read_csv(haxby_dataset.session_target[0], sep=" ")
stimuli = labels["labels"]
# identify resting state labels in order to be able to remove them
task_mask = stimuli != "rest"

# find names of remaining active labels
categories = stimuli[task_mask].unique()

# extract tags indicating to which acquisition run a tag belongs
run_labels = labels["chunks"][task_mask]

# apply the task_mask to  fMRI data (func_filename)
from nilearn.image import index_img

task_data = index_img(func_filename, task_mask)
[get_dataset_dir] Dataset found in /home/runner/nilearn_data/haxby2001
First subject anatomical nifti image (3D) located is at: /home/runner/nilearn_data/haxby2001/subj2/anat.nii.gz
First subject functional nifti image (4D) is located at: /home/runner/nilearn_data/haxby2001/subj2/bold.nii.gz

Decoding on the different masks

The classifier used here is a support vector classifier (svc). We use Decoder and specify the classifier.

import numpy as np

# Make a data splitting object for cross validation
from sklearn.model_selection import LeaveOneGroupOut

from nilearn.decoding import Decoder

cv = LeaveOneGroupOut()

We use Decoder to estimate a baseline.

mask_names = ["mask_vt", "mask_face", "mask_house"]

mask_scores = {}
mask_chance_scores = {}

for mask_name in mask_names:
    print(f"Working on {mask_name}")
    # For decoding, standardizing is often very important
    mask_filename = haxby_dataset[mask_name][0]
    masker = NiftiMasker(mask_img=mask_filename, standardize="zscore_sample")
    mask_scores[mask_name] = {}
    mask_chance_scores[mask_name] = {}

    for category in categories:
        print(f"Processing {mask_name} {category}")
        classification_target = stimuli[task_mask] == category
        # Specify the classifier to the decoder object.
        # With the decoder we can input the masker directly.
        # We are using the svc_l1 here because it is intra subject.
        decoder = Decoder(
            estimator="svc_l1",
            cv=cv,
            mask=masker,
            scoring="roc_auc",
            standardize="zscore_sample",
        )
        decoder.fit(task_data, classification_target, groups=run_labels)
        mask_scores[mask_name][category] = decoder.cv_scores_[1]
        mean = np.mean(mask_scores[mask_name][category])
        std = np.std(mask_scores[mask_name][category])
        print(f"Scores: {mean:1.2f} +- {std:1.2f}")

        dummy_classifier = Decoder(
            estimator="dummy_classifier",
            cv=cv,
            mask=masker,
            scoring="roc_auc",
            standardize="zscore_sample",
        )
        dummy_classifier.fit(
            task_data, classification_target, groups=run_labels
        )
        mask_chance_scores[mask_name][category] = dummy_classifier.cv_scores_[
            1
        ]
Working on mask_vt
Processing mask_vt scissors
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 0.92 +- 0.05
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Processing mask_vt face
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 0.98 +- 0.03
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Processing mask_vt cat
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 0.96 +- 0.04
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Processing mask_vt shoe
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 0.92 +- 0.07
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Processing mask_vt house
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 1.00 +- 0.00
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Processing mask_vt scrambledpix
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 0.99 +- 0.01
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Processing mask_vt bottle
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 0.89 +- 0.08
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Processing mask_vt chair
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Scores: 0.93 +- 0.04
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

Working on mask_face
Processing mask_face scissors
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.70 +- 0.16
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Processing mask_face face
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.90 +- 0.06
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Processing mask_face cat
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.76 +- 0.12
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Processing mask_face shoe
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.73 +- 0.17
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Processing mask_face house
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.71 +- 0.16
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Processing mask_face scrambledpix
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.87 +- 0.09
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Processing mask_face bottle
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.68 +- 0.17
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Processing mask_face chair
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Scores: 0.63 +- 0.10
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:796: UserWarning:

After clustering and screening, the decoding model will be trained only on 30 features. Consider raising clustering_percentile or screening_percentile parameters.

Working on mask_house
Processing mask_house scissors
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 0.83 +- 0.08
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Processing mask_house face
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 0.90 +- 0.07
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Processing mask_house cat
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 0.86 +- 0.09
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Processing mask_house shoe
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 0.82 +- 0.12
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Processing mask_house house
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 1.00 +- 0.00
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Processing mask_house scrambledpix
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 0.96 +- 0.05
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Processing mask_house bottle
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 0.86 +- 0.10
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Processing mask_house chair
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

Scores: 0.90 +- 0.10
/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/image/resampling.py:489: UserWarning:

The provided image has no sform in its header. Please check the provided file. Results may not be as expected.

/home/runner/work/nilearn/nilearn/.tox/doc/lib/python3.9/site-packages/nilearn/decoding/decoder.py:774: UserWarning:

Brain mask is smaller than .5% of the size of the standard human brain. This object is probably not tuned to be used on such data.

We make a simple bar plot to summarize the results

import matplotlib.pyplot as plt

plt.figure(constrained_layout=True)

tick_position = np.arange(len(categories))
plt.xticks(tick_position, categories, rotation=45)

for color, mask_name in zip("rgb", mask_names):
    score_means = [
        np.mean(mask_scores[mask_name][category]) for category in categories
    ]
    plt.bar(
        tick_position, score_means, label=mask_name, width=0.25, color=color
    )

    score_chance = [
        np.mean(mask_chance_scores[mask_name][category])
        for category in categories
    ]
    plt.bar(
        tick_position,
        score_chance,
        width=0.25,
        edgecolor="k",
        facecolor="none",
    )

    tick_position = tick_position + 0.2

plt.ylabel("Classification accuracy (AUC score)")
plt.xlabel("Visual stimuli category")
plt.ylim(0.3, 1)
plt.legend(loc="lower right")
plt.title("Category-specific classification accuracy for different masks")

show()
Category-specific classification accuracy for different masks

References

Total running time of the script: (2 minutes 38.103 seconds)

Estimated memory usage: 1459 MB

Gallery generated by Sphinx-Gallery