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-Remi King <jeanremi.king@gmail.com>
#         Eric Larson <larson.eric.d@gmail.com>
#
# License: BSD-3-Clause
import numpy as np
import matplotlib.pyplot as plt

from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.feature_selection import SelectKBest, f_classif
from sklearn.linear_model import LogisticRegression

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

print(__doc__)

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

Set parameters

raw_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw.fif'
event_fname = data_path + '/MEG/sample/sample_audvis_filt-0-40_raw-eve.fif'
fname_cov = data_path + '/MEG/sample/sample_audvis-cov.fif'
fname_inv = data_path + '/MEG/sample/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., 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

Out:

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 sec)

Not setting metadata
Not setting metadata
143 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] sec
Applying baseline correction (mode: mean)
Created an SSP operator (subspace dimension = 3)
4 projection items activated
Loading data for 143 events and 151 original time points ...
    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")

Out:

    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=1)

# Plot average decoding scores of 5 splits
fig, ax = plt.subplots(1)
ax.plot(epochs.times, scores.mean(0), label='score')
ax.axhline(.5, color='k', linestyle='--', label='chance')
ax.axvline(0, color='k')
plt.legend()
decoding spatio temporal source

Out:

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|3         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.78it/s]
  6%|6         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   19.84it/s]
 10%|9         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   17.75it/s]
 13%|#2        | Fitting SlidingEstimator : 4/31 [00:00<00:01,   14.62it/s]
 16%|#6        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   14.66it/s]
 19%|#9        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   16.20it/s]
 23%|##2       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   14.65it/s]
 26%|##5       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   14.68it/s]
 29%|##9       | Fitting SlidingEstimator : 9/31 [00:00<00:01,   15.75it/s]
 32%|###2      | Fitting SlidingEstimator : 10/31 [00:00<00:01,   14.68it/s]
 35%|###5      | Fitting SlidingEstimator : 11/31 [00:00<00:01,   14.17it/s]
 39%|###8      | Fitting SlidingEstimator : 12/31 [00:00<00:01,   15.02it/s]
 42%|####1     | Fitting SlidingEstimator : 13/31 [00:00<00:01,   15.00it/s]
 45%|####5     | Fitting SlidingEstimator : 14/31 [00:00<00:01,   14.28it/s]
 48%|####8     | Fitting SlidingEstimator : 15/31 [00:01<00:01,   14.33it/s]
 52%|#####1    | Fitting SlidingEstimator : 16/31 [00:01<00:00,   15.03it/s]
 55%|#####4    | Fitting SlidingEstimator : 17/31 [00:01<00:00,   14.39it/s]
 58%|#####8    | Fitting SlidingEstimator : 18/31 [00:01<00:00,   13.87it/s]
 61%|######1   | Fitting SlidingEstimator : 19/31 [00:01<00:00,   14.49it/s]
 65%|######4   | Fitting SlidingEstimator : 20/31 [00:01<00:00,   14.52it/s]
 68%|######7   | Fitting SlidingEstimator : 21/31 [00:01<00:00,   14.02it/s]
 71%|#######   | Fitting SlidingEstimator : 22/31 [00:01<00:00,   14.08it/s]
 74%|#######4  | Fitting SlidingEstimator : 23/31 [00:01<00:00,   14.13it/s]
 77%|#######7  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   14.18it/s]
 81%|########  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   13.77it/s]
 84%|########3 | Fitting SlidingEstimator : 26/31 [00:01<00:00,   13.42it/s]
 87%|########7 | Fitting SlidingEstimator : 27/31 [00:01<00:00,   13.50it/s]
 90%|######### | Fitting SlidingEstimator : 28/31 [00:02<00:00,   13.18it/s]
 94%|#########3| Fitting SlidingEstimator : 29/31 [00:02<00:00,   12.90it/s]
 97%|#########6| Fitting SlidingEstimator : 30/31 [00:02<00:00,   12.66it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.59it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   13.29it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|3         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   13.58it/s]
  6%|6         | Fitting SlidingEstimator : 2/31 [00:00<00:02,   14.18it/s]
 10%|9         | Fitting SlidingEstimator : 3/31 [00:00<00:01,   14.41it/s]
 13%|#2        | Fitting SlidingEstimator : 4/31 [00:00<00:02,   12.83it/s]
 16%|#6        | Fitting SlidingEstimator : 5/31 [00:00<00:02,   12.05it/s]
 19%|#9        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   13.57it/s]
 23%|##2       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   13.76it/s]
 26%|##5       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   13.02it/s]
 29%|##9       | Fitting SlidingEstimator : 9/31 [00:00<00:01,   12.62it/s]
 32%|###2      | Fitting SlidingEstimator : 10/31 [00:00<00:01,   13.59it/s]
 35%|###5      | Fitting SlidingEstimator : 11/31 [00:00<00:01,   13.72it/s]
 39%|###8      | Fitting SlidingEstimator : 12/31 [00:00<00:01,   13.17it/s]
 42%|####1     | Fitting SlidingEstimator : 13/31 [00:00<00:01,   13.97it/s]
 45%|####5     | Fitting SlidingEstimator : 14/31 [00:01<00:01,   14.05it/s]
 48%|####8     | Fitting SlidingEstimator : 15/31 [00:01<00:01,   13.52it/s]
 52%|#####1    | Fitting SlidingEstimator : 16/31 [00:01<00:01,   13.10it/s]
 55%|#####4    | Fitting SlidingEstimator : 17/31 [00:01<00:01,   13.76it/s]
 58%|#####8    | Fitting SlidingEstimator : 18/31 [00:01<00:00,   13.84it/s]
 61%|######1   | Fitting SlidingEstimator : 19/31 [00:01<00:00,   13.52it/s]
 65%|######4   | Fitting SlidingEstimator : 20/31 [00:01<00:00,   13.14it/s]
 68%|######7   | Fitting SlidingEstimator : 21/31 [00:01<00:00,   13.26it/s]
 71%|#######   | Fitting SlidingEstimator : 22/31 [00:01<00:00,   13.36it/s]
 74%|#######4  | Fitting SlidingEstimator : 23/31 [00:01<00:00,   13.46it/s]
 77%|#######7  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   13.08it/s]
 81%|########  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   12.80it/s]
 84%|########3 | Fitting SlidingEstimator : 26/31 [00:02<00:00,   12.65it/s]
 87%|########7 | Fitting SlidingEstimator : 27/31 [00:02<00:00,   12.42it/s]
 90%|######### | Fitting SlidingEstimator : 28/31 [00:02<00:00,   12.22it/s]
 94%|#########3| Fitting SlidingEstimator : 29/31 [00:02<00:00,   12.03it/s]
 97%|#########6| Fitting SlidingEstimator : 30/31 [00:02<00:00,   11.87it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.06it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.52it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|3         | Fitting SlidingEstimator : 1/31 [00:00<00:03,    8.66it/s]
  6%|6         | Fitting SlidingEstimator : 2/31 [00:00<00:02,   11.00it/s]
 10%|9         | Fitting SlidingEstimator : 3/31 [00:00<00:02,   10.59it/s]
 13%|#2        | Fitting SlidingEstimator : 4/31 [00:00<00:02,   11.48it/s]
 16%|#6        | Fitting SlidingEstimator : 5/31 [00:00<00:02,   11.09it/s]
 19%|#9        | Fitting SlidingEstimator : 6/31 [00:00<00:02,   11.65it/s]
 23%|##2       | Fitting SlidingEstimator : 7/31 [00:00<00:02,   11.32it/s]
 26%|##5       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   11.73it/s]
 29%|##9       | Fitting SlidingEstimator : 9/31 [00:00<00:01,   11.45it/s]
 32%|###2      | Fitting SlidingEstimator : 10/31 [00:00<00:01,   12.40it/s]
 35%|###5      | Fitting SlidingEstimator : 11/31 [00:00<00:01,   12.64it/s]
 39%|###8      | Fitting SlidingEstimator : 12/31 [00:00<00:01,   12.27it/s]
 42%|####1     | Fitting SlidingEstimator : 13/31 [00:01<00:01,   12.49it/s]
 45%|####5     | Fitting SlidingEstimator : 14/31 [00:01<00:01,   13.24it/s]
 48%|####8     | Fitting SlidingEstimator : 15/31 [00:01<00:01,   12.84it/s]
 52%|#####1    | Fitting SlidingEstimator : 16/31 [00:01<00:01,   12.51it/s]
 55%|#####4    | Fitting SlidingEstimator : 17/31 [00:01<00:01,   12.39it/s]
 58%|#####8    | Fitting SlidingEstimator : 18/31 [00:01<00:01,   12.14it/s]
 61%|######1   | Fitting SlidingEstimator : 19/31 [00:01<00:00,   12.32it/s]
 65%|######4   | Fitting SlidingEstimator : 20/31 [00:01<00:00,   11.72it/s]
 68%|######7   | Fitting SlidingEstimator : 21/31 [00:01<00:00,   12.28it/s]
 71%|#######   | Fitting SlidingEstimator : 22/31 [00:01<00:00,   12.44it/s]
 74%|#######4  | Fitting SlidingEstimator : 23/31 [00:01<00:00,   12.21it/s]
 77%|#######7  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   12.08it/s]
 81%|########  | Fitting SlidingEstimator : 25/31 [00:02<00:00,   11.90it/s]
 84%|########3 | Fitting SlidingEstimator : 26/31 [00:02<00:00,   12.40it/s]
 87%|########7 | Fitting SlidingEstimator : 27/31 [00:02<00:00,   12.54it/s]
 90%|######### | Fitting SlidingEstimator : 28/31 [00:02<00:00,   12.32it/s]
 94%|#########3| Fitting SlidingEstimator : 29/31 [00:02<00:00,   12.13it/s]
 97%|#########6| Fitting SlidingEstimator : 30/31 [00:02<00:00,   12.27it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.67it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.42it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|3         | Fitting SlidingEstimator : 1/31 [00:00<00:03,    9.91it/s]
  6%|6         | Fitting SlidingEstimator : 2/31 [00:00<00:02,   11.92it/s]
 10%|9         | Fitting SlidingEstimator : 3/31 [00:00<00:02,   12.81it/s]
 13%|#2        | Fitting SlidingEstimator : 4/31 [00:00<00:02,   13.30it/s]
 16%|#6        | Fitting SlidingEstimator : 5/31 [00:00<00:02,   12.37it/s]
 19%|#9        | Fitting SlidingEstimator : 6/31 [00:00<00:02,   11.94it/s]
 23%|##2       | Fitting SlidingEstimator : 7/31 [00:00<00:02,   11.55it/s]
 26%|##5       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   11.94it/s]
 29%|##9       | Fitting SlidingEstimator : 9/31 [00:00<00:01,   12.27it/s]
 32%|###2      | Fitting SlidingEstimator : 10/31 [00:00<00:01,   12.54it/s]
 35%|###5      | Fitting SlidingEstimator : 11/31 [00:00<00:01,   12.16it/s]
 39%|###8      | Fitting SlidingEstimator : 12/31 [00:01<00:01,   11.87it/s]
 42%|####1     | Fitting SlidingEstimator : 13/31 [00:01<00:01,   11.63it/s]
 45%|####5     | Fitting SlidingEstimator : 14/31 [00:01<00:01,   11.88it/s]
 48%|####8     | Fitting SlidingEstimator : 15/31 [00:01<00:01,   12.11it/s]
 52%|#####1    | Fitting SlidingEstimator : 16/31 [00:01<00:01,   12.31it/s]
 55%|#####4    | Fitting SlidingEstimator : 17/31 [00:01<00:01,   12.06it/s]
 58%|#####8    | Fitting SlidingEstimator : 18/31 [00:01<00:01,   11.85it/s]
 61%|######1   | Fitting SlidingEstimator : 19/31 [00:01<00:00,   12.04it/s]
 65%|######4   | Fitting SlidingEstimator : 20/31 [00:01<00:00,   12.62it/s]
 68%|######7   | Fitting SlidingEstimator : 21/31 [00:01<00:00,   12.37it/s]
 71%|#######   | Fitting SlidingEstimator : 22/31 [00:01<00:00,   12.29it/s]
 74%|#######4  | Fitting SlidingEstimator : 23/31 [00:01<00:00,   12.08it/s]
 77%|#######7  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   12.61it/s]
 81%|########  | Fitting SlidingEstimator : 25/31 [00:02<00:00,   12.74it/s]
 84%|########3 | Fitting SlidingEstimator : 26/31 [00:02<00:00,   12.50it/s]
 87%|########7 | Fitting SlidingEstimator : 27/31 [00:02<00:00,   12.29it/s]
 90%|######### | Fitting SlidingEstimator : 28/31 [00:02<00:00,   12.78it/s]
 94%|#########3| Fitting SlidingEstimator : 29/31 [00:02<00:00,   12.54it/s]
 97%|#########6| Fitting SlidingEstimator : 30/31 [00:02<00:00,   12.67it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.73it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.51it/s]

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|3         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.82it/s]
  6%|6         | Fitting SlidingEstimator : 2/31 [00:00<00:01,   14.84it/s]
 10%|9         | Fitting SlidingEstimator : 3/31 [00:00<00:02,   13.38it/s]
 13%|#2        | Fitting SlidingEstimator : 4/31 [00:00<00:02,   12.23it/s]
 16%|#6        | Fitting SlidingEstimator : 5/31 [00:00<00:01,   14.05it/s]
 19%|#9        | Fitting SlidingEstimator : 6/31 [00:00<00:01,   14.20it/s]
 23%|##2       | Fitting SlidingEstimator : 7/31 [00:00<00:01,   13.25it/s]
 26%|##5       | Fitting SlidingEstimator : 8/31 [00:00<00:01,   12.71it/s]
 29%|##9       | Fitting SlidingEstimator : 9/31 [00:00<00:01,   12.24it/s]
 32%|###2      | Fitting SlidingEstimator : 10/31 [00:00<00:01,   13.20it/s]
 35%|###5      | Fitting SlidingEstimator : 11/31 [00:00<00:01,   12.16it/s]
 39%|###8      | Fitting SlidingEstimator : 12/31 [00:00<00:01,   12.99it/s]
 42%|####1     | Fitting SlidingEstimator : 13/31 [00:01<00:01,   12.59it/s]
 45%|####5     | Fitting SlidingEstimator : 14/31 [00:01<00:01,   12.27it/s]
 48%|####8     | Fitting SlidingEstimator : 15/31 [00:01<00:01,   12.00it/s]
 52%|#####1    | Fitting SlidingEstimator : 16/31 [00:01<00:01,   12.26it/s]
 55%|#####4    | Fitting SlidingEstimator : 17/31 [00:01<00:01,   12.91it/s]
 58%|#####8    | Fitting SlidingEstimator : 18/31 [00:01<00:01,   12.60it/s]
 61%|######1   | Fitting SlidingEstimator : 19/31 [00:01<00:00,   12.33it/s]
 65%|######4   | Fitting SlidingEstimator : 20/31 [00:01<00:00,   12.10it/s]
 68%|######7   | Fitting SlidingEstimator : 21/31 [00:01<00:00,   12.67it/s]
 71%|#######   | Fitting SlidingEstimator : 22/31 [00:01<00:00,   12.80it/s]
 74%|#######4  | Fitting SlidingEstimator : 23/31 [00:01<00:00,   12.54it/s]
 77%|#######7  | Fitting SlidingEstimator : 24/31 [00:01<00:00,   12.68it/s]
 81%|########  | Fitting SlidingEstimator : 25/31 [00:01<00:00,   12.81it/s]
 84%|########3 | Fitting SlidingEstimator : 26/31 [00:02<00:00,   12.93it/s]
 87%|########7 | Fitting SlidingEstimator : 27/31 [00:02<00:00,   12.67it/s]
 90%|######### | Fitting SlidingEstimator : 28/31 [00:02<00:00,   12.45it/s]
 94%|#########3| Fitting SlidingEstimator : 29/31 [00:02<00:00,   12.58it/s]
 97%|#########6| Fitting SlidingEstimator : 30/31 [00:02<00:00,   13.06it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.91it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:02<00:00,   12.79it/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

Out:

  0%|          | Fitting SlidingEstimator : 0/31 [00:00<?,       ?it/s]
  3%|3         | Fitting SlidingEstimator : 1/31 [00:00<00:02,   14.71it/s]
  6%|6         | Fitting SlidingEstimator : 2/31 [00:00<00:02,   11.77it/s]
 10%|9         | Fitting SlidingEstimator : 3/31 [00:00<00:02,   11.04it/s]
 13%|#2        | Fitting SlidingEstimator : 4/31 [00:00<00:02,   10.70it/s]
 16%|#6        | Fitting SlidingEstimator : 5/31 [00:00<00:02,   10.51it/s]
 19%|#9        | Fitting SlidingEstimator : 6/31 [00:00<00:02,   10.39it/s]
 23%|##2       | Fitting SlidingEstimator : 7/31 [00:00<00:02,   10.30it/s]
 26%|##5       | Fitting SlidingEstimator : 8/31 [00:00<00:02,   10.24it/s]
 29%|##9       | Fitting SlidingEstimator : 9/31 [00:00<00:02,   10.20it/s]
 32%|###2      | Fitting SlidingEstimator : 10/31 [00:00<00:02,    9.98it/s]
 35%|###5      | Fitting SlidingEstimator : 11/31 [00:01<00:02,    9.97it/s]
 39%|###8      | Fitting SlidingEstimator : 12/31 [00:01<00:01,    9.96it/s]
 42%|####1     | Fitting SlidingEstimator : 13/31 [00:01<00:01,    9.96it/s]
 45%|####5     | Fitting SlidingEstimator : 14/31 [00:01<00:01,    9.95it/s]
 48%|####8     | Fitting SlidingEstimator : 15/31 [00:01<00:01,    9.95it/s]
 52%|#####1    | Fitting SlidingEstimator : 16/31 [00:01<00:01,   10.00it/s]
 55%|#####4    | Fitting SlidingEstimator : 17/31 [00:01<00:01,    9.99it/s]
 58%|#####8    | Fitting SlidingEstimator : 18/31 [00:01<00:01,   10.00it/s]
 61%|######1   | Fitting SlidingEstimator : 19/31 [00:01<00:01,    9.99it/s]
 65%|######4   | Fitting SlidingEstimator : 20/31 [00:01<00:01,    9.99it/s]
 68%|######7   | Fitting SlidingEstimator : 21/31 [00:02<00:01,    9.98it/s]
 71%|#######   | Fitting SlidingEstimator : 22/31 [00:02<00:00,    9.97it/s]
 74%|#######4  | Fitting SlidingEstimator : 23/31 [00:02<00:00,    9.54it/s]
 77%|#######7  | Fitting SlidingEstimator : 24/31 [00:02<00:00,    9.79it/s]
 81%|########  | Fitting SlidingEstimator : 25/31 [00:02<00:00,    9.80it/s]
 84%|########3 | Fitting SlidingEstimator : 26/31 [00:02<00:00,   10.03it/s]
 87%|########7 | Fitting SlidingEstimator : 27/31 [00:02<00:00,   10.02it/s]
 90%|######### | Fitting SlidingEstimator : 28/31 [00:02<00:00,   10.04it/s]
 94%|#########3| Fitting SlidingEstimator : 29/31 [00:02<00:00,   10.03it/s]
 97%|#########6| Fitting SlidingEstimator : 30/31 [00:02<00:00,   10.03it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:03<00:00,   10.22it/s]
100%|##########| Fitting SlidingEstimator : 31/31 [00:03<00:00,   10.12it/s]
Using control points [ 3.50724321  4.37721471 15.59502306]

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

Estimated memory usage: 376 MB

Gallery generated by Sphinx-Gallery