Note
Click here to download the full example code
Decoding (MVPA)¶
Design philosophy¶
Decoding (a.k.a. MVPA) in MNE largely follows the machine
learning API of the scikit-learn package.
Each estimator implements fit
, transform
, fit_transform
, and
(optionally) inverse_transform
methods. For more details on this design,
visit scikit-learn. For additional theoretical insights into the decoding
framework in MNE 1.
For ease of comprehension, we will denote instantiations of the class using the same name as the class but in small caps instead of camel cases.
Let’s start by loading data for a simple two-class problem:
import numpy as np
import matplotlib.pyplot as plt
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.linear_model import LogisticRegression
import mne
from mne.datasets import sample
from mne.decoding import (SlidingEstimator, GeneralizingEstimator, Scaler,
cross_val_multiscore, LinearModel, get_coef,
Vectorizer, CSP)
data_path = sample.data_path()
subjects_dir = data_path + '/subjects'
raw_fname = data_path + '/MEG/sample/sample_audvis_raw.fif'
tmin, tmax = -0.200, 0.500
event_id = {'Auditory/Left': 1, 'Visual/Left': 3} # just use two
raw = mne.io.read_raw_fif(raw_fname, preload=True)
# The subsequent decoding analyses only capture evoked responses, so we can
# low-pass the MEG data. Usually a value more like 40 Hz would be used,
# but here low-pass at 20 so we can more heavily decimate, and allow
# the examlpe to run faster. The 2 Hz high-pass helps improve CSP.
raw.filter(2, 20)
events = mne.find_events(raw, 'STI 014')
# Set up pick list: EEG + MEG - bad channels (modify to your needs)
raw.info['bads'] += ['MEG 2443', 'EEG 053'] # bads + 2 more
# Read epochs
epochs = mne.Epochs(raw, events, event_id, tmin, tmax, proj=True,
picks=('grad', 'eog'), baseline=(None, 0.), preload=True,
reject=dict(grad=4000e-13, eog=150e-6), decim=10)
epochs.pick_types(meg=True, exclude='bads') # remove stim and EOG
del raw
X = epochs.get_data() # MEG signals: n_epochs, n_meg_channels, n_times
y = epochs.events[:, 2] # target: auditory left vs visual left
Out:
Opening raw data file /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis_raw.fif...
Read a total of 3 projection items:
PCA-v1 (1 x 102) idle
PCA-v2 (1 x 102) idle
PCA-v3 (1 x 102) idle
Range : 25800 ... 192599 = 42.956 ... 320.670 secs
Ready.
Reading 0 ... 166799 = 0.000 ... 277.714 secs...
Filtering raw data in 1 contiguous segment
Setting up band-pass filter from 2 - 20 Hz
FIR filter parameters
---------------------
Designing a one-pass, zero-phase, non-causal bandpass filter:
- Windowed time-domain design (firwin) method
- Hamming window with 0.0194 passband ripple and 53 dB stopband attenuation
- Lower passband edge: 2.00
- Lower transition bandwidth: 2.00 Hz (-6 dB cutoff frequency: 1.00 Hz)
- Upper passband edge: 20.00 Hz
- Upper transition bandwidth: 5.00 Hz (-6 dB cutoff frequency: 22.50 Hz)
- Filter length: 993 samples (1.653 sec)
320 events found
Event IDs: [ 1 2 3 4 5 32]
Not setting metadata
Not setting metadata
145 matching events found
Setting baseline interval to [-0.19979521315838786, 0.0] sec
Applying baseline correction (mode: mean)
3 projection items activated
Loading data for 145 events and 421 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']
22 bad epochs dropped
Removing projector <Projection | PCA-v1, active : True, n_channels : 102>
Removing projector <Projection | PCA-v2, active : True, n_channels : 102>
Removing projector <Projection | PCA-v3, active : True, n_channels : 102>
Transformation classes¶
Scaler¶
The mne.decoding.Scaler
will standardize the data based on channel
scales. In the simplest modes scalings=None
or scalings=dict(...)
,
each data channel type (e.g., mag, grad, eeg) is treated separately and
scaled by a constant. This is the approach used by e.g.,
mne.compute_covariance()
to standardize channel scales.
If scalings='mean'
or scalings='median'
, each channel is scaled using
empirical measures. Each channel is scaled independently by the mean and
standand deviation, or median and interquartile range, respectively, across
all epochs and time points during fit
(during training). The transform()
method is
called to transform data (training or test set) by scaling all time points
and epochs on a channel-by-channel basis. To perform both the fit
and
transform
operations in a single call, the
fit_transform()
method may be used. To invert the
transform, inverse_transform()
can be used. For
scalings='median'
, scikit-learn version 0.17+ is required.
Note
Using this class is different from directly applying
sklearn.preprocessing.StandardScaler
or
sklearn.preprocessing.RobustScaler
offered by
scikit-learn. These scale each classification feature, e.g.
each time point for each channel, with mean and standard
deviation computed across epochs, whereas
mne.decoding.Scaler
scales each channel using mean and
standard deviation computed across all of its time points
and epochs.
Vectorizer¶
Scikit-learn API provides functionality to chain transformers and estimators
by using sklearn.pipeline.Pipeline
. We can construct decoding
pipelines and perform cross-validation and grid-search. However scikit-learn
transformers and estimators generally expect 2D data
(n_samples * n_features), whereas MNE transformers typically output data
with a higher dimensionality
(e.g. n_samples * n_channels * n_frequencies * n_times). A Vectorizer
therefore needs to be applied between the MNE and the scikit-learn steps
like:
# Uses all MEG sensors and time points as separate classification
# features, so the resulting filters used are spatio-temporal
clf = make_pipeline(Scaler(epochs.info),
Vectorizer(),
LogisticRegression(solver='lbfgs'))
scores = cross_val_multiscore(clf, X, y, cv=5, n_jobs=1)
# Mean scores across cross-validation splits
score = np.mean(scores, axis=0)
print('Spatio-temporal: %0.1f%%' % (100 * score,))
Out:
Spatio-temporal: 99.2%
PSDEstimator¶
The mne.decoding.PSDEstimator
computes the power spectral density (PSD) using the multitaper
method. It takes a 3D array as input, converts it into 2D and computes the
PSD.
FilterEstimator¶
The mne.decoding.FilterEstimator
filters the 3D epochs data.
Spatial filters¶
Just like temporal filters, spatial filters provide weights to modify the data along the sensor dimension. They are popular in the BCI community because of their simplicity and ability to distinguish spatially-separated neural activity.
Common spatial pattern¶
mne.decoding.CSP
is a technique to analyze multichannel data based
on recordings from two classes 2 (see also
https://en.wikipedia.org/wiki/Common_spatial_pattern).
Let \(X \in R^{C\times T}\) be a segment of data with \(C\) channels and \(T\) time points. The data at a single time point is denoted by \(x(t)\) such that \(X=[x(t), x(t+1), ..., x(t+T-1)]\). Common spatial pattern (CSP) finds a decomposition that projects the signal in the original sensor space to CSP space using the following transformation:
where each column of \(W \in R^{C\times C}\) is a spatial filter and each row of \(x_{CSP}\) is a CSP component. The matrix \(W\) is also called the de-mixing matrix in other contexts. Let \(\Sigma^{+} \in R^{C\times C}\) and \(\Sigma^{-} \in R^{C\times C}\) be the estimates of the covariance matrices of the two conditions. CSP analysis is given by the simultaneous diagonalization of the two covariance matrices
where \(\lambda^{C}\) is a diagonal matrix whose entries are the eigenvalues of the following generalized eigenvalue problem
Large entries in the diagonal matrix corresponds to a spatial filter which gives high variance in one class but low variance in the other. Thus, the filter facilitates discrimination between the two classes.
Examples
Note
The winning entry of the Grasp-and-lift EEG competition in Kaggle used
the CSP
implementation in MNE and was featured as
a script of the week.
We can use CSP with these data with:
csp = CSP(n_components=3, norm_trace=False)
clf_csp = make_pipeline(csp, LinearModel(LogisticRegression(solver='lbfgs')))
scores = cross_val_multiscore(clf_csp, X, y, cv=5, n_jobs=1)
print('CSP: %0.1f%%' % (100 * scores.mean(),))
Out:
Computing rank from data with rank=None
Using tolerance 4.4e-11 (2.2e-16 eps * 203 dim * 9.7e+02 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 5.2e-11 (2.2e-16 eps * 203 dim * 1.1e+03 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 4.2e-11 (2.2e-16 eps * 203 dim * 9.3e+02 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 5.2e-11 (2.2e-16 eps * 203 dim * 1.2e+03 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 4.2e-11 (2.2e-16 eps * 203 dim * 9.4e+02 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 5.2e-11 (2.2e-16 eps * 203 dim * 1.1e+03 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 4.2e-11 (2.2e-16 eps * 203 dim * 9.4e+02 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 5e-11 (2.2e-16 eps * 203 dim * 1.1e+03 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 4.2e-11 (2.2e-16 eps * 203 dim * 9.3e+02 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 5.2e-11 (2.2e-16 eps * 203 dim * 1.1e+03 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
CSP: 87.0%
Source power comodulation (SPoC)¶
Source Power Comodulation (mne.decoding.SPoC
)
3 identifies the composition of
orthogonal spatial filters that maximally correlate with a continuous target.
SPoC can be seen as an extension of the CSP where the target is driven by a continuous variable rather than a discrete variable. Typical applications include extraction of motor patterns using EMG power or audio patterns using sound envelope.
Examples
xDAWN¶
mne.preprocessing.Xdawn
is a spatial filtering method designed to
improve the signal to signal + noise ratio (SSNR) of the ERP responses
4. Xdawn was originally
designed for P300 evoked potential by enhancing the target response with
respect to the non-target response. The implementation in MNE-Python is a
generalization to any type of ERP.
Effect-matched spatial filtering¶
The result of mne.decoding.EMS
is a spatial filter at each time
point and a corresponding time course 5.
Intuitively, the result gives the similarity between the filter at
each time point and the data vector (sensors) at that time point.
Patterns vs. filters¶
When interpreting the components of the CSP (or spatial filters in general), it is often more intuitive to think about how \(x(t)\) is composed of the different CSP components \(x_{CSP}(t)\). In other words, we can rewrite Equation (1) as follows:
The columns of the matrix \((W^{-1})^T\) are called spatial patterns. This is also called the mixing matrix. The example Linear classifier on sensor data with plot patterns and filters discusses the difference between patterns and filters.
These can be plotted with:
# Fit CSP on full data and plot
csp.fit(X, y)
csp.plot_patterns(epochs.info)
csp.plot_filters(epochs.info, scalings=1e-9)
Out:
Computing rank from data with rank=None
Using tolerance 4.8e-11 (2.2e-16 eps * 203 dim * 1.1e+03 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Computing rank from data with rank=None
Using tolerance 5.7e-11 (2.2e-16 eps * 203 dim * 1.3e+03 max singular value)
Estimated rank (mag): 203
MAG: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Decoding over time¶
This strategy consists in fitting a multivariate predictive model on each
time instant and evaluating its performance at the same instant on new
epochs. The mne.decoding.SlidingEstimator
will take as input a
pair of features \(X\) and targets \(y\), where \(X\) has
more than 2 dimensions. For decoding over time the data \(X\)
is the epochs data of shape n_epochs x n_channels x n_times. As the
last dimension of \(X\) is the time, an estimator will be fit
on every time instant.
This approach is analogous to SlidingEstimator-based approaches in fMRI, where here we are interested in when one can discriminate experimental conditions and therefore figure out when the effect of interest happens.
When working with linear models as estimators, this approach boils down to estimating a discriminative spatial filter for each time instant.
Temporal decoding¶
We’ll use a Logistic Regression for a binary classification as machine learning model.
# We will train the classifier on all left visual vs auditory trials on MEG
clf = make_pipeline(StandardScaler(), LogisticRegression(solver='lbfgs'))
time_decod = SlidingEstimator(clf, n_jobs=1, scoring='roc_auc', verbose=True)
scores = cross_val_multiscore(time_decod, X, y, cv=5, n_jobs=1)
# Mean scores across cross-validation splits
scores = np.mean(scores, axis=0)
# Plot
fig, ax = plt.subplots()
ax.plot(epochs.times, scores, label='score')
ax.axhline(.5, color='k', linestyle='--', label='chance')
ax.set_xlabel('Times')
ax.set_ylabel('AUC') # Area Under the Curve
ax.legend()
ax.axvline(.0, color='k', linestyle='-')
ax.set_title('Sensor space decoding')
Out:
0%| | Fitting SlidingEstimator : 0/43 [00:00<?, ?it/s]
5%|4 | Fitting SlidingEstimator : 2/43 [00:00<00:00, 56.98it/s]
7%|6 | Fitting SlidingEstimator : 3/43 [00:00<00:00, 43.16it/s]
12%|#1 | Fitting SlidingEstimator : 5/43 [00:00<00:00, 48.55it/s]
14%|#3 | Fitting SlidingEstimator : 6/43 [00:00<00:01, 33.93it/s]
19%|#8 | Fitting SlidingEstimator : 8/43 [00:00<00:00, 38.38it/s]
26%|##5 | Fitting SlidingEstimator : 11/43 [00:00<00:00, 35.42it/s]
28%|##7 | Fitting SlidingEstimator : 12/43 [00:00<00:00, 31.37it/s]
30%|### | Fitting SlidingEstimator : 13/43 [00:00<00:00, 31.05it/s]
33%|###2 | Fitting SlidingEstimator : 14/43 [00:00<00:01, 28.52it/s]
37%|###7 | Fitting SlidingEstimator : 16/43 [00:00<00:00, 31.04it/s]
40%|###9 | Fitting SlidingEstimator : 17/43 [00:00<00:00, 28.73it/s]
44%|####4 | Fitting SlidingEstimator : 19/43 [00:00<00:00, 30.77it/s]
47%|####6 | Fitting SlidingEstimator : 20/43 [00:00<00:00, 28.89it/s]
51%|#####1 | Fitting SlidingEstimator : 22/43 [00:00<00:00, 30.41it/s]
53%|#####3 | Fitting SlidingEstimator : 23/43 [00:00<00:00, 29.01it/s]
60%|###### | Fitting SlidingEstimator : 26/43 [00:00<00:00, 32.51it/s]
65%|######5 | Fitting SlidingEstimator : 28/43 [00:00<00:00, 32.34it/s]
70%|######9 | Fitting SlidingEstimator : 30/43 [00:00<00:00, 33.83it/s]
72%|#######2 | Fitting SlidingEstimator : 31/43 [00:00<00:00, 31.79it/s]
79%|#######9 | Fitting SlidingEstimator : 34/43 [00:01<00:00, 34.69it/s]
81%|########1 | Fitting SlidingEstimator : 35/43 [00:01<00:00, 32.97it/s]
88%|########8 | Fitting SlidingEstimator : 38/43 [00:01<00:00, 35.68it/s]
91%|######### | Fitting SlidingEstimator : 39/43 [00:01<00:00, 33.83it/s]
98%|#########7| Fitting SlidingEstimator : 42/43 [00:01<00:00, 36.42it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 35.39it/s]
0%| | Fitting SlidingEstimator : 0/43 [00:00<?, ?it/s]
7%|6 | Fitting SlidingEstimator : 3/43 [00:00<00:00, 42.12it/s]
9%|9 | Fitting SlidingEstimator : 4/43 [00:00<00:01, 28.82it/s]
16%|#6 | Fitting SlidingEstimator : 7/43 [00:00<00:00, 40.74it/s]
19%|#8 | Fitting SlidingEstimator : 8/43 [00:00<00:01, 33.48it/s]
26%|##5 | Fitting SlidingEstimator : 11/43 [00:00<00:00, 41.11it/s]
28%|##7 | Fitting SlidingEstimator : 12/43 [00:00<00:00, 35.38it/s]
33%|###2 | Fitting SlidingEstimator : 14/43 [00:00<00:00, 37.66it/s]
35%|###4 | Fitting SlidingEstimator : 15/43 [00:00<00:00, 33.81it/s]
44%|####4 | Fitting SlidingEstimator : 19/43 [00:00<00:00, 41.30it/s]
49%|####8 | Fitting SlidingEstimator : 21/43 [00:00<00:00, 39.32it/s]
56%|#####5 | Fitting SlidingEstimator : 24/43 [00:00<00:00, 43.06it/s]
58%|#####8 | Fitting SlidingEstimator : 25/43 [00:00<00:00, 39.53it/s]
63%|######2 | Fitting SlidingEstimator : 27/43 [00:00<00:00, 40.82it/s]
65%|######5 | Fitting SlidingEstimator : 28/43 [00:00<00:00, 37.70it/s]
67%|######7 | Fitting SlidingEstimator : 29/43 [00:00<00:00, 37.00it/s]
70%|######9 | Fitting SlidingEstimator : 30/43 [00:00<00:00, 34.68it/s]
74%|#######4 | Fitting SlidingEstimator : 32/43 [00:00<00:00, 35.68it/s]
77%|#######6 | Fitting SlidingEstimator : 33/43 [00:00<00:00, 33.88it/s]
81%|########1 | Fitting SlidingEstimator : 35/43 [00:00<00:00, 35.17it/s]
84%|########3 | Fitting SlidingEstimator : 36/43 [00:01<00:00, 33.24it/s]
91%|######### | Fitting SlidingEstimator : 39/43 [00:01<00:00, 32.79it/s]
95%|#########5| Fitting SlidingEstimator : 41/43 [00:01<00:00, 33.99it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 32.89it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 34.24it/s]
0%| | Fitting SlidingEstimator : 0/43 [00:00<?, ?it/s]
5%|4 | Fitting SlidingEstimator : 2/43 [00:00<00:00, 58.82it/s]
7%|6 | Fitting SlidingEstimator : 3/43 [00:00<00:00, 40.58it/s]
14%|#3 | Fitting SlidingEstimator : 6/43 [00:00<00:00, 56.31it/s]
16%|#6 | Fitting SlidingEstimator : 7/43 [00:00<00:00, 39.73it/s]
21%|## | Fitting SlidingEstimator : 9/43 [00:00<00:00, 43.16it/s]
23%|##3 | Fitting SlidingEstimator : 10/43 [00:00<00:00, 35.64it/s]
28%|##7 | Fitting SlidingEstimator : 12/43 [00:00<00:00, 38.54it/s]
30%|### | Fitting SlidingEstimator : 13/43 [00:00<00:00, 33.76it/s]
37%|###7 | Fitting SlidingEstimator : 16/43 [00:00<00:00, 39.26it/s]
40%|###9 | Fitting SlidingEstimator : 17/43 [00:00<00:00, 35.06it/s]
49%|####8 | Fitting SlidingEstimator : 21/43 [00:00<00:00, 41.96it/s]
53%|#####3 | Fitting SlidingEstimator : 23/43 [00:00<00:00, 40.39it/s]
60%|###### | Fitting SlidingEstimator : 26/43 [00:00<00:00, 43.95it/s]
65%|######5 | Fitting SlidingEstimator : 28/43 [00:00<00:00, 42.14it/s]
72%|#######2 | Fitting SlidingEstimator : 31/43 [00:00<00:00, 45.22it/s]
74%|#######4 | Fitting SlidingEstimator : 32/43 [00:00<00:00, 41.61it/s]
81%|########1 | Fitting SlidingEstimator : 35/43 [00:00<00:00, 44.41it/s]
84%|########3 | Fitting SlidingEstimator : 36/43 [00:00<00:00, 41.16it/s]
91%|######### | Fitting SlidingEstimator : 39/43 [00:00<00:00, 43.83it/s]
93%|#########3| Fitting SlidingEstimator : 40/43 [00:00<00:00, 40.90it/s]
98%|#########7| Fitting SlidingEstimator : 42/43 [00:01<00:00, 41.03it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 42.11it/s]
0%| | Fitting SlidingEstimator : 0/43 [00:00<?, ?it/s]
7%|6 | Fitting SlidingEstimator : 3/43 [00:00<00:01, 34.14it/s]
9%|9 | Fitting SlidingEstimator : 4/43 [00:00<00:01, 25.73it/s]
14%|#3 | Fitting SlidingEstimator : 6/43 [00:00<00:01, 32.15it/s]
19%|#8 | Fitting SlidingEstimator : 8/43 [00:00<00:01, 31.60it/s]
23%|##3 | Fitting SlidingEstimator : 10/43 [00:00<00:00, 35.20it/s]
26%|##5 | Fitting SlidingEstimator : 11/43 [00:00<00:01, 30.94it/s]
33%|###2 | Fitting SlidingEstimator : 14/43 [00:00<00:00, 36.73it/s]
40%|###9 | Fitting SlidingEstimator : 17/43 [00:00<00:00, 35.26it/s]
44%|####4 | Fitting SlidingEstimator : 19/43 [00:00<00:00, 34.50it/s]
53%|#####3 | Fitting SlidingEstimator : 23/43 [00:00<00:00, 40.50it/s]
56%|#####5 | Fitting SlidingEstimator : 24/43 [00:00<00:00, 37.27it/s]
65%|######5 | Fitting SlidingEstimator : 28/43 [00:00<00:00, 42.55it/s]
67%|######7 | Fitting SlidingEstimator : 29/43 [00:00<00:00, 39.30it/s]
74%|#######4 | Fitting SlidingEstimator : 32/43 [00:00<00:00, 42.04it/s]
77%|#######6 | Fitting SlidingEstimator : 33/43 [00:00<00:00, 39.29it/s]
84%|########3 | Fitting SlidingEstimator : 36/43 [00:00<00:00, 41.51it/s]
86%|########6 | Fitting SlidingEstimator : 37/43 [00:00<00:00, 39.30it/s]
93%|#########3| Fitting SlidingEstimator : 40/43 [00:00<00:00, 41.88it/s]
95%|#########5| Fitting SlidingEstimator : 41/43 [00:01<00:00, 39.27it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 41.13it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 40.03it/s]
0%| | Fitting SlidingEstimator : 0/43 [00:00<?, ?it/s]
5%|4 | Fitting SlidingEstimator : 2/43 [00:00<00:00, 58.59it/s]
12%|#1 | Fitting SlidingEstimator : 5/43 [00:00<00:00, 48.73it/s]
14%|#3 | Fitting SlidingEstimator : 6/43 [00:00<00:01, 35.02it/s]
19%|#8 | Fitting SlidingEstimator : 8/43 [00:00<00:00, 38.88it/s]
21%|## | Fitting SlidingEstimator : 9/43 [00:00<00:01, 32.80it/s]
26%|##5 | Fitting SlidingEstimator : 11/43 [00:00<00:00, 35.47it/s]
28%|##7 | Fitting SlidingEstimator : 12/43 [00:00<00:00, 31.81it/s]
30%|### | Fitting SlidingEstimator : 13/43 [00:00<00:00, 31.39it/s]
33%|###2 | Fitting SlidingEstimator : 14/43 [00:00<00:01, 28.77it/s]
40%|###9 | Fitting SlidingEstimator : 17/43 [00:00<00:00, 33.77it/s]
42%|####1 | Fitting SlidingEstimator : 18/43 [00:00<00:00, 31.06it/s]
51%|#####1 | Fitting SlidingEstimator : 22/43 [00:00<00:00, 37.40it/s]
53%|#####3 | Fitting SlidingEstimator : 23/43 [00:00<00:00, 34.55it/s]
60%|###### | Fitting SlidingEstimator : 26/43 [00:00<00:00, 38.11it/s]
65%|######5 | Fitting SlidingEstimator : 28/43 [00:00<00:00, 37.19it/s]
72%|#######2 | Fitting SlidingEstimator : 31/43 [00:00<00:00, 39.79it/s]
74%|#######4 | Fitting SlidingEstimator : 32/43 [00:00<00:00, 37.54it/s]
81%|########1 | Fitting SlidingEstimator : 35/43 [00:00<00:00, 40.43it/s]
86%|########6 | Fitting SlidingEstimator : 37/43 [00:00<00:00, 39.37it/s]
93%|#########3| Fitting SlidingEstimator : 40/43 [00:01<00:00, 41.99it/s]
95%|#########5| Fitting SlidingEstimator : 41/43 [00:01<00:00, 39.34it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 41.18it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 39.50it/s]
You can retrieve the spatial filters and spatial patterns if you explicitly use a LinearModel
clf = make_pipeline(StandardScaler(),
LinearModel(LogisticRegression(solver='lbfgs')))
time_decod = SlidingEstimator(clf, n_jobs=1, scoring='roc_auc', verbose=True)
time_decod.fit(X, y)
coef = get_coef(time_decod, 'patterns_', inverse_transform=True)
evoked_time_gen = mne.EvokedArray(coef, epochs.info, tmin=epochs.times[0])
joint_kwargs = dict(ts_args=dict(time_unit='s'),
topomap_args=dict(time_unit='s'))
evoked_time_gen.plot_joint(times=np.arange(0., .500, .100), title='patterns',
**joint_kwargs)
Out:
0%| | Fitting SlidingEstimator : 0/43 [00:00<?, ?it/s]
2%|2 | Fitting SlidingEstimator : 1/43 [00:00<00:01, 28.78it/s]
7%|6 | Fitting SlidingEstimator : 3/43 [00:00<00:01, 26.32it/s]
12%|#1 | Fitting SlidingEstimator : 5/43 [00:00<00:01, 34.12it/s]
14%|#3 | Fitting SlidingEstimator : 6/43 [00:00<00:01, 27.74it/s]
16%|#6 | Fitting SlidingEstimator : 7/43 [00:00<00:01, 21.65it/s]
21%|## | Fitting SlidingEstimator : 9/43 [00:00<00:01, 25.75it/s]
23%|##3 | Fitting SlidingEstimator : 10/43 [00:00<00:01, 23.85it/s]
28%|##7 | Fitting SlidingEstimator : 12/43 [00:00<00:01, 27.01it/s]
30%|### | Fitting SlidingEstimator : 13/43 [00:00<00:01, 25.17it/s]
35%|###4 | Fitting SlidingEstimator : 15/43 [00:00<00:01, 27.78it/s]
40%|###9 | Fitting SlidingEstimator : 17/43 [00:00<00:00, 28.14it/s]
47%|####6 | Fitting SlidingEstimator : 20/43 [00:00<00:00, 32.29it/s]
49%|####8 | Fitting SlidingEstimator : 21/43 [00:00<00:00, 30.18it/s]
56%|#####5 | Fitting SlidingEstimator : 24/43 [00:00<00:00, 33.71it/s]
58%|#####8 | Fitting SlidingEstimator : 25/43 [00:00<00:00, 31.72it/s]
65%|######5 | Fitting SlidingEstimator : 28/43 [00:00<00:00, 35.03it/s]
67%|######7 | Fitting SlidingEstimator : 29/43 [00:00<00:00, 32.90it/s]
72%|#######2 | Fitting SlidingEstimator : 31/43 [00:00<00:00, 34.23it/s]
74%|#######4 | Fitting SlidingEstimator : 32/43 [00:01<00:00, 32.39it/s]
79%|#######9 | Fitting SlidingEstimator : 34/43 [00:01<00:00, 33.76it/s]
81%|########1 | Fitting SlidingEstimator : 35/43 [00:01<00:00, 31.98it/s]
88%|########8 | Fitting SlidingEstimator : 38/43 [00:01<00:00, 34.74it/s]
91%|######### | Fitting SlidingEstimator : 39/43 [00:01<00:00, 32.96it/s]
95%|#########5| Fitting SlidingEstimator : 41/43 [00:01<00:00, 34.04it/s]
98%|#########7| Fitting SlidingEstimator : 42/43 [00:01<00:00, 32.52it/s]
100%|##########| Fitting SlidingEstimator : 43/43 [00:01<00:00, 32.53it/s]
No projector specified for this dataset. Please consider the method self.add_proj.
Temporal generalization¶
Temporal generalization is an extension of the decoding over time approach. It consists in evaluating whether the model estimated at a particular time instant accurately predicts any other time instant. It is analogous to transferring a trained model to a distinct learning problem, where the problems correspond to decoding the patterns of brain activity recorded at distinct time instants.
The object to for Temporal generalization is
mne.decoding.GeneralizingEstimator
. It expects as input \(X\)
and \(y\) (similarly to SlidingEstimator
) but
generates predictions from each model for all time instants. The class
GeneralizingEstimator
is generic and will treat the
last dimension as the one to be used for generalization testing. For
convenience, here, we refer to it as different tasks. If \(X\)
corresponds to epochs data then the last dimension is time.
This runs the analysis used in 6 and further detailed in 7:
# define the Temporal generalization object
time_gen = GeneralizingEstimator(clf, n_jobs=1, scoring='roc_auc',
verbose=True)
scores = cross_val_multiscore(time_gen, X, y, cv=5, n_jobs=1)
# Mean scores across cross-validation splits
scores = np.mean(scores, axis=0)
# Plot the diagonal (it's exactly the same as the time-by-time decoding above)
fig, ax = plt.subplots()
ax.plot(epochs.times, np.diag(scores), label='score')
ax.axhline(.5, color='k', linestyle='--', label='chance')
ax.set_xlabel('Times')
ax.set_ylabel('AUC')
ax.legend()
ax.axvline(.0, color='k', linestyle='-')
ax.set_title('Decoding MEG sensors over time')
Out:
0%| | Fitting GeneralizingEstimator : 0/43 [00:00<?, ?it/s]
2%|2 | Fitting GeneralizingEstimator : 1/43 [00:00<00:01, 28.62it/s]
7%|6 | Fitting GeneralizingEstimator : 3/43 [00:00<00:00, 43.99it/s]
12%|#1 | Fitting GeneralizingEstimator : 5/43 [00:00<00:01, 22.69it/s]
19%|#8 | Fitting GeneralizingEstimator : 8/43 [00:00<00:01, 32.18it/s]
23%|##3 | Fitting GeneralizingEstimator : 10/43 [00:00<00:01, 28.46it/s]
26%|##5 | Fitting GeneralizingEstimator : 11/43 [00:00<00:01, 28.56it/s]
28%|##7 | Fitting GeneralizingEstimator : 12/43 [00:00<00:01, 28.66it/s]
33%|###2 | Fitting GeneralizingEstimator : 14/43 [00:00<00:00, 31.35it/s]
35%|###4 | Fitting GeneralizingEstimator : 15/43 [00:00<00:00, 28.94it/s]
37%|###7 | Fitting GeneralizingEstimator : 16/43 [00:00<00:00, 28.46it/s]
40%|###9 | Fitting GeneralizingEstimator : 17/43 [00:00<00:00, 27.09it/s]
47%|####6 | Fitting GeneralizingEstimator : 20/43 [00:00<00:00, 31.16it/s]
49%|####8 | Fitting GeneralizingEstimator : 21/43 [00:00<00:00, 29.34it/s]
58%|#####8 | Fitting GeneralizingEstimator : 25/43 [00:00<00:00, 34.82it/s]
60%|###### | Fitting GeneralizingEstimator : 26/43 [00:00<00:00, 32.68it/s]
67%|######7 | Fitting GeneralizingEstimator : 29/43 [00:00<00:00, 35.95it/s]
70%|######9 | Fitting GeneralizingEstimator : 30/43 [00:00<00:00, 33.72it/s]
74%|#######4 | Fitting GeneralizingEstimator : 32/43 [00:00<00:00, 34.58it/s]
77%|#######6 | Fitting GeneralizingEstimator : 33/43 [00:01<00:00, 33.10it/s]
81%|########1 | Fitting GeneralizingEstimator : 35/43 [00:01<00:00, 34.42it/s]
86%|########6 | Fitting GeneralizingEstimator : 37/43 [00:01<00:00, 34.04it/s]
91%|######### | Fitting GeneralizingEstimator : 39/43 [00:01<00:00, 35.06it/s]
93%|#########3| Fitting GeneralizingEstimator : 40/43 [00:01<00:00, 33.43it/s]
98%|#########7| Fitting GeneralizingEstimator : 42/43 [00:01<00:00, 34.64it/s]
100%|##########| Fitting GeneralizingEstimator : 43/43 [00:01<00:00, 34.09it/s]
0%| | Scoring GeneralizingEstimator : 0/1849 [00:00<?, ?it/s]
1%|1 | Scoring GeneralizingEstimator : 19/1849 [00:00<00:06, 280.10it/s]
2%|2 | Scoring GeneralizingEstimator : 40/1849 [00:00<00:04, 395.00it/s]
3%|3 | Scoring GeneralizingEstimator : 59/1849 [00:00<00:04, 438.32it/s]
4%|4 | Scoring GeneralizingEstimator : 80/1849 [00:00<00:03, 477.28it/s]
6%|5 | Scoring GeneralizingEstimator : 109/1849 [00:00<00:03, 547.77it/s]
8%|7 | Scoring GeneralizingEstimator : 146/1849 [00:00<00:02, 636.85it/s]
10%|9 | Scoring GeneralizingEstimator : 177/1849 [00:00<00:02, 676.85it/s]
11%|#1 | Scoring GeneralizingEstimator : 212/1849 [00:00<00:02, 723.27it/s]
13%|#3 | Scoring GeneralizingEstimator : 248/1849 [00:00<00:02, 765.05it/s]
15%|#5 | Scoring GeneralizingEstimator : 281/1849 [00:00<00:01, 787.14it/s]
17%|#7 | Scoring GeneralizingEstimator : 318/1849 [00:00<00:01, 820.15it/s]
19%|#8 | Scoring GeneralizingEstimator : 349/1849 [00:00<00:01, 829.64it/s]
20%|## | Scoring GeneralizingEstimator : 373/1849 [00:00<00:01, 816.93it/s]
22%|##2 | Scoring GeneralizingEstimator : 408/1849 [00:00<00:01, 836.63it/s]
24%|##4 | Scoring GeneralizingEstimator : 444/1849 [00:00<00:01, 856.43it/s]
26%|##6 | Scoring GeneralizingEstimator : 481/1849 [00:00<00:01, 875.63it/s]
28%|##8 | Scoring GeneralizingEstimator : 518/1849 [00:00<00:01, 893.50it/s]
30%|##9 | Scoring GeneralizingEstimator : 554/1849 [00:00<00:01, 907.17it/s]
32%|###1 | Scoring GeneralizingEstimator : 591/1849 [00:00<00:01, 921.64it/s]
34%|###3 | Scoring GeneralizingEstimator : 625/1849 [00:00<00:01, 927.29it/s]
35%|###5 | Scoring GeneralizingEstimator : 655/1849 [00:00<00:01, 922.81it/s]
37%|###7 | Scoring GeneralizingEstimator : 689/1849 [00:00<00:01, 928.78it/s]
39%|###9 | Scoring GeneralizingEstimator : 725/1849 [00:00<00:01, 937.22it/s]
41%|####1 | Scoring GeneralizingEstimator : 760/1849 [00:00<00:01, 943.89it/s]
43%|####2 | Scoring GeneralizingEstimator : 794/1849 [00:00<00:01, 947.19it/s]
45%|####4 | Scoring GeneralizingEstimator : 826/1849 [00:00<00:01, 946.25it/s]
46%|####6 | Scoring GeneralizingEstimator : 854/1849 [00:00<00:01, 938.52it/s]
48%|####8 | Scoring GeneralizingEstimator : 889/1849 [00:00<00:01, 943.59it/s]
50%|##### | Scoring GeneralizingEstimator : 927/1849 [00:01<00:00, 954.96it/s]
52%|#####1 | Scoring GeneralizingEstimator : 956/1849 [00:01<00:00, 947.82it/s]
54%|#####3 | Scoring GeneralizingEstimator : 993/1849 [00:01<00:00, 956.35it/s]
56%|#####5 | Scoring GeneralizingEstimator : 1031/1849 [00:01<00:00, 966.50it/s]
58%|#####7 | Scoring GeneralizingEstimator : 1064/1849 [00:01<00:00, 966.63it/s]
60%|#####9 | Scoring GeneralizingEstimator : 1101/1849 [00:01<00:00, 973.17it/s]
62%|######1 | Scoring GeneralizingEstimator : 1138/1849 [00:01<00:00, 979.32it/s]
63%|######3 | Scoring GeneralizingEstimator : 1169/1849 [00:01<00:00, 975.69it/s]
65%|######4 | Scoring GeneralizingEstimator : 1200/1849 [00:01<00:00, 971.50it/s]
67%|######6 | Scoring GeneralizingEstimator : 1236/1849 [00:01<00:00, 976.72it/s]
69%|######8 | Scoring GeneralizingEstimator : 1267/1849 [00:01<00:00, 973.13it/s]
71%|####### | Scoring GeneralizingEstimator : 1304/1849 [00:01<00:00, 979.75it/s]
73%|#######2 | Scoring GeneralizingEstimator : 1342/1849 [00:01<00:00, 986.83it/s]
74%|#######3 | Scoring GeneralizingEstimator : 1368/1849 [00:01<00:00, 974.65it/s]
76%|#######6 | Scoring GeneralizingEstimator : 1406/1849 [00:01<00:00, 982.68it/s]
78%|#######7 | Scoring GeneralizingEstimator : 1441/1849 [00:01<00:00, 985.48it/s]
80%|#######9 | Scoring GeneralizingEstimator : 1470/1849 [00:01<00:00, 978.45it/s]
82%|########1 | Scoring GeneralizingEstimator : 1507/1849 [00:01<00:00, 984.21it/s]
83%|########3 | Scoring GeneralizingEstimator : 1542/1849 [00:01<00:00, 986.96it/s]
85%|########5 | Scoring GeneralizingEstimator : 1578/1849 [00:01<00:00, 990.52it/s]
87%|########7 | Scoring GeneralizingEstimator : 1615/1849 [00:01<00:00, 995.43it/s]
89%|########9 | Scoring GeneralizingEstimator : 1653/1849 [00:01<00:00, 1002.06it/s]
91%|#########1| Scoring GeneralizingEstimator : 1690/1849 [00:01<00:00, 1006.89it/s]
93%|#########3| Scoring GeneralizingEstimator : 1727/1849 [00:01<00:00, 1010.60it/s]
95%|#########5| Scoring GeneralizingEstimator : 1759/1849 [00:01<00:00, 1006.49it/s]
97%|#########7| Scoring GeneralizingEstimator : 1797/1849 [00:01<00:00, 1012.41it/s]
99%|#########9| Scoring GeneralizingEstimator : 1833/1849 [00:01<00:00, 1015.16it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:01<00:00, 961.26it/s]
0%| | Fitting GeneralizingEstimator : 0/43 [00:00<?, ?it/s]
5%|4 | Fitting GeneralizingEstimator : 2/43 [00:00<00:00, 58.96it/s]
7%|6 | Fitting GeneralizingEstimator : 3/43 [00:00<00:01, 35.14it/s]
12%|#1 | Fitting GeneralizingEstimator : 5/43 [00:00<00:00, 41.34it/s]
14%|#3 | Fitting GeneralizingEstimator : 6/43 [00:00<00:01, 31.96it/s]
19%|#8 | Fitting GeneralizingEstimator : 8/43 [00:00<00:00, 36.53it/s]
21%|## | Fitting GeneralizingEstimator : 9/43 [00:00<00:01, 31.02it/s]
28%|##7 | Fitting GeneralizingEstimator : 12/43 [00:00<00:00, 38.08it/s]
30%|### | Fitting GeneralizingEstimator : 13/43 [00:00<00:00, 33.46it/s]
35%|###4 | Fitting GeneralizingEstimator : 15/43 [00:00<00:00, 35.93it/s]
37%|###7 | Fitting GeneralizingEstimator : 16/43 [00:00<00:00, 32.48it/s]
44%|####4 | Fitting GeneralizingEstimator : 19/43 [00:00<00:00, 36.97it/s]
49%|####8 | Fitting GeneralizingEstimator : 21/43 [00:00<00:00, 36.13it/s]
56%|#####5 | Fitting GeneralizingEstimator : 24/43 [00:00<00:00, 39.96it/s]
58%|#####8 | Fitting GeneralizingEstimator : 25/43 [00:00<00:00, 36.73it/s]
65%|######5 | Fitting GeneralizingEstimator : 28/43 [00:00<00:00, 39.76it/s]
67%|######7 | Fitting GeneralizingEstimator : 29/43 [00:00<00:00, 37.17it/s]
72%|#######2 | Fitting GeneralizingEstimator : 31/43 [00:00<00:00, 38.47it/s]
77%|#######6 | Fitting GeneralizingEstimator : 33/43 [00:00<00:00, 37.58it/s]
81%|########1 | Fitting GeneralizingEstimator : 35/43 [00:00<00:00, 38.78it/s]
86%|########6 | Fitting GeneralizingEstimator : 37/43 [00:00<00:00, 37.90it/s]
91%|######### | Fitting GeneralizingEstimator : 39/43 [00:01<00:00, 38.93it/s]
93%|#########3| Fitting GeneralizingEstimator : 40/43 [00:01<00:00, 36.67it/s]
95%|#########5| Fitting GeneralizingEstimator : 41/43 [00:01<00:00, 36.22it/s]
98%|#########7| Fitting GeneralizingEstimator : 42/43 [00:01<00:00, 34.35it/s]
100%|##########| Fitting GeneralizingEstimator : 43/43 [00:01<00:00, 35.96it/s]
0%| | Scoring GeneralizingEstimator : 0/1849 [00:00<?, ?it/s]
1%|1 | Scoring GeneralizingEstimator : 19/1849 [00:00<00:06, 292.07it/s]
2%|2 | Scoring GeneralizingEstimator : 39/1849 [00:00<00:04, 396.87it/s]
4%|4 | Scoring GeneralizingEstimator : 76/1849 [00:00<00:03, 583.83it/s]
6%|6 | Scoring GeneralizingEstimator : 111/1849 [00:00<00:02, 683.27it/s]
8%|7 | Scoring GeneralizingEstimator : 140/1849 [00:00<00:02, 715.84it/s]
10%|9 | Scoring GeneralizingEstimator : 177/1849 [00:00<00:02, 777.72it/s]
11%|#1 | Scoring GeneralizingEstimator : 212/1849 [00:00<00:02, 815.29it/s]
13%|#3 | Scoring GeneralizingEstimator : 244/1849 [00:00<00:01, 832.23it/s]
15%|#5 | Scoring GeneralizingEstimator : 281/1849 [00:00<00:01, 863.90it/s]
17%|#7 | Scoring GeneralizingEstimator : 315/1849 [00:00<00:01, 879.30it/s]
18%|#8 | Scoring GeneralizingEstimator : 341/1849 [00:00<00:01, 866.84it/s]
20%|## | Scoring GeneralizingEstimator : 379/1849 [00:00<00:01, 891.61it/s]
22%|##2 | Scoring GeneralizingEstimator : 412/1849 [00:00<00:01, 897.59it/s]
24%|##3 | Scoring GeneralizingEstimator : 441/1849 [00:00<00:01, 893.82it/s]
26%|##5 | Scoring GeneralizingEstimator : 475/1849 [00:00<00:01, 903.62it/s]
27%|##7 | Scoring GeneralizingEstimator : 508/1849 [00:00<00:01, 908.99it/s]
29%|##9 | Scoring GeneralizingEstimator : 537/1849 [00:00<00:01, 904.46it/s]
31%|### | Scoring GeneralizingEstimator : 566/1849 [00:00<00:01, 899.69it/s]
32%|###2 | Scoring GeneralizingEstimator : 599/1849 [00:00<00:01, 904.92it/s]
34%|###4 | Scoring GeneralizingEstimator : 635/1849 [00:00<00:01, 915.02it/s]
36%|###6 | Scoring GeneralizingEstimator : 668/1849 [00:00<00:01, 919.51it/s]
38%|###7 | Scoring GeneralizingEstimator : 699/1849 [00:00<00:01, 919.04it/s]
39%|###9 | Scoring GeneralizingEstimator : 729/1849 [00:00<00:01, 916.16it/s]
41%|#### | Scoring GeneralizingEstimator : 757/1849 [00:00<00:01, 908.99it/s]
43%|####2 | Scoring GeneralizingEstimator : 793/1849 [00:00<00:01, 919.48it/s]
45%|####4 | Scoring GeneralizingEstimator : 829/1849 [00:00<00:01, 929.01it/s]
47%|####6 | Scoring GeneralizingEstimator : 864/1849 [00:00<00:01, 935.49it/s]
48%|####8 | Scoring GeneralizingEstimator : 896/1849 [00:00<00:01, 936.16it/s]
50%|##### | Scoring GeneralizingEstimator : 928/1849 [00:01<00:00, 935.27it/s]
52%|#####2 | Scoring GeneralizingEstimator : 964/1849 [00:01<00:00, 943.22it/s]
53%|#####3 | Scoring GeneralizingEstimator : 989/1849 [00:01<00:00, 929.37it/s]
55%|#####4 | Scoring GeneralizingEstimator : 1012/1849 [00:01<00:00, 913.34it/s]
56%|#####6 | Scoring GeneralizingEstimator : 1043/1849 [00:01<00:00, 913.43it/s]
58%|#####7 | Scoring GeneralizingEstimator : 1067/1849 [00:01<00:00, 901.08it/s]
59%|#####9 | Scoring GeneralizingEstimator : 1098/1849 [00:01<00:00, 901.28it/s]
61%|######1 | Scoring GeneralizingEstimator : 1135/1849 [00:01<00:00, 912.56it/s]
63%|######2 | Scoring GeneralizingEstimator : 1157/1849 [00:01<00:00, 897.42it/s]
64%|######4 | Scoring GeneralizingEstimator : 1192/1849 [00:01<00:00, 905.16it/s]
66%|######6 | Scoring GeneralizingEstimator : 1229/1849 [00:01<00:00, 915.76it/s]
68%|######7 | Scoring GeneralizingEstimator : 1252/1849 [00:01<00:00, 902.19it/s]
70%|######9 | Scoring GeneralizingEstimator : 1288/1849 [00:01<00:00, 911.22it/s]
71%|#######1 | Scoring GeneralizingEstimator : 1322/1849 [00:01<00:00, 916.44it/s]
72%|#######2 | Scoring GeneralizingEstimator : 1338/1849 [00:01<00:00, 891.31it/s]
74%|#######4 | Scoring GeneralizingEstimator : 1372/1849 [00:01<00:00, 897.36it/s]
76%|#######6 | Scoring GeneralizingEstimator : 1407/1849 [00:01<00:00, 904.26it/s]
77%|#######7 | Scoring GeneralizingEstimator : 1429/1849 [00:01<00:00, 889.56it/s]
78%|#######8 | Scoring GeneralizingEstimator : 1451/1849 [00:01<00:00, 876.47it/s]
80%|#######9 | Scoring GeneralizingEstimator : 1478/1849 [00:01<00:00, 871.85it/s]
81%|########1 | Scoring GeneralizingEstimator : 1503/1849 [00:01<00:00, 863.64it/s]
83%|########3 | Scoring GeneralizingEstimator : 1540/1849 [00:01<00:00, 875.92it/s]
85%|########5 | Scoring GeneralizingEstimator : 1575/1849 [00:01<00:00, 884.31it/s]
87%|########6 | Scoring GeneralizingEstimator : 1607/1849 [00:01<00:00, 887.13it/s]
88%|########8 | Scoring GeneralizingEstimator : 1631/1849 [00:01<00:00, 876.50it/s]
90%|########9 | Scoring GeneralizingEstimator : 1655/1849 [00:01<00:00, 867.39it/s]
91%|#########1| Scoring GeneralizingEstimator : 1685/1849 [00:01<00:00, 867.46it/s]
93%|#########3| Scoring GeneralizingEstimator : 1723/1849 [00:01<00:00, 880.43it/s]
95%|#########5| Scoring GeneralizingEstimator : 1758/1849 [00:01<00:00, 887.04it/s]
97%|#########6| Scoring GeneralizingEstimator : 1785/1849 [00:02<00:00, 881.66it/s]
98%|#########8| Scoring GeneralizingEstimator : 1821/1849 [00:02<00:00, 890.88it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:02<00:00, 898.82it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:02<00:00, 893.03it/s]
0%| | Fitting GeneralizingEstimator : 0/43 [00:00<?, ?it/s]
2%|2 | Fitting GeneralizingEstimator : 1/43 [00:00<00:01, 29.48it/s]
5%|4 | Fitting GeneralizingEstimator : 2/43 [00:00<00:01, 24.39it/s]
9%|9 | Fitting GeneralizingEstimator : 4/43 [00:00<00:01, 34.79it/s]
12%|#1 | Fitting GeneralizingEstimator : 5/43 [00:00<00:01, 27.34it/s]
14%|#3 | Fitting GeneralizingEstimator : 6/43 [00:00<00:01, 27.71it/s]
16%|#6 | Fitting GeneralizingEstimator : 7/43 [00:00<00:01, 24.42it/s]
21%|## | Fitting GeneralizingEstimator : 9/43 [00:00<00:01, 28.71it/s]
23%|##3 | Fitting GeneralizingEstimator : 10/43 [00:00<00:01, 25.95it/s]
28%|##7 | Fitting GeneralizingEstimator : 12/43 [00:00<00:01, 29.21it/s]
30%|### | Fitting GeneralizingEstimator : 13/43 [00:00<00:01, 26.84it/s]
35%|###4 | Fitting GeneralizingEstimator : 15/43 [00:00<00:00, 29.50it/s]
37%|###7 | Fitting GeneralizingEstimator : 16/43 [00:00<00:00, 27.42it/s]
44%|####4 | Fitting GeneralizingEstimator : 19/43 [00:00<00:00, 31.88it/s]
47%|####6 | Fitting GeneralizingEstimator : 20/43 [00:00<00:00, 29.70it/s]
53%|#####3 | Fitting GeneralizingEstimator : 23/43 [00:00<00:00, 33.30it/s]
56%|#####5 | Fitting GeneralizingEstimator : 24/43 [00:00<00:00, 31.39it/s]
63%|######2 | Fitting GeneralizingEstimator : 27/43 [00:00<00:00, 34.69it/s]
65%|######5 | Fitting GeneralizingEstimator : 28/43 [00:00<00:00, 32.63it/s]
72%|#######2 | Fitting GeneralizingEstimator : 31/43 [00:00<00:00, 35.73it/s]
74%|#######4 | Fitting GeneralizingEstimator : 32/43 [00:00<00:00, 33.68it/s]
79%|#######9 | Fitting GeneralizingEstimator : 34/43 [00:01<00:00, 35.01it/s]
81%|########1 | Fitting GeneralizingEstimator : 35/43 [00:01<00:00, 32.99it/s]
84%|########3 | Fitting GeneralizingEstimator : 36/43 [00:01<00:00, 32.57it/s]
86%|########6 | Fitting GeneralizingEstimator : 37/43 [00:01<00:00, 31.25it/s]
91%|######### | Fitting GeneralizingEstimator : 39/43 [00:01<00:00, 32.55it/s]
95%|#########5| Fitting GeneralizingEstimator : 41/43 [00:01<00:00, 32.38it/s]
98%|#########7| Fitting GeneralizingEstimator : 42/43 [00:01<00:00, 32.09it/s]
100%|##########| Fitting GeneralizingEstimator : 43/43 [00:01<00:00, 32.48it/s]
0%| | Scoring GeneralizingEstimator : 0/1849 [00:00<?, ?it/s]
2%|1 | Scoring GeneralizingEstimator : 30/1849 [00:00<00:02, 874.59it/s]
4%|3 | Scoring GeneralizingEstimator : 68/1849 [00:00<00:01, 997.39it/s]
6%|5 | Scoring GeneralizingEstimator : 104/1849 [00:00<00:01, 1020.28it/s]
8%|7 | Scoring GeneralizingEstimator : 139/1849 [00:00<00:01, 1021.49it/s]
9%|9 | Scoring GeneralizingEstimator : 171/1849 [00:00<00:01, 999.44it/s]
11%|# | Scoring GeneralizingEstimator : 200/1849 [00:00<00:01, 971.98it/s]
12%|#2 | Scoring GeneralizingEstimator : 231/1849 [00:00<00:01, 962.80it/s]
15%|#4 | Scoring GeneralizingEstimator : 269/1849 [00:00<00:01, 986.46it/s]
17%|#6 | Scoring GeneralizingEstimator : 307/1849 [00:00<00:01, 1003.43it/s]
18%|#8 | Scoring GeneralizingEstimator : 341/1849 [00:00<00:01, 1001.94it/s]
20%|## | Scoring GeneralizingEstimator : 376/1849 [00:00<00:01, 1003.16it/s]
22%|##1 | Scoring GeneralizingEstimator : 406/1849 [00:00<00:01, 989.41it/s]
24%|##3 | Scoring GeneralizingEstimator : 437/1849 [00:00<00:01, 981.80it/s]
26%|##5 | Scoring GeneralizingEstimator : 474/1849 [00:00<00:01, 992.61it/s]
28%|##7 | Scoring GeneralizingEstimator : 509/1849 [00:00<00:01, 995.76it/s]
29%|##9 | Scoring GeneralizingEstimator : 545/1849 [00:00<00:01, 1001.86it/s]
31%|### | Scoring GeneralizingEstimator : 570/1849 [00:00<00:01, 978.68it/s]
32%|###2 | Scoring GeneralizingEstimator : 595/1849 [00:00<00:01, 958.70it/s]
34%|###3 | Scoring GeneralizingEstimator : 620/1849 [00:00<00:01, 939.87it/s]
35%|###4 | Scoring GeneralizingEstimator : 647/1849 [00:00<00:01, 927.70it/s]
37%|###6 | Scoring GeneralizingEstimator : 676/1849 [00:00<00:01, 921.88it/s]
38%|###8 | Scoring GeneralizingEstimator : 707/1849 [00:00<00:01, 921.23it/s]
40%|###9 | Scoring GeneralizingEstimator : 737/1849 [00:00<00:01, 918.29it/s]
41%|####1 | Scoring GeneralizingEstimator : 763/1849 [00:00<00:01, 907.78it/s]
43%|####2 | Scoring GeneralizingEstimator : 786/1849 [00:00<00:01, 891.11it/s]
44%|####4 | Scoring GeneralizingEstimator : 819/1849 [00:00<00:01, 896.73it/s]
46%|####6 | Scoring GeneralizingEstimator : 851/1849 [00:00<00:01, 900.00it/s]
48%|####7 | Scoring GeneralizingEstimator : 879/1849 [00:00<00:01, 894.76it/s]
50%|####9 | Scoring GeneralizingEstimator : 917/1849 [00:00<00:01, 909.20it/s]
51%|#####1 | Scoring GeneralizingEstimator : 944/1849 [00:01<00:01, 902.21it/s]
53%|#####3 | Scoring GeneralizingEstimator : 981/1849 [00:01<00:00, 913.17it/s]
55%|#####5 | Scoring GeneralizingEstimator : 1018/1849 [00:01<00:00, 924.35it/s]
57%|#####6 | Scoring GeneralizingEstimator : 1049/1849 [00:01<00:00, 923.50it/s]
59%|#####8 | Scoring GeneralizingEstimator : 1083/1849 [00:01<00:00, 927.94it/s]
61%|###### | Scoring GeneralizingEstimator : 1120/1849 [00:01<00:00, 937.66it/s]
62%|######2 | Scoring GeneralizingEstimator : 1153/1849 [00:01<00:00, 938.64it/s]
64%|######4 | Scoring GeneralizingEstimator : 1189/1849 [00:01<00:00, 945.77it/s]
66%|######5 | Scoring GeneralizingEstimator : 1214/1849 [00:01<00:00, 933.68it/s]
67%|######7 | Scoring GeneralizingEstimator : 1239/1849 [00:01<00:00, 921.52it/s]
68%|######8 | Scoring GeneralizingEstimator : 1264/1849 [00:01<00:00, 911.04it/s]
70%|######9 | Scoring GeneralizingEstimator : 1289/1849 [00:01<00:00, 900.93it/s]
71%|#######1 | Scoring GeneralizingEstimator : 1322/1849 [00:01<00:00, 904.85it/s]
73%|#######3 | Scoring GeneralizingEstimator : 1354/1849 [00:01<00:00, 906.90it/s]
75%|#######5 | Scoring GeneralizingEstimator : 1392/1849 [00:01<00:00, 918.86it/s]
77%|#######7 | Scoring GeneralizingEstimator : 1425/1849 [00:01<00:00, 920.93it/s]
79%|#######8 | Scoring GeneralizingEstimator : 1460/1849 [00:01<00:00, 927.04it/s]
81%|######## | Scoring GeneralizingEstimator : 1495/1849 [00:01<00:00, 932.87it/s]
83%|########2 | Scoring GeneralizingEstimator : 1530/1849 [00:01<00:00, 938.24it/s]
84%|########4 | Scoring GeneralizingEstimator : 1555/1849 [00:01<00:00, 927.54it/s]
86%|########5 | Scoring GeneralizingEstimator : 1584/1849 [00:01<00:00, 923.73it/s]
87%|########7 | Scoring GeneralizingEstimator : 1616/1849 [00:01<00:00, 924.91it/s]
89%|########9 | Scoring GeneralizingEstimator : 1653/1849 [00:01<00:00, 933.79it/s]
91%|#########1| Scoring GeneralizingEstimator : 1688/1849 [00:01<00:00, 939.14it/s]
93%|#########3| Scoring GeneralizingEstimator : 1722/1849 [00:01<00:00, 942.52it/s]
95%|#########5| Scoring GeneralizingEstimator : 1759/1849 [00:01<00:00, 950.37it/s]
97%|#########7| Scoring GeneralizingEstimator : 1796/1849 [00:01<00:00, 957.83it/s]
99%|#########8| Scoring GeneralizingEstimator : 1829/1849 [00:01<00:00, 958.64it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:01<00:00, 963.13it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:01<00:00, 943.86it/s]
0%| | Fitting GeneralizingEstimator : 0/43 [00:00<?, ?it/s]
2%|2 | Fitting GeneralizingEstimator : 1/43 [00:00<00:01, 28.94it/s]
9%|9 | Fitting GeneralizingEstimator : 4/43 [00:00<00:01, 33.73it/s]
14%|#3 | Fitting GeneralizingEstimator : 6/43 [00:00<00:00, 39.28it/s]
16%|#6 | Fitting GeneralizingEstimator : 7/43 [00:00<00:01, 31.70it/s]
21%|## | Fitting GeneralizingEstimator : 9/43 [00:00<00:00, 35.71it/s]
23%|##3 | Fitting GeneralizingEstimator : 10/43 [00:00<00:01, 30.94it/s]
28%|##7 | Fitting GeneralizingEstimator : 12/43 [00:00<00:00, 33.98it/s]
30%|### | Fitting GeneralizingEstimator : 13/43 [00:00<00:00, 30.55it/s]
35%|###4 | Fitting GeneralizingEstimator : 15/43 [00:00<00:00, 33.06it/s]
37%|###7 | Fitting GeneralizingEstimator : 16/43 [00:00<00:00, 30.30it/s]
44%|####4 | Fitting GeneralizingEstimator : 19/43 [00:00<00:00, 34.64it/s]
47%|####6 | Fitting GeneralizingEstimator : 20/43 [00:00<00:00, 32.15it/s]
53%|#####3 | Fitting GeneralizingEstimator : 23/43 [00:00<00:00, 36.09it/s]
58%|#####8 | Fitting GeneralizingEstimator : 25/43 [00:00<00:00, 35.36it/s]
63%|######2 | Fitting GeneralizingEstimator : 27/43 [00:00<00:00, 36.83it/s]
70%|######9 | Fitting GeneralizingEstimator : 30/43 [00:00<00:00, 35.75it/s]
72%|#######2 | Fitting GeneralizingEstimator : 31/43 [00:00<00:00, 33.61it/s]
77%|#######6 | Fitting GeneralizingEstimator : 33/43 [00:00<00:00, 34.21it/s]
81%|########1 | Fitting GeneralizingEstimator : 35/43 [00:01<00:00, 33.73it/s]
86%|########6 | Fitting GeneralizingEstimator : 37/43 [00:01<00:00, 32.61it/s]
91%|######### | Fitting GeneralizingEstimator : 39/43 [00:01<00:00, 33.49it/s]
93%|#########3| Fitting GeneralizingEstimator : 40/43 [00:01<00:00, 32.22it/s]
100%|##########| Fitting GeneralizingEstimator : 43/43 [00:01<00:00, 34.75it/s]
100%|##########| Fitting GeneralizingEstimator : 43/43 [00:01<00:00, 34.33it/s]
0%| | Scoring GeneralizingEstimator : 0/1849 [00:00<?, ?it/s]
1%| | Scoring GeneralizingEstimator : 16/1849 [00:00<00:07, 247.30it/s]
3%|2 | Scoring GeneralizingEstimator : 49/1849 [00:00<00:03, 504.61it/s]
5%|4 | Scoring GeneralizingEstimator : 86/1849 [00:00<00:02, 662.90it/s]
7%|6 | Scoring GeneralizingEstimator : 123/1849 [00:00<00:02, 756.80it/s]
9%|8 | Scoring GeneralizingEstimator : 158/1849 [00:00<00:02, 807.88it/s]
11%|# | Scoring GeneralizingEstimator : 196/1849 [00:00<00:01, 859.87it/s]
12%|#2 | Scoring GeneralizingEstimator : 231/1849 [00:00<00:01, 885.06it/s]
14%|#4 | Scoring GeneralizingEstimator : 268/1849 [00:00<00:01, 911.60it/s]
17%|#6 | Scoring GeneralizingEstimator : 306/1849 [00:00<00:01, 937.14it/s]
18%|#8 | Scoring GeneralizingEstimator : 342/1849 [00:00<00:01, 951.18it/s]
20%|## | Scoring GeneralizingEstimator : 378/1849 [00:00<00:01, 962.56it/s]
22%|##2 | Scoring GeneralizingEstimator : 416/1849 [00:00<00:01, 978.64it/s]
24%|##4 | Scoring GeneralizingEstimator : 453/1849 [00:00<00:01, 989.64it/s]
26%|##6 | Scoring GeneralizingEstimator : 488/1849 [00:00<00:01, 993.65it/s]
28%|##8 | Scoring GeneralizingEstimator : 525/1849 [00:00<00:01, 1002.07it/s]
30%|### | Scoring GeneralizingEstimator : 560/1849 [00:00<00:01, 1004.22it/s]
32%|###1 | Scoring GeneralizingEstimator : 584/1849 [00:00<00:01, 979.16it/s]
33%|###2 | Scoring GeneralizingEstimator : 605/1849 [00:00<00:01, 949.72it/s]
35%|###4 | Scoring GeneralizingEstimator : 640/1849 [00:00<00:01, 956.40it/s]
36%|###6 | Scoring GeneralizingEstimator : 673/1849 [00:00<00:01, 956.74it/s]
38%|###8 | Scoring GeneralizingEstimator : 711/1849 [00:00<00:01, 968.61it/s]
40%|#### | Scoring GeneralizingEstimator : 748/1849 [00:00<00:01, 976.91it/s]
42%|####2 | Scoring GeneralizingEstimator : 785/1849 [00:00<00:01, 984.92it/s]
44%|####4 | Scoring GeneralizingEstimator : 822/1849 [00:00<00:01, 992.51it/s]
46%|####6 | Scoring GeneralizingEstimator : 856/1849 [00:00<00:01, 991.28it/s]
48%|####7 | Scoring GeneralizingEstimator : 887/1849 [00:00<00:00, 985.91it/s]
50%|####9 | Scoring GeneralizingEstimator : 924/1849 [00:00<00:00, 992.97it/s]
52%|#####1 | Scoring GeneralizingEstimator : 956/1849 [00:00<00:00, 989.95it/s]
53%|#####3 | Scoring GeneralizingEstimator : 982/1849 [00:01<00:00, 975.55it/s]
55%|#####4 | Scoring GeneralizingEstimator : 1008/1849 [00:01<00:00, 962.47it/s]
56%|#####6 | Scoring GeneralizingEstimator : 1040/1849 [00:01<00:00, 960.40it/s]
58%|#####8 | Scoring GeneralizingEstimator : 1075/1849 [00:01<00:00, 964.76it/s]
60%|###### | Scoring GeneralizingEstimator : 1114/1849 [00:01<00:00, 975.59it/s]
62%|######1 | Scoring GeneralizingEstimator : 1144/1849 [00:01<00:00, 969.34it/s]
64%|######3 | Scoring GeneralizingEstimator : 1181/1849 [00:01<00:00, 976.31it/s]
66%|######5 | Scoring GeneralizingEstimator : 1219/1849 [00:01<00:00, 984.41it/s]
68%|######7 | Scoring GeneralizingEstimator : 1253/1849 [00:01<00:00, 985.40it/s]
70%|######9 | Scoring GeneralizingEstimator : 1288/1849 [00:01<00:00, 987.31it/s]
71%|#######1 | Scoring GeneralizingEstimator : 1320/1849 [00:01<00:00, 984.23it/s]
73%|#######2 | Scoring GeneralizingEstimator : 1348/1849 [00:01<00:00, 975.38it/s]
75%|#######4 | Scoring GeneralizingEstimator : 1385/1849 [00:01<00:00, 981.35it/s]
77%|#######6 | Scoring GeneralizingEstimator : 1417/1849 [00:01<00:00, 978.49it/s]
79%|#######8 | Scoring GeneralizingEstimator : 1452/1849 [00:01<00:00, 981.53it/s]
80%|######## | Scoring GeneralizingEstimator : 1486/1849 [00:01<00:00, 982.39it/s]
82%|########2 | Scoring GeneralizingEstimator : 1520/1849 [00:01<00:00, 983.68it/s]
84%|########3 | Scoring GeneralizingEstimator : 1550/1849 [00:01<00:00, 977.61it/s]
86%|########5 | Scoring GeneralizingEstimator : 1584/1849 [00:01<00:00, 979.09it/s]
88%|########7 | Scoring GeneralizingEstimator : 1618/1849 [00:01<00:00, 980.29it/s]
89%|########9 | Scoring GeneralizingEstimator : 1654/1849 [00:01<00:00, 983.52it/s]
91%|#########1| Scoring GeneralizingEstimator : 1687/1849 [00:01<00:00, 983.05it/s]
93%|#########3| Scoring GeneralizingEstimator : 1721/1849 [00:01<00:00, 984.03it/s]
95%|#########4| Scoring GeneralizingEstimator : 1751/1849 [00:01<00:00, 978.29it/s]
96%|#########6| Scoring GeneralizingEstimator : 1780/1849 [00:01<00:00, 971.68it/s]
98%|#########8| Scoring GeneralizingEstimator : 1813/1849 [00:01<00:00, 971.35it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:01<00:00, 977.69it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:01<00:00, 970.92it/s]
0%| | Fitting GeneralizingEstimator : 0/43 [00:00<?, ?it/s]
5%|4 | Fitting GeneralizingEstimator : 2/43 [00:00<00:00, 58.13it/s]
9%|9 | Fitting GeneralizingEstimator : 4/43 [00:00<00:00, 58.57it/s]
14%|#3 | Fitting GeneralizingEstimator : 6/43 [00:00<00:00, 37.89it/s]
19%|#8 | Fitting GeneralizingEstimator : 8/43 [00:00<00:00, 41.76it/s]
21%|## | Fitting GeneralizingEstimator : 9/43 [00:00<00:00, 34.38it/s]
26%|##5 | Fitting GeneralizingEstimator : 11/43 [00:00<00:00, 37.52it/s]
28%|##7 | Fitting GeneralizingEstimator : 12/43 [00:00<00:00, 32.84it/s]
33%|###2 | Fitting GeneralizingEstimator : 14/43 [00:00<00:00, 35.44it/s]
37%|###7 | Fitting GeneralizingEstimator : 16/43 [00:00<00:00, 31.34it/s]
40%|###9 | Fitting GeneralizingEstimator : 17/43 [00:00<00:00, 29.38it/s]
47%|####6 | Fitting GeneralizingEstimator : 20/43 [00:00<00:00, 33.66it/s]
49%|####8 | Fitting GeneralizingEstimator : 21/43 [00:00<00:00, 31.27it/s]
56%|#####5 | Fitting GeneralizingEstimator : 24/43 [00:00<00:00, 34.98it/s]
58%|#####8 | Fitting GeneralizingEstimator : 25/43 [00:00<00:00, 32.66it/s]
65%|######5 | Fitting GeneralizingEstimator : 28/43 [00:00<00:00, 36.01it/s]
67%|######7 | Fitting GeneralizingEstimator : 29/43 [00:00<00:00, 33.72it/s]
72%|#######2 | Fitting GeneralizingEstimator : 31/43 [00:00<00:00, 34.84it/s]
74%|#######4 | Fitting GeneralizingEstimator : 32/43 [00:00<00:00, 33.08it/s]
79%|#######9 | Fitting GeneralizingEstimator : 34/43 [00:00<00:00, 34.22it/s]
81%|########1 | Fitting GeneralizingEstimator : 35/43 [00:01<00:00, 32.58it/s]
86%|########6 | Fitting GeneralizingEstimator : 37/43 [00:01<00:00, 33.82it/s]
88%|########8 | Fitting GeneralizingEstimator : 38/43 [00:01<00:00, 32.15it/s]
95%|#########5| Fitting GeneralizingEstimator : 41/43 [00:01<00:00, 34.85it/s]
98%|#########7| Fitting GeneralizingEstimator : 42/43 [00:01<00:00, 33.06it/s]
100%|##########| Fitting GeneralizingEstimator : 43/43 [00:01<00:00, 33.83it/s]
0%| | Scoring GeneralizingEstimator : 0/1849 [00:00<?, ?it/s]
1%|1 | Scoring GeneralizingEstimator : 20/1849 [00:00<00:05, 311.85it/s]
3%|2 | Scoring GeneralizingEstimator : 50/1849 [00:00<00:03, 515.95it/s]
5%|4 | Scoring GeneralizingEstimator : 88/1849 [00:00<00:02, 676.41it/s]
7%|6 | Scoring GeneralizingEstimator : 124/1849 [00:00<00:02, 762.48it/s]
9%|8 | Scoring GeneralizingEstimator : 158/1849 [00:00<00:02, 808.15it/s]
11%|# | Scoring GeneralizingEstimator : 195/1849 [00:00<00:01, 854.20it/s]
12%|#2 | Scoring GeneralizingEstimator : 231/1849 [00:00<00:01, 883.68it/s]
14%|#4 | Scoring GeneralizingEstimator : 262/1849 [00:00<00:01, 888.15it/s]
16%|#6 | Scoring GeneralizingEstimator : 299/1849 [00:00<00:01, 913.54it/s]
18%|#8 | Scoring GeneralizingEstimator : 334/1849 [00:00<00:01, 926.53it/s]
19%|#9 | Scoring GeneralizingEstimator : 358/1849 [00:00<00:01, 902.58it/s]
21%|##1 | Scoring GeneralizingEstimator : 389/1849 [00:00<00:01, 904.11it/s]
22%|##2 | Scoring GeneralizingEstimator : 412/1849 [00:00<00:01, 881.05it/s]
24%|##4 | Scoring GeneralizingEstimator : 448/1849 [00:00<00:01, 897.79it/s]
26%|##5 | Scoring GeneralizingEstimator : 478/1849 [00:00<00:01, 896.75it/s]
28%|##7 | Scoring GeneralizingEstimator : 513/1849 [00:00<00:01, 908.36it/s]
29%|##9 | Scoring GeneralizingEstimator : 544/1849 [00:00<00:01, 909.03it/s]
31%|### | Scoring GeneralizingEstimator : 573/1849 [00:00<00:01, 904.61it/s]
33%|###2 | Scoring GeneralizingEstimator : 602/1849 [00:00<00:01, 899.95it/s]
34%|###4 | Scoring GeneralizingEstimator : 632/1849 [00:00<00:01, 898.26it/s]
36%|###6 | Scoring GeneralizingEstimator : 667/1849 [00:00<00:01, 908.13it/s]
38%|###7 | Scoring GeneralizingEstimator : 699/1849 [00:00<00:01, 910.81it/s]
39%|###8 | Scoring GeneralizingEstimator : 721/1849 [00:00<00:01, 892.14it/s]
40%|#### | Scoring GeneralizingEstimator : 747/1849 [00:00<00:01, 883.55it/s]
42%|####1 | Scoring GeneralizingEstimator : 768/1849 [00:00<00:01, 865.86it/s]
43%|####2 | Scoring GeneralizingEstimator : 795/1849 [00:00<00:01, 860.62it/s]
44%|####4 | Scoring GeneralizingEstimator : 817/1849 [00:00<00:01, 846.93it/s]
46%|####5 | Scoring GeneralizingEstimator : 843/1849 [00:00<00:01, 841.35it/s]
48%|####7 | Scoring GeneralizingEstimator : 880/1849 [00:01<00:01, 856.36it/s]
49%|####9 | Scoring GeneralizingEstimator : 914/1849 [00:01<00:01, 864.81it/s]
51%|#####1 | Scoring GeneralizingEstimator : 947/1849 [00:01<00:01, 871.68it/s]
53%|#####2 | Scoring GeneralizingEstimator : 977/1849 [00:01<00:00, 872.34it/s]
54%|#####4 | Scoring GeneralizingEstimator : 1004/1849 [00:01<00:00, 867.53it/s]
56%|#####5 | Scoring GeneralizingEstimator : 1030/1849 [00:01<00:00, 861.68it/s]
57%|#####7 | Scoring GeneralizingEstimator : 1057/1849 [00:01<00:00, 857.72it/s]
59%|#####9 | Scoring GeneralizingEstimator : 1091/1849 [00:01<00:00, 866.32it/s]
61%|###### | Scoring GeneralizingEstimator : 1119/1849 [00:01<00:00, 864.00it/s]
62%|######2 | Scoring GeneralizingEstimator : 1151/1849 [00:01<00:00, 868.10it/s]
64%|######3 | Scoring GeneralizingEstimator : 1182/1849 [00:01<00:00, 870.89it/s]
65%|######5 | Scoring GeneralizingEstimator : 1211/1849 [00:01<00:00, 868.96it/s]
67%|######7 | Scoring GeneralizingEstimator : 1240/1849 [00:01<00:00, 867.24it/s]
69%|######8 | Scoring GeneralizingEstimator : 1267/1849 [00:01<00:00, 862.80it/s]
70%|####### | Scoring GeneralizingEstimator : 1296/1849 [00:01<00:00, 862.28it/s]
72%|#######1 | Scoring GeneralizingEstimator : 1329/1849 [00:01<00:00, 867.89it/s]
74%|#######3 | Scoring GeneralizingEstimator : 1363/1849 [00:01<00:00, 875.24it/s]
75%|#######5 | Scoring GeneralizingEstimator : 1391/1849 [00:01<00:00, 872.60it/s]
77%|#######7 | Scoring GeneralizingEstimator : 1425/1849 [00:01<00:00, 879.39it/s]
79%|#######8 | Scoring GeneralizingEstimator : 1458/1849 [00:01<00:00, 884.54it/s]
80%|#######9 | Scoring GeneralizingEstimator : 1476/1849 [00:01<00:00, 865.42it/s]
81%|######## | Scoring GeneralizingEstimator : 1494/1849 [00:01<00:00, 847.24it/s]
83%|########2 | Scoring GeneralizingEstimator : 1528/1849 [00:01<00:00, 853.21it/s]
84%|########3 | Scoring GeneralizingEstimator : 1552/1849 [00:01<00:00, 845.32it/s]
86%|########5 | Scoring GeneralizingEstimator : 1587/1849 [00:01<00:00, 854.34it/s]
88%|########7 | Scoring GeneralizingEstimator : 1622/1849 [00:01<00:00, 863.42it/s]
89%|########9 | Scoring GeneralizingEstimator : 1649/1849 [00:01<00:00, 859.77it/s]
91%|######### | Scoring GeneralizingEstimator : 1676/1849 [00:01<00:00, 856.46it/s]
92%|#########2| Scoring GeneralizingEstimator : 1709/1849 [00:01<00:00, 862.31it/s]
94%|#########3| Scoring GeneralizingEstimator : 1738/1849 [00:02<00:00, 861.96it/s]
96%|#########5| Scoring GeneralizingEstimator : 1770/1849 [00:02<00:00, 865.97it/s]
98%|#########7| Scoring GeneralizingEstimator : 1803/1849 [00:02<00:00, 871.08it/s]
98%|#########8| Scoring GeneralizingEstimator : 1821/1849 [00:02<00:00, 853.29it/s]
99%|#########9| Scoring GeneralizingEstimator : 1839/1849 [00:02<00:00, 836.71it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:02<00:00, 828.65it/s]
100%|##########| Scoring GeneralizingEstimator : 1849/1849 [00:02<00:00, 855.41it/s]
Plot the full (generalization) matrix:
fig, ax = plt.subplots(1, 1)
im = ax.imshow(scores, interpolation='lanczos', origin='lower', cmap='RdBu_r',
extent=epochs.times[[0, -1, 0, -1]], vmin=0., vmax=1.)
ax.set_xlabel('Testing Time (s)')
ax.set_ylabel('Training Time (s)')
ax.set_title('Temporal generalization')
ax.axvline(0, color='k')
ax.axhline(0, color='k')
plt.colorbar(im, ax=ax)
Projecting sensor-space patterns to source space¶
If you use a linear classifier (or regressor) for your data, you can also
project these to source space. For example, using our evoked_time_gen
from before:
cov = mne.compute_covariance(epochs, tmax=0.)
del epochs
fwd = mne.read_forward_solution(
data_path + '/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif')
inv = mne.minimum_norm.make_inverse_operator(
evoked_time_gen.info, fwd, cov, loose=0.)
stc = mne.minimum_norm.apply_inverse(evoked_time_gen, inv, 1. / 9., 'dSPM')
del fwd, inv
Out:
Computing rank from data with rank=None
Using tolerance 3.4e-10 (2.2e-16 eps * 203 dim * 7.6e+03 max singular value)
Estimated rank (grad): 203
GRAD: rank 203 computed from 203 data channels with 0 projectors
Reducing data rank from 203 -> 203
Estimating covariance using EMPIRICAL
Done.
Number of samples used : 1599
[done]
Reading forward solution from /home/circleci/mne_data/MNE-sample-data/MEG/sample/sample_audvis-meg-eeg-oct-6-fwd.fif...
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
Desired named matrix (kind = 3523) not available
Read MEG forward solution (7498 sources, 306 channels, free orientations)
Desired named matrix (kind = 3523) not available
Read EEG forward solution (7498 sources, 60 channels, free orientations)
MEG and EEG forward solutions combined
Source spaces transformed to the forward solution coordinate frame
Computing inverse operator with 203 channels.
203 out of 366 channels remain after picking
Selected 203 channels
Creating the depth weighting matrix...
203 planar channels
limit = 7262/7498 = 10.020866
scale = 2.58122e-08 exp = 0.8
Picked elements from a free-orientation depth-weighting prior into the fixed-orientation one
Average patch normals will be employed in the rotation to the local surface coordinates....
Converting to surface-based source orientations...
[done]
Whitening the forward solution.
Computing rank from covariance with rank=None
Using tolerance 1.6e-13 (2.2e-16 eps * 203 dim * 3.6 max singular value)
Estimated rank (grad): 203
GRAD: rank 203 computed from 203 data channels with 0 projectors
Setting small GRAD eigenvalues to zero (without PCA)
Creating the source covariance matrix
Adjusting source covariance matrix.
Computing SVD of whitened and weighted lead field matrix.
largest singular value = 3.91789
scaling factor to adjust the trace = 6.28301e+18 (nchan = 203 nzero = 0)
Preparing the inverse operator for use...
Scaled noise and source covariance from nave = 1 to nave = 1
Created the regularized inverter
The projection vectors do not apply to these channels.
Created the whitener using a noise covariance matrix with rank 203 (0 small eigenvalues omitted)
Computing noise-normalization factors (dSPM)...
[done]
Applying inverse operator to ""...
Picked 203 channels from the data
Computing inverse...
Eigenleads need to be weighted ...
Computing residual...
Explained 76.6% variance
dSPM...
[done]
And this can be visualized using stc.plot
:
brain = stc.plot(hemi='split', views=('lat', 'med'), initial_time=0.1,
subjects_dir=subjects_dir)
Out:
Using control points [2.03727704 2.4722366 8.19426193]
Source-space decoding¶
Source space decoding is also possible, but because the number of features can be much larger than in the sensor space, univariate feature selection using ANOVA f-test (or some other metric) can be done to reduce the feature dimension. Interpreting decoding results might be easier in source space as compared to sensor space.
Examples
Exercise¶
Explore other datasets from MNE (e.g. Face dataset from SPM to predict Face vs. Scrambled)
References¶
- 1
Jean-Rémi King, Laura Gwilliams, Chris Holdgraf, Jona Sassenhagen, Alexandre Barachant, Denis Engemann, Eric Larson, and Alexandre Gramfort. Encoding and decoding neuronal dynamics: methodological framework to uncover the algorithms of cognition. hal-01848442, 2018. URL: https://hal.archives-ouvertes.fr/hal-01848442.
- 2
Zoltan J. Koles. The quantitative extraction and topographic mapping of the abnormal components in the clinical EEG. Electroencephalography and Clinical Neurophysiology, 79(6):440–447, 1991. doi:10.1016/0013-4694(91)90163-X.
- 3
Sven Dähne, Frank C. Meinecke, Stefan Haufe, Johannes Höhne, Michael Tangermann, Klaus-Robert Müller, and Vadim V. Nikulin. SPoC: a novel framework for relating the amplitude of neuronal oscillations to behaviorally relevant parameters. NeuroImage, 86:111–122, 2014. doi:10.1016/j.neuroimage.2013.07.079.
- 4
Bertrand Rivet, Antoine Souloumiac, Virginie Attina, and Guillaume Gibert. xDAWN algorithm to enhance evoked potentials: application to brain–computer interface. IEEE Transactions on Biomedical Engineering, 56(8):2035–2043, 2009. doi:10.1109/TBME.2009.2012869.
- 5
Aaron Schurger, Sebastien Marti, and Stanislas Dehaene. Reducing multi-sensor data to a single time course that reveals experimental effects. BMC Neuroscience, 2013. doi:10.1186/1471-2202-14-122.
- 6
Jean-Rémi King, Alexandre Gramfort, Aaron Schurger, Lionel Naccache, and Stanislas Dehaene. Two distinct dynamic modes subtend the detection of unexpected sounds. PLoS ONE, 9(1):e85791, 2014. doi:10.1371/journal.pone.0085791.
- 7
Jean-Rémi King and Stanislas Dehaene. Characterizing the dynamics of mental representations: the temporal generalization method. Trends in Cognitive Sciences, 18(4):203–210, 2014. doi:10.1016/j.tics.2014.01.002.
Total running time of the script: ( 0 minutes 56.772 seconds)
Estimated memory usage: 487 MB