Decoding source space data#

Decoding to MEG data in source space on the left cortical surface. Here univariate feature selection is employed for speed purposes to confine the classification to a small number of potentially relevant features. The classifier then is trained to selected features of epochs in source space.

# Author: Denis A. Engemann <denis.engemann@gmail.com>
#         Alexandre Gramfort <alexandre.gramfort@inria.fr>
#         Jean-Rémi King <jeanremi.king@gmail.com>
#         Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD-3-Clause
# Copyright the MNE-Python contributors.
import matplotlib.pyplot as plt
import numpy as np
from sklearn.feature_selection import SelectKBest, f_classif
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

import mne
from mne.decoding import LinearModel, SlidingEstimator, cross_val_multiscore, get_coef
from mne.minimum_norm import apply_inverse_epochs, read_inverse_operator

print(__doc__)

data_path = mne.datasets.sample.data_path()
meg_path = data_path / "MEG" / "sample"
fname_fwd = meg_path / "sample_audvis-meg-oct-6-fwd.fif"
fname_evoked = meg_path / "sample_audvis-ave.fif"
subjects_dir = data_path / "subjects"

Set parameters

raw_fname = meg_path / "sample_audvis_filt-0-40_raw.fif"
event_fname = meg_path / "sample_audvis_filt-0-40_raw-eve.fif"
fname_cov = meg_path / "sample_audvis-cov.fif"
fname_inv = meg_path / "sample_audvis-meg-oct-6-meg-inv.fif"

tmin, tmax = -0.2, 0.8
event_id = dict(aud_r=2, vis_r=4)  # load contra-lateral conditions

# Setup for reading the raw data
raw = mne.io.read_raw_fif(raw_fname, preload=True)
raw.filter(None, 10.0, fir_design="firwin")
events = mne.read_events(event_fname)

# Set up pick list: MEG - bad channels (modify to your needs)
raw.info["bads"] += ["MEG 2443"]  # mark bads
picks = mne.pick_types(
    raw.info, meg=True, eeg=False, stim=True, eog=True, exclude="bads"
)

# Read epochs
epochs = mne.Epochs(
    raw,
    events,
    event_id,
    tmin,
    tmax,
    proj=True,
    picks=picks,
    baseline=(None, 0),
    preload=True,
    reject=dict(grad=4000e-13, eog=150e-6),
    decim=5,
)  # decimate to save memory and increase speed
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_filt-0-40_raw.fif...
    Read a total of 4 projection items:
        PCA-v1 (1 x 102)  idle
        PCA-v2 (1 x 102)  idle
        PCA-v3 (1 x 102)  idle
        Average EEG reference (1 x 60)  idle
    Range : 6450 ... 48149 =     42.956 ...   320.665 secs
Ready.
Reading 0 ... 41699  =      0.000 ...   277.709 secs...
Filtering raw data in 1 contiguous segment
Setting up low-pass filter at 10 Hz

FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal lowpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Upper passband edge: 10.00 Hz
- Upper transition bandwidth: 2.50 Hz (-6 dB cutoff frequency: 11.25 Hz)
- Filter length: 199 samples (1.325 s)

[Parallel(n_jobs=1)]: Done  17 tasks      | elapsed:    0.0s
[Parallel(n_jobs=1)]: Done  71 tasks      | elapsed:    0.2s
[Parallel(n_jobs=1)]: Done 161 tasks      | elapsed:    0.4s
[Parallel(n_jobs=1)]: Done 287 tasks      | elapsed:    0.7s
Not setting metadata
143 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] s
Applying baseline correction (mode: mean)
Created an SSP operator (subspace dimension = 3)
3 projection items activated
Using data from preloaded Raw for 143 events and 151 original time points (prior to decimation) ...
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
    Rejecting  epoch based on EOG : ['EOG 061']
28 bad epochs dropped

Compute inverse solution

snr = 3.0
noise_cov = mne.read_cov(fname_cov)
inverse_operator = read_inverse_operator(fname_inv)

stcs = apply_inverse_epochs(
    epochs,
    inverse_operator,
    lambda2=1.0 / snr**2,
    verbose=False,
    method="dSPM",
    pick_ori="normal",
)
    366 x 366 full covariance (kind = 1) found.
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
Reading inverse operator decomposition from /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-meg-oct-6-meg-inv.fif...
    Reading inverse operator info...
    [done]
    Reading inverse operator decomposition...
    [done]
    305 x 305 full covariance (kind = 1) found.
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Noise covariance matrix read.
    22494 x 22494 diagonal covariance (kind = 2) found.
    Source covariance matrix read.
    22494 x 22494 diagonal covariance (kind = 6) found.
    Orientation priors read.
    22494 x 22494 diagonal covariance (kind = 5) found.
    Depth priors read.
    Did not find the desired covariance matrix (kind = 3)
    Reading a source space...
    Computing patch statistics...
    Patch information added...
    Distance information added...
    [done]
    Reading a source space...
    Computing patch statistics...
    Patch information added...
    Distance information added...
    [done]
    2 source spaces read
    Read a total of 4 projection items:
        PCA-v1 (1 x 102) active
        PCA-v2 (1 x 102) active
        PCA-v3 (1 x 102) active
        Average EEG reference (1 x 60) active
    Source spaces transformed to the inverse solution coordinate frame

Decoding in sensor space using a logistic regression

# Retrieve source space data into an array
X = np.array([stc.lh_data for stc in stcs])  # only keep left hemisphere
y = epochs.events[:, 2]

# prepare a series of classifier applied at each time sample
clf = make_pipeline(
    StandardScaler(),  # z-score normalization
    SelectKBest(f_classif, k=500),  # select features for speed
    LinearModel(LogisticRegression(C=1, solver="liblinear")),
)
time_decod = SlidingEstimator(clf, scoring="roc_auc")

# Run cross-validated decoding analyses:
scores = cross_val_multiscore(time_decod, X, y, cv=5, n_jobs=None)

# Plot average decoding scores of 5 splits
fig, ax = plt.subplots(1)
ax.plot(epochs.times, scores.mean(0), label="score")
ax.axhline(0.5, color="k", linestyle="--", label="chance")
ax.axvline(0, color="k")
plt.legend()
decoding spatio temporal source
  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|▎         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.30it/s]
  6%|▋         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   14.59it/s]
 10%|▉         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   17.76it/s]
 13%|█▎        | Fitting SlidingEstimator : 4/31 [00:00<00:01,   19.92it/s]
 16%|█▌        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   18.54it/s]
 19%|█▉        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   19.95it/s]
 23%|██▎       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   21.10it/s]
 26%|██▌       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   22.05it/s]
 29%|██▉       | Fitting SlidingEstimator : 9/31 [00:00<00:00,   22.85it/s]
 32%|███▏      | Fitting SlidingEstimator : 10/31 [00:00<00:00,   23.35it/s]
 35%|███▌      | Fitting SlidingEstimator : 11/31 [00:00<00:00,   23.95it/s]
 39%|███▊      | Fitting SlidingEstimator : 12/31 [00:00<00:00,   24.46it/s]
 42%|████▏     | Fitting SlidingEstimator : 13/31 [00:00<00:00,   24.92it/s]
 45%|████▌     | Fitting SlidingEstimator : 14/31 [00:00<00:00,   25.32it/s]
 48%|████▊     | Fitting SlidingEstimator : 15/31 [00:00<00:00,   25.67it/s]
 52%|█████▏    | Fitting SlidingEstimator : 16/31 [00:00<00:00,   25.99it/s]
 55%|█████▍    | Fitting SlidingEstimator : 17/31 [00:00<00:00,   26.27it/s]
 58%|█████▊    | Fitting SlidingEstimator : 18/31 [00:00<00:00,   24.71it/s]
 61%|██████▏   | Fitting SlidingEstimator : 19/31 [00:00<00:00,   24.91it/s]
 65%|██████▍   | Fitting SlidingEstimator : 20/31 [00:00<00:00,   25.23it/s]
 68%|██████▊   | Fitting SlidingEstimator : 21/31 [00:00<00:00,   25.52it/s]
 71%|███████   | Fitting SlidingEstimator : 22/31 [00:00<00:00,   25.79it/s]
 74%|███████▍  | Fitting SlidingEstimator : 23/31 [00:00<00:00,   24.49it/s]
 77%|███████▋  | Fitting SlidingEstimator : 24/31 [00:00<00:00,   24.80it/s]
 81%|████████  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   25.05it/s]
 84%|████████▍ | Fitting SlidingEstimator : 26/31 [00:01<00:00,   23.94it/s]
 87%|████████▋ | Fitting SlidingEstimator : 27/31 [00:01<00:00,   24.25it/s]
 90%|█████████ | Fitting SlidingEstimator : 28/31 [00:01<00:00,   24.42it/s]
 94%|█████████▎| Fitting SlidingEstimator : 29/31 [00:01<00:00,   23.46it/s]
 97%|█████████▋| Fitting SlidingEstimator : 30/31 [00:01<00:00,   23.77it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   24.11it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   24.05it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|▎         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.28it/s]
  6%|▋         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   19.45it/s]
 10%|▉         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   22.11it/s]
 13%|█▎        | Fitting SlidingEstimator : 4/31 [00:00<00:01,   19.56it/s]
 16%|█▌        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   21.16it/s]
 19%|█▉        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   22.36it/s]
 23%|██▎       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   20.64it/s]
 26%|██▌       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   21.62it/s]
 29%|██▉       | Fitting SlidingEstimator : 9/31 [00:00<00:00,   22.32it/s]
 32%|███▏      | Fitting SlidingEstimator : 10/31 [00:00<00:00,   23.03it/s]
 35%|███▌      | Fitting SlidingEstimator : 11/31 [00:00<00:00,   23.65it/s]
 39%|███▊      | Fitting SlidingEstimator : 12/31 [00:00<00:00,   22.23it/s]
 42%|████▏     | Fitting SlidingEstimator : 13/31 [00:00<00:00,   22.81it/s]
 45%|████▌     | Fitting SlidingEstimator : 14/31 [00:00<00:00,   23.34it/s]
 48%|████▊     | Fitting SlidingEstimator : 15/31 [00:00<00:00,   23.74it/s]
 52%|█████▏    | Fitting SlidingEstimator : 16/31 [00:00<00:00,   22.54it/s]
 55%|█████▍    | Fitting SlidingEstimator : 17/31 [00:00<00:00,   23.02it/s]
 58%|█████▊    | Fitting SlidingEstimator : 18/31 [00:00<00:00,   23.44it/s]
 61%|██████▏   | Fitting SlidingEstimator : 19/31 [00:00<00:00,   23.73it/s]
 65%|██████▍   | Fitting SlidingEstimator : 20/31 [00:00<00:00,   22.68it/s]
 68%|██████▊   | Fitting SlidingEstimator : 21/31 [00:00<00:00,   23.09it/s]
 71%|███████   | Fitting SlidingEstimator : 22/31 [00:00<00:00,   23.48it/s]
 74%|███████▍  | Fitting SlidingEstimator : 23/31 [00:01<00:00,   22.54it/s]
 77%|███████▋  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   22.93it/s]
 81%|████████  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   23.30it/s]
 84%|████████▍ | Fitting SlidingEstimator : 26/31 [00:01<00:00,   23.49it/s]
 87%|████████▋ | Fitting SlidingEstimator : 27/31 [00:01<00:00,   22.62it/s]
 90%|█████████ | Fitting SlidingEstimator : 28/31 [00:01<00:00,   22.98it/s]
 94%|█████████▎| Fitting SlidingEstimator : 29/31 [00:01<00:00,   22.20it/s]
 97%|█████████▋| Fitting SlidingEstimator : 30/31 [00:01<00:00,   22.55it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   23.28it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   23.00it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|▎         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.32it/s]
  6%|▋         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   19.50it/s]
 10%|▉         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   22.17it/s]
 13%|█▎        | Fitting SlidingEstimator : 4/31 [00:00<00:01,   23.80it/s]
 16%|█▌        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   24.89it/s]
 19%|█▉        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   22.10it/s]
 23%|██▎       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   23.08it/s]
 26%|██▌       | Fitting SlidingEstimator : 8/31 [00:00<00:00,   23.86it/s]
 29%|██▉       | Fitting SlidingEstimator : 9/31 [00:00<00:00,   24.52it/s]
 32%|███▏      | Fitting SlidingEstimator : 10/31 [00:00<00:00,   24.98it/s]
 35%|███▌      | Fitting SlidingEstimator : 11/31 [00:00<00:00,   23.16it/s]
 39%|███▊      | Fitting SlidingEstimator : 12/31 [00:00<00:00,   23.73it/s]
 42%|████▏     | Fitting SlidingEstimator : 13/31 [00:00<00:00,   24.08it/s]
 45%|████▌     | Fitting SlidingEstimator : 14/31 [00:00<00:00,   24.53it/s]
 48%|████▊     | Fitting SlidingEstimator : 15/31 [00:00<00:00,   24.94it/s]
 52%|█████▏    | Fitting SlidingEstimator : 16/31 [00:00<00:00,   23.52it/s]
 55%|█████▍    | Fitting SlidingEstimator : 17/31 [00:00<00:00,   23.95it/s]
 58%|█████▊    | Fitting SlidingEstimator : 18/31 [00:00<00:00,   24.34it/s]
 61%|██████▏   | Fitting SlidingEstimator : 19/31 [00:00<00:00,   24.69it/s]
 65%|██████▍   | Fitting SlidingEstimator : 20/31 [00:00<00:00,   23.49it/s]
 68%|██████▊   | Fitting SlidingEstimator : 21/31 [00:00<00:00,   23.80it/s]
 71%|███████   | Fitting SlidingEstimator : 22/31 [00:00<00:00,   24.15it/s]
 74%|███████▍  | Fitting SlidingEstimator : 23/31 [00:00<00:00,   24.48it/s]
 77%|███████▋  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   23.41it/s]
 81%|████████  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   23.76it/s]
 84%|████████▍ | Fitting SlidingEstimator : 26/31 [00:01<00:00,   24.09it/s]
 87%|████████▋ | Fitting SlidingEstimator : 27/31 [00:01<00:00,   24.34it/s]
 90%|█████████ | Fitting SlidingEstimator : 28/31 [00:01<00:00,   23.37it/s]
 94%|█████████▎| Fitting SlidingEstimator : 29/31 [00:01<00:00,   23.69it/s]
 97%|█████████▋| Fitting SlidingEstimator : 30/31 [00:01<00:00,   24.00it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   24.33it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   24.09it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|▎         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.33it/s]
  6%|▋         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   19.50it/s]
 10%|▉         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   17.59it/s]
 13%|█▎        | Fitting SlidingEstimator : 4/31 [00:00<00:01,   19.76it/s]
 16%|█▌        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   21.34it/s]
 19%|█▉        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   22.54it/s]
 23%|██▎       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   20.77it/s]
 26%|██▌       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   21.68it/s]
 29%|██▉       | Fitting SlidingEstimator : 9/31 [00:00<00:00,   22.50it/s]
 32%|███▏      | Fitting SlidingEstimator : 10/31 [00:00<00:00,   23.20it/s]
 35%|███▌      | Fitting SlidingEstimator : 11/31 [00:00<00:00,   23.74it/s]
 39%|███▊      | Fitting SlidingEstimator : 12/31 [00:00<00:00,   24.27it/s]
 42%|████▏     | Fitting SlidingEstimator : 13/31 [00:00<00:00,   24.74it/s]
 45%|████▌     | Fitting SlidingEstimator : 14/31 [00:00<00:00,   23.19it/s]
 48%|████▊     | Fitting SlidingEstimator : 15/31 [00:00<00:00,   23.67it/s]
 52%|█████▏    | Fitting SlidingEstimator : 16/31 [00:00<00:00,   24.11it/s]
 55%|█████▍    | Fitting SlidingEstimator : 17/31 [00:00<00:00,   24.51it/s]
 58%|█████▊    | Fitting SlidingEstimator : 18/31 [00:00<00:00,   24.77it/s]
 61%|██████▏   | Fitting SlidingEstimator : 19/31 [00:00<00:00,   25.10it/s]
 65%|██████▍   | Fitting SlidingEstimator : 20/31 [00:00<00:00,   25.41it/s]
 68%|██████▊   | Fitting SlidingEstimator : 21/31 [00:00<00:00,   24.11it/s]
 71%|███████   | Fitting SlidingEstimator : 22/31 [00:00<00:00,   24.45it/s]
 74%|███████▍  | Fitting SlidingEstimator : 23/31 [00:00<00:00,   24.77it/s]
 77%|███████▋  | Fitting SlidingEstimator : 24/31 [00:00<00:00,   25.00it/s]
 81%|████████  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   23.88it/s]
 84%|████████▍ | Fitting SlidingEstimator : 26/31 [00:01<00:00,   24.20it/s]
 87%|████████▋ | Fitting SlidingEstimator : 27/31 [00:01<00:00,   24.51it/s]
 90%|█████████ | Fitting SlidingEstimator : 28/31 [00:01<00:00,   24.66it/s]
 94%|█████████▎| Fitting SlidingEstimator : 29/31 [00:01<00:00,   23.66it/s]
 97%|█████████▋| Fitting SlidingEstimator : 30/31 [00:01<00:00,   23.97it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   24.43it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   24.11it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|▎         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.82it/s]
  6%|▋         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   19.74it/s]
 10%|▉         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   22.38it/s]
 13%|█▎        | Fitting SlidingEstimator : 4/31 [00:00<00:01,   19.71it/s]
 16%|█▌        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   21.04it/s]
 19%|█▉        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   22.27it/s]
 23%|██▎       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   23.23it/s]
 26%|██▌       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   21.45it/s]
 29%|██▉       | Fitting SlidingEstimator : 9/31 [00:00<00:00,   22.28it/s]
 32%|███▏      | Fitting SlidingEstimator : 10/31 [00:00<00:00,   22.99it/s]
 35%|███▌      | Fitting SlidingEstimator : 11/31 [00:00<00:00,   23.61it/s]
 39%|███▊      | Fitting SlidingEstimator : 12/31 [00:00<00:00,   24.15it/s]
 42%|████▏     | Fitting SlidingEstimator : 13/31 [00:00<00:00,   24.56it/s]
 45%|████▌     | Fitting SlidingEstimator : 14/31 [00:00<00:00,   23.09it/s]
 48%|████▊     | Fitting SlidingEstimator : 15/31 [00:00<00:00,   23.58it/s]
 52%|█████▏    | Fitting SlidingEstimator : 16/31 [00:00<00:00,   23.90it/s]
 55%|█████▍    | Fitting SlidingEstimator : 17/31 [00:00<00:00,   24.30it/s]
 58%|█████▊    | Fitting SlidingEstimator : 18/31 [00:00<00:00,   23.09it/s]
 61%|██████▏   | Fitting SlidingEstimator : 19/31 [00:00<00:00,   23.51it/s]
 65%|██████▍   | Fitting SlidingEstimator : 20/31 [00:00<00:00,   23.90it/s]
 68%|██████▊   | Fitting SlidingEstimator : 21/31 [00:00<00:00,   24.26it/s]
 71%|███████   | Fitting SlidingEstimator : 22/31 [00:00<00:00,   23.18it/s]
 74%|███████▍  | Fitting SlidingEstimator : 23/31 [00:00<00:00,   23.55it/s]
 77%|███████▋  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   23.90it/s]
 81%|████████  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   24.19it/s]
 84%|████████▍ | Fitting SlidingEstimator : 26/31 [00:01<00:00,   23.21it/s]
 87%|████████▋ | Fitting SlidingEstimator : 27/31 [00:01<00:00,   23.56it/s]
 90%|█████████ | Fitting SlidingEstimator : 28/31 [00:01<00:00,   23.78it/s]
 94%|█████████▎| Fitting SlidingEstimator : 29/31 [00:01<00:00,   24.09it/s]
 97%|█████████▋| Fitting SlidingEstimator : 30/31 [00:01<00:00,   24.37it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   24.32it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   23.87it/s]

To investigate weights, we need to retrieve the patterns of a fitted model

# The fitting needs not be cross validated because the weights are based on
# the training sets
time_decod.fit(X, y)

# Retrieve patterns after inversing the z-score normalization step:
patterns = get_coef(time_decod, "patterns_", inverse_transform=True)

stc = stcs[0]  # for convenience, lookup parameters from first stc
vertices = [stc.lh_vertno, np.array([], int)]  # empty array for right hemi
stc_feat = mne.SourceEstimate(
    np.abs(patterns),
    vertices=vertices,
    tmin=stc.tmin,
    tstep=stc.tstep,
    subject="sample",
)

brain = stc_feat.plot(
    views=["lat"],
    transparent=True,
    initial_time=0.1,
    time_unit="s",
    subjects_dir=subjects_dir,
)
decoding spatio temporal source
  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|▎         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.32it/s]
  6%|▋         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   14.59it/s]
 10%|▉         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   17.76it/s]
 13%|█▎        | Fitting SlidingEstimator : 4/31 [00:00<00:01,   16.89it/s]
 16%|█▌        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   18.66it/s]
 19%|█▉        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   17.81it/s]
 23%|██▎       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   17.25it/s]
 26%|██▌       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   18.26it/s]
 29%|██▉       | Fitting SlidingEstimator : 9/31 [00:00<00:01,   19.22it/s]
 32%|███▏      | Fitting SlidingEstimator : 10/31 [00:00<00:01,   18.54it/s]
 35%|███▌      | Fitting SlidingEstimator : 11/31 [00:00<00:01,   19.38it/s]
 39%|███▊      | Fitting SlidingEstimator : 12/31 [00:00<00:01,   18.77it/s]
 42%|████▏     | Fitting SlidingEstimator : 13/31 [00:00<00:00,   19.51it/s]
 45%|████▌     | Fitting SlidingEstimator : 14/31 [00:00<00:00,   18.93it/s]
 48%|████▊     | Fitting SlidingEstimator : 15/31 [00:00<00:00,   19.60it/s]
 52%|█████▏    | Fitting SlidingEstimator : 16/31 [00:00<00:00,   20.21it/s]
 55%|█████▍    | Fitting SlidingEstimator : 17/31 [00:00<00:00,   19.54it/s]
 58%|█████▊    | Fitting SlidingEstimator : 18/31 [00:00<00:00,   20.11it/s]
 61%|██████▏   | Fitting SlidingEstimator : 19/31 [00:00<00:00,   19.56it/s]
 65%|██████▍   | Fitting SlidingEstimator : 20/31 [00:01<00:00,   20.10it/s]
 68%|██████▊   | Fitting SlidingEstimator : 21/31 [00:01<00:00,   19.58it/s]
 71%|███████   | Fitting SlidingEstimator : 22/31 [00:01<00:00,   20.09it/s]
 74%|███████▍  | Fitting SlidingEstimator : 23/31 [00:01<00:00,   19.59it/s]
 77%|███████▋  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   20.05it/s]
 81%|████████  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   19.58it/s]
 84%|████████▍ | Fitting SlidingEstimator : 26/31 [00:01<00:00,   19.17it/s]
 87%|████████▋ | Fitting SlidingEstimator : 27/31 [00:01<00:00,   19.58it/s]
 90%|█████████ | Fitting SlidingEstimator : 28/31 [00:01<00:00,   19.19it/s]
 94%|█████████▎| Fitting SlidingEstimator : 29/31 [00:01<00:00,   19.63it/s]
 97%|█████████▋| Fitting SlidingEstimator : 30/31 [00:01<00:00,   19.24it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   19.62it/s]
100%|██████████| Fitting SlidingEstimator : 31/31 [00:01<00:00,   19.45it/s]
Using control points [ 3.50724321  4.37721471 15.59502306]
True

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

Gallery generated by Sphinx-Gallery