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:

sphinx_gallery_thumbnail_number = 6

import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LogisticRegression
from sklearn.pipeline import make_pipeline
from sklearn.preprocessing import StandardScaler

import mne
from mne.datasets import sample
from mne.decoding import (
    CSP,
    GeneralizingEstimator,
    LinearModel,
    Scaler,
    SlidingEstimator,
    Vectorizer,
    cross_val_multiscore,
    get_coef,
)

data_path = sample.data_path()

subjects_dir = data_path / "subjects"
meg_path = data_path / "MEG" / "sample"
raw_fname = meg_path / "sample_audvis_filt-0-40_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)
raw.pick(picks=["grad", "stim", "eog"])

# 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 example to run faster. The 2 Hz high-pass helps improve CSP.
raw.load_data().filter(2, 20)
events = mne.find_events(raw, "STI 014")

# Set up bad channels (modify to your needs)
raw.info["bads"] += ["MEG 2443"]  # bads + 2 more

# Read epochs
epochs = mne.Epochs(
    raw,
    events,
    event_id,
    tmin,
    tmax,
    proj=True,
    picks=("grad", "eog"),
    baseline=(None, 0.0),
    preload=True,
    reject=dict(grad=4000e-13, eog=150e-6),
    decim=3,
    verbose="error",
)
epochs.pick(picks="meg", exclude="bads")  # remove stim and EOG
del raw

X = epochs.get_data(copy=False)  # MEG signals: n_epochs, n_meg_channels, n_times
y = epochs.events[:, 2]  # target: auditory left vs visual left
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 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: 249 samples (1.658 s)

[Parallel(n_jobs=1)]: Done  17 tasks      | elapsed:    0.1s
[Parallel(n_jobs=1)]: Done  71 tasks      | elapsed:    0.2s
[Parallel(n_jobs=1)]: Done 161 tasks      | elapsed:    0.3s
319 events found on stim channel STI 014
Event IDs: [ 1  2  3  4  5 32]

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="liblinear"),  # liblinear is faster than lbfgs
)

scores = cross_val_multiscore(clf, X, y, cv=5, n_jobs=None)

# Mean scores across cross-validation splits
score = np.mean(scores, axis=0)
print(f"Spatio-temporal: {100 * score:0.1f}%")
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:

(1)#\[x_{CSP}(t) = W^{T}x(t)\]

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

(2)#\[W^{T}\Sigma^{+}W = \lambda^{+}\]
(3)#\[W^{T}\Sigma^{-}W = \lambda^{-}\]

where \(\lambda^{C}\) is a diagonal matrix whose entries are the eigenvalues of the following generalized eigenvalue problem

(4)#\[\Sigma^{+}w = \lambda \Sigma^{-}w\]

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.

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="liblinear")))
scores = cross_val_multiscore(clf_csp, X, y, cv=5, n_jobs=None)
print(f"CSP: {100 * scores.mean():0.1f}%")
Computing rank from data with rank=None
    Using tolerance 4e-11 (2.2e-16 eps * 203 dim * 8.9e+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 4.7e-11 (2.2e-16 eps * 203 dim * 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 3.8e-11 (2.2e-16 eps * 203 dim * 8.5e+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 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 3.9e-11 (2.2e-16 eps * 203 dim * 8.6e+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 4.7e-11 (2.2e-16 eps * 203 dim * 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 3.9e-11 (2.2e-16 eps * 203 dim * 8.6e+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 4.5e-11 (2.2e-16 eps * 203 dim * 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 3.8e-11 (2.2e-16 eps * 203 dim * 8.5e+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 4.7e-11 (2.2e-16 eps * 203 dim * 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: 89.4%

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.

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:

(5)#\[x(t) = (W^{-1})^{T}x_{CSP}(t)\]

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)
  • CSP0, CSP1, CSP2, AU
  • CSP0, CSP1, CSP2, AU
Computing rank from data with rank=None
    Using tolerance 4.3e-11 (2.2e-16 eps * 203 dim * 9.6e+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.

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 × n_channels × 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="liblinear"))

time_decod = SlidingEstimator(clf, n_jobs=None, scoring="roc_auc", verbose=True)
# here we use cv=3 just for speed
scores = cross_val_multiscore(time_decod, X, y, cv=3, n_jobs=None)

# 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(0.5, color="k", linestyle="--", label="chance")
ax.set_xlabel("Times")
ax.set_ylabel("AUC")  # Area Under the Curve
ax.legend()
ax.axvline(0.0, color="k", linestyle="-")
ax.set_title("Sensor space decoding")
Sensor space decoding
  0%|          | Fitting SlidingEstimator : 0/36 [00:00<?,       ?it/s]
 11%|█         | Fitting SlidingEstimator : 4/36 [00:00<00:00,  112.32it/s]
 25%|██▌       | Fitting SlidingEstimator : 9/36 [00:00<00:00,  129.85it/s]
 36%|███▌      | Fitting SlidingEstimator : 13/36 [00:00<00:00,  125.87it/s]
 53%|█████▎    | Fitting SlidingEstimator : 19/36 [00:00<00:00,  138.72it/s]
 67%|██████▋   | Fitting SlidingEstimator : 24/36 [00:00<00:00,  140.67it/s]
 83%|████████▎ | Fitting SlidingEstimator : 30/36 [00:00<00:00,  139.86it/s]
 97%|█████████▋| Fitting SlidingEstimator : 35/36 [00:00<00:00,  140.87it/s]
100%|██████████| Fitting SlidingEstimator : 36/36 [00:00<00:00,  141.74it/s]

  0%|          | Fitting SlidingEstimator : 0/36 [00:00<?,       ?it/s]
 11%|█         | Fitting SlidingEstimator : 4/36 [00:00<00:00,  118.18it/s]
 28%|██▊       | Fitting SlidingEstimator : 10/36 [00:00<00:00,  147.52it/s]
 42%|████▏     | Fitting SlidingEstimator : 15/36 [00:00<00:00,  147.55it/s]
 56%|█████▌    | Fitting SlidingEstimator : 20/36 [00:00<00:00,  147.67it/s]
 72%|███████▏  | Fitting SlidingEstimator : 26/36 [00:00<00:00,  153.37it/s]
 83%|████████▎ | Fitting SlidingEstimator : 30/36 [00:00<00:00,  146.77it/s]
 94%|█████████▍| Fitting SlidingEstimator : 34/36 [00:00<00:00,  142.10it/s]
100%|██████████| Fitting SlidingEstimator : 36/36 [00:00<00:00,  142.09it/s]

  0%|          | Fitting SlidingEstimator : 0/36 [00:00<?,       ?it/s]
 11%|█         | Fitting SlidingEstimator : 4/36 [00:00<00:00,  117.92it/s]
 22%|██▏       | Fitting SlidingEstimator : 8/36 [00:00<00:00,  118.08it/s]
 36%|███▌      | Fitting SlidingEstimator : 13/36 [00:00<00:00,  128.38it/s]
 56%|█████▌    | Fitting SlidingEstimator : 20/36 [00:00<00:00,  149.48it/s]
 67%|██████▋   | Fitting SlidingEstimator : 24/36 [00:00<00:00,  142.60it/s]
 83%|████████▎ | Fitting SlidingEstimator : 30/36 [00:00<00:00,  149.10it/s]
 97%|█████████▋| Fitting SlidingEstimator : 35/36 [00:00<00:00,  148.76it/s]
100%|██████████| Fitting SlidingEstimator : 36/36 [00:00<00:00,  148.80it/s]

You can retrieve the spatial filters and spatial patterns if you explicitly use a LinearModel

clf = make_pipeline(
    StandardScaler(), LinearModel(LogisticRegression(solver="liblinear"))
)
time_decod = SlidingEstimator(clf, n_jobs=None, 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.0, 0.500, 0.100), title="patterns", **joint_kwargs
)
patterns, 0.000 s, 0.100 s, 0.200 s, 0.300 s, 0.400 s
  0%|          | Fitting SlidingEstimator : 0/36 [00:00<?,       ?it/s]
  6%|▌         | Fitting SlidingEstimator : 2/36 [00:00<00:00,   57.97it/s]
 11%|█         | Fitting SlidingEstimator : 4/36 [00:00<00:00,   58.43it/s]
 19%|█▉        | Fitting SlidingEstimator : 7/36 [00:00<00:00,   68.74it/s]
 28%|██▊       | Fitting SlidingEstimator : 10/36 [00:00<00:00,   73.96it/s]
 36%|███▌      | Fitting SlidingEstimator : 13/36 [00:00<00:00,   77.05it/s]
 47%|████▋     | Fitting SlidingEstimator : 17/36 [00:00<00:00,   84.46it/s]
 58%|█████▊    | Fitting SlidingEstimator : 21/36 [00:00<00:00,   89.99it/s]
 67%|██████▋   | Fitting SlidingEstimator : 24/36 [00:00<00:00,   89.76it/s]
 75%|███████▌  | Fitting SlidingEstimator : 27/36 [00:00<00:00,   89.14it/s]
 83%|████████▎ | Fitting SlidingEstimator : 30/36 [00:00<00:00,   88.95it/s]
 89%|████████▉ | Fitting SlidingEstimator : 32/36 [00:00<00:00,   85.51it/s]
 97%|█████████▋| Fitting SlidingEstimator : 35/36 [00:00<00:00,   85.83it/s]
100%|██████████| Fitting SlidingEstimator : 36/36 [00:00<00:00,   87.15it/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=None, scoring="roc_auc", verbose=True)

# again, cv=3 just for speed
scores = cross_val_multiscore(time_gen, X, y, cv=3, n_jobs=None)

# 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(0.5, color="k", linestyle="--", label="chance")
ax.set_xlabel("Times")
ax.set_ylabel("AUC")
ax.legend()
ax.axvline(0.0, color="k", linestyle="-")
ax.set_title("Decoding MEG sensors over time")
Decoding MEG sensors over time
  0%|          | Fitting GeneralizingEstimator : 0/36 [00:00<?,       ?it/s]
  6%|▌         | Fitting GeneralizingEstimator : 2/36 [00:00<00:00,   58.17it/s]
 17%|█▋        | Fitting GeneralizingEstimator : 6/36 [00:00<00:00,   88.42it/s]
 31%|███       | Fitting GeneralizingEstimator : 11/36 [00:00<00:00,  109.01it/s]
 47%|████▋     | Fitting GeneralizingEstimator : 17/36 [00:00<00:00,  127.27it/s]
 67%|██████▋   | Fitting GeneralizingEstimator : 24/36 [00:00<00:00,  144.74it/s]
 83%|████████▎ | Fitting GeneralizingEstimator : 30/36 [00:00<00:00,  150.85it/s]
 97%|█████████▋| Fitting GeneralizingEstimator : 35/36 [00:00<00:00,  150.28it/s]
100%|██████████| Fitting GeneralizingEstimator : 36/36 [00:00<00:00,  146.55it/s]

  0%|          | Scoring GeneralizingEstimator : 0/1296 [00:00<?,       ?it/s]
  1%|          | Scoring GeneralizingEstimator : 11/1296 [00:00<00:04,  315.99it/s]
  2%|▏         | Scoring GeneralizingEstimator : 29/1296 [00:00<00:03,  417.50it/s]
  3%|▎         | Scoring GeneralizingEstimator : 45/1296 [00:00<00:02,  431.91it/s]
  5%|▍         | Scoring GeneralizingEstimator : 64/1296 [00:00<00:02,  464.03it/s]
  6%|▋         | Scoring GeneralizingEstimator : 82/1296 [00:00<00:02,  477.09it/s]
  8%|▊         | Scoring GeneralizingEstimator : 101/1296 [00:00<00:02,  492.87it/s]
  9%|▉         | Scoring GeneralizingEstimator : 121/1296 [00:00<00:02,  507.27it/s]
 11%|█         | Scoring GeneralizingEstimator : 143/1296 [00:00<00:02,  528.17it/s]
 13%|█▎        | Scoring GeneralizingEstimator : 164/1296 [00:00<00:02,  540.30it/s]
 14%|█▍        | Scoring GeneralizingEstimator : 185/1296 [00:00<00:02,  549.24it/s]
 16%|█▌        | Scoring GeneralizingEstimator : 206/1296 [00:00<00:01,  557.01it/s]
 18%|█▊        | Scoring GeneralizingEstimator : 227/1296 [00:00<00:01,  564.00it/s]
 19%|█▉        | Scoring GeneralizingEstimator : 248/1296 [00:00<00:01,  569.17it/s]
 21%|██        | Scoring GeneralizingEstimator : 268/1296 [00:00<00:01,  570.69it/s]
 22%|██▏       | Scoring GeneralizingEstimator : 289/1296 [00:00<00:01,  575.18it/s]
 24%|██▍       | Scoring GeneralizingEstimator : 310/1296 [00:00<00:01,  578.06it/s]
 26%|██▌       | Scoring GeneralizingEstimator : 332/1296 [00:00<00:01,  583.98it/s]
 27%|██▋       | Scoring GeneralizingEstimator : 352/1296 [00:00<00:01,  584.60it/s]
 28%|██▊       | Scoring GeneralizingEstimator : 367/1296 [00:00<00:01,  573.08it/s]
 29%|██▉       | Scoring GeneralizingEstimator : 382/1296 [00:00<00:01,  563.16it/s]
 31%|███       | Scoring GeneralizingEstimator : 400/1296 [00:00<00:01,  560.58it/s]
 32%|███▏      | Scoring GeneralizingEstimator : 419/1296 [00:00<00:01,  560.51it/s]
 34%|███▍      | Scoring GeneralizingEstimator : 440/1296 [00:00<00:01,  562.89it/s]
 35%|███▌      | Scoring GeneralizingEstimator : 457/1296 [00:00<00:01,  558.49it/s]
 36%|███▋      | Scoring GeneralizingEstimator : 471/1296 [00:00<00:01,  548.66it/s]
 38%|███▊      | Scoring GeneralizingEstimator : 491/1296 [00:00<00:01,  550.24it/s]
 39%|███▊      | Scoring GeneralizingEstimator : 502/1296 [00:00<00:01,  535.34it/s]
 40%|███▉      | Scoring GeneralizingEstimator : 518/1296 [00:00<00:01,  531.34it/s]
 42%|████▏     | Scoring GeneralizingEstimator : 539/1296 [00:00<00:01,  536.97it/s]
 43%|████▎     | Scoring GeneralizingEstimator : 557/1296 [00:01<00:01,  536.66it/s]
 44%|████▍     | Scoring GeneralizingEstimator : 575/1296 [00:01<00:01,  535.76it/s]
 46%|████▌     | Scoring GeneralizingEstimator : 597/1296 [00:01<00:01,  541.00it/s]
 47%|████▋     | Scoring GeneralizingEstimator : 614/1296 [00:01<00:01,  538.08it/s]
 49%|████▉     | Scoring GeneralizingEstimator : 632/1296 [00:01<00:01,  537.70it/s]
 50%|█████     | Scoring GeneralizingEstimator : 652/1296 [00:01<00:01,  540.93it/s]
 52%|█████▏    | Scoring GeneralizingEstimator : 670/1296 [00:01<00:01,  540.15it/s]
 53%|█████▎    | Scoring GeneralizingEstimator : 689/1296 [00:01<00:01,  540.92it/s]
 55%|█████▍    | Scoring GeneralizingEstimator : 710/1296 [00:01<00:01,  545.58it/s]
 56%|█████▋    | Scoring GeneralizingEstimator : 729/1296 [00:01<00:01,  546.51it/s]
 58%|█████▊    | Scoring GeneralizingEstimator : 750/1296 [00:01<00:00,  550.16it/s]
 59%|█████▉    | Scoring GeneralizingEstimator : 768/1296 [00:01<00:00,  549.15it/s]
 61%|██████    | Scoring GeneralizingEstimator : 786/1296 [00:01<00:00,  547.16it/s]
 62%|██████▏   | Scoring GeneralizingEstimator : 805/1296 [00:01<00:00,  547.88it/s]
 64%|██████▎   | Scoring GeneralizingEstimator : 823/1296 [00:01<00:00,  546.88it/s]
 65%|██████▌   | Scoring GeneralizingEstimator : 843/1296 [00:01<00:00,  548.55it/s]
 67%|██████▋   | Scoring GeneralizingEstimator : 864/1296 [00:01<00:00,  552.54it/s]
 68%|██████▊   | Scoring GeneralizingEstimator : 880/1296 [00:01<00:00,  548.14it/s]
 69%|██████▉   | Scoring GeneralizingEstimator : 893/1296 [00:01<00:00,  539.07it/s]
 70%|███████   | Scoring GeneralizingEstimator : 908/1296 [00:01<00:00,  533.12it/s]
 71%|███████   | Scoring GeneralizingEstimator : 922/1296 [00:01<00:00,  526.65it/s]
 72%|███████▏  | Scoring GeneralizingEstimator : 937/1296 [00:01<00:00,  522.23it/s]
 74%|███████▎  | Scoring GeneralizingEstimator : 954/1296 [00:01<00:00,  520.84it/s]
 75%|███████▌  | Scoring GeneralizingEstimator : 974/1296 [00:01<00:00,  523.71it/s]
 77%|███████▋  | Scoring GeneralizingEstimator : 994/1296 [00:01<00:00,  526.59it/s]
 78%|███████▊  | Scoring GeneralizingEstimator : 1014/1296 [00:01<00:00,  529.90it/s]
 79%|███████▉  | Scoring GeneralizingEstimator : 1025/1296 [00:01<00:00,  519.18it/s]
 80%|████████  | Scoring GeneralizingEstimator : 1038/1296 [00:01<00:00,  511.76it/s]
 82%|████████▏ | Scoring GeneralizingEstimator : 1057/1296 [00:01<00:00,  514.07it/s]
 83%|████████▎ | Scoring GeneralizingEstimator : 1073/1296 [00:02<00:00,  511.91it/s]
 84%|████████▍ | Scoring GeneralizingEstimator : 1088/1296 [00:02<00:00,  508.29it/s]
 85%|████████▌ | Scoring GeneralizingEstimator : 1103/1296 [00:02<00:00,  504.85it/s]
 86%|████████▌ | Scoring GeneralizingEstimator : 1115/1296 [00:02<00:00,  496.74it/s]
 87%|████████▋ | Scoring GeneralizingEstimator : 1131/1296 [00:02<00:00,  495.08it/s]
 89%|████████▉ | Scoring GeneralizingEstimator : 1151/1296 [00:02<00:00,  499.98it/s]
 90%|████████▉ | Scoring GeneralizingEstimator : 1163/1296 [00:02<00:00,  492.54it/s]
 91%|█████████ | Scoring GeneralizingEstimator : 1178/1296 [00:02<00:00,  489.66it/s]
 92%|█████████▏| Scoring GeneralizingEstimator : 1197/1296 [00:02<00:00,  493.25it/s]
 94%|█████████▎| Scoring GeneralizingEstimator : 1213/1296 [00:02<00:00,  491.81it/s]
 95%|█████████▌| Scoring GeneralizingEstimator : 1234/1296 [00:02<00:00,  497.93it/s]
 97%|█████████▋| Scoring GeneralizingEstimator : 1254/1296 [00:02<00:00,  502.66it/s]
 98%|█████████▊| Scoring GeneralizingEstimator : 1267/1296 [00:02<00:00,  496.57it/s]
 99%|█████████▉| Scoring GeneralizingEstimator : 1282/1296 [00:02<00:00,  493.30it/s]
100%|██████████| Scoring GeneralizingEstimator : 1296/1296 [00:02<00:00,  498.77it/s]
100%|██████████| Scoring GeneralizingEstimator : 1296/1296 [00:02<00:00,  521.92it/s]

  0%|          | Fitting GeneralizingEstimator : 0/36 [00:00<?,       ?it/s]
  8%|▊         | Fitting GeneralizingEstimator : 3/36 [00:00<00:00,   88.38it/s]
 22%|██▏       | Fitting GeneralizingEstimator : 8/36 [00:00<00:00,  118.92it/s]
 39%|███▉      | Fitting GeneralizingEstimator : 14/36 [00:00<00:00,  139.51it/s]
 58%|█████▊    | Fitting GeneralizingEstimator : 21/36 [00:00<00:00,  157.78it/s]
 75%|███████▌  | Fitting GeneralizingEstimator : 27/36 [00:00<00:00,  162.23it/s]
 86%|████████▌ | Fitting GeneralizingEstimator : 31/36 [00:00<00:00,  154.00it/s]
 97%|█████████▋| Fitting GeneralizingEstimator : 35/36 [00:00<00:00,  147.87it/s]
100%|██████████| Fitting GeneralizingEstimator : 36/36 [00:00<00:00,  149.13it/s]

  0%|          | Scoring GeneralizingEstimator : 0/1296 [00:00<?,       ?it/s]
  1%|          | Scoring GeneralizingEstimator : 13/1296 [00:00<00:03,  383.91it/s]
  2%|▏         | Scoring GeneralizingEstimator : 25/1296 [00:00<00:03,  367.73it/s]
  4%|▎         | Scoring GeneralizingEstimator : 46/1296 [00:00<00:02,  456.50it/s]
  5%|▍         | Scoring GeneralizingEstimator : 60/1296 [00:00<00:02,  444.63it/s]
  6%|▌         | Scoring GeneralizingEstimator : 74/1296 [00:00<00:02,  437.95it/s]
  7%|▋         | Scoring GeneralizingEstimator : 95/1296 [00:00<00:02,  472.49it/s]
  8%|▊         | Scoring GeneralizingEstimator : 109/1296 [00:00<00:02,  460.70it/s]
  9%|▉         | Scoring GeneralizingEstimator : 121/1296 [00:00<00:02,  444.55it/s]
 11%|█         | Scoring GeneralizingEstimator : 142/1296 [00:00<00:02,  468.42it/s]
 12%|█▏        | Scoring GeneralizingEstimator : 155/1296 [00:00<00:02,  457.92it/s]
 13%|█▎        | Scoring GeneralizingEstimator : 168/1296 [00:00<00:02,  448.58it/s]
 15%|█▍        | Scoring GeneralizingEstimator : 189/1296 [00:00<00:02,  466.28it/s]
 16%|█▌        | Scoring GeneralizingEstimator : 208/1296 [00:00<00:02,  475.99it/s]
 18%|█▊        | Scoring GeneralizingEstimator : 228/1296 [00:00<00:02,  487.10it/s]
 19%|█▉        | Scoring GeneralizingEstimator : 249/1296 [00:00<00:02,  499.39it/s]
 21%|██        | Scoring GeneralizingEstimator : 269/1296 [00:00<00:02,  507.15it/s]
 22%|██▏       | Scoring GeneralizingEstimator : 289/1296 [00:00<00:01,  514.16it/s]
 24%|██▍       | Scoring GeneralizingEstimator : 310/1296 [00:00<00:01,  523.01it/s]
 25%|██▌       | Scoring GeneralizingEstimator : 328/1296 [00:00<00:01,  523.73it/s]
 27%|██▋       | Scoring GeneralizingEstimator : 348/1296 [00:00<00:01,  528.43it/s]
 28%|██▊       | Scoring GeneralizingEstimator : 368/1296 [00:00<00:01,  533.25it/s]
 29%|██▉       | Scoring GeneralizingEstimator : 381/1296 [00:00<00:01,  521.76it/s]
 30%|███       | Scoring GeneralizingEstimator : 393/1296 [00:00<00:01,  509.78it/s]
 32%|███▏      | Scoring GeneralizingEstimator : 409/1296 [00:00<00:01,  506.10it/s]
 33%|███▎      | Scoring GeneralizingEstimator : 431/1296 [00:00<00:01,  515.76it/s]
 35%|███▍      | Scoring GeneralizingEstimator : 453/1296 [00:00<00:01,  523.17it/s]
 37%|███▋      | Scoring GeneralizingEstimator : 474/1296 [00:00<00:01,  529.15it/s]
 38%|███▊      | Scoring GeneralizingEstimator : 495/1296 [00:00<00:01,  535.12it/s]
 40%|███▉      | Scoring GeneralizingEstimator : 516/1296 [00:00<00:01,  539.63it/s]
 41%|████▏     | Scoring GeneralizingEstimator : 537/1296 [00:01<00:01,  544.52it/s]
 43%|████▎     | Scoring GeneralizingEstimator : 558/1296 [00:01<00:01,  548.44it/s]
 45%|████▍     | Scoring GeneralizingEstimator : 578/1296 [00:01<00:01,  550.77it/s]
 46%|████▌     | Scoring GeneralizingEstimator : 599/1296 [00:01<00:01,  554.49it/s]
 48%|████▊     | Scoring GeneralizingEstimator : 619/1296 [00:01<00:01,  556.73it/s]
 49%|████▉     | Scoring GeneralizingEstimator : 640/1296 [00:01<00:01,  560.29it/s]
 51%|█████     | Scoring GeneralizingEstimator : 660/1296 [00:01<00:01,  561.83it/s]
 53%|█████▎    | Scoring GeneralizingEstimator : 681/1296 [00:01<00:01,  564.67it/s]
 54%|█████▍    | Scoring GeneralizingEstimator : 702/1296 [00:01<00:01,  567.77it/s]
 56%|█████▌    | Scoring GeneralizingEstimator : 722/1296 [00:01<00:01,  569.02it/s]
 57%|█████▋    | Scoring GeneralizingEstimator : 743/1296 [00:01<00:00,  571.90it/s]
 59%|█████▉    | Scoring GeneralizingEstimator : 763/1296 [00:01<00:00,  573.00it/s]
 60%|██████    | Scoring GeneralizingEstimator : 784/1296 [00:01<00:00,  575.66it/s]
 62%|██████▏   | Scoring GeneralizingEstimator : 805/1296 [00:01<00:00,  578.06it/s]
 64%|██████▎   | Scoring GeneralizingEstimator : 826/1296 [00:01<00:00,  580.11it/s]
 65%|██████▌   | Scoring GeneralizingEstimator : 847/1296 [00:01<00:00,  582.35it/s]
 67%|██████▋   | Scoring GeneralizingEstimator : 867/1296 [00:01<00:00,  582.82it/s]
 68%|██████▊   | Scoring GeneralizingEstimator : 887/1296 [00:01<00:00,  583.17it/s]
 70%|███████   | Scoring GeneralizingEstimator : 908/1296 [00:01<00:00,  585.01it/s]
 72%|███████▏  | Scoring GeneralizingEstimator : 928/1296 [00:01<00:00,  585.11it/s]
 73%|███████▎  | Scoring GeneralizingEstimator : 947/1296 [00:01<00:00,  583.91it/s]
 75%|███████▍  | Scoring GeneralizingEstimator : 969/1296 [00:01<00:00,  586.20it/s]
 76%|███████▋  | Scoring GeneralizingEstimator : 990/1296 [00:01<00:00,  587.47it/s]
 78%|███████▊  | Scoring GeneralizingEstimator : 1011/1296 [00:01<00:00,  588.26it/s]
 80%|███████▉  | Scoring GeneralizingEstimator : 1031/1296 [00:01<00:00,  588.37it/s]
 81%|████████  | Scoring GeneralizingEstimator : 1051/1296 [00:01<00:00,  588.41it/s]
 83%|████████▎ | Scoring GeneralizingEstimator : 1072/1296 [00:01<00:00,  589.77it/s]
 84%|████████▍ | Scoring GeneralizingEstimator : 1089/1296 [00:01<00:00,  585.08it/s]
 85%|████████▌ | Scoring GeneralizingEstimator : 1105/1296 [00:01<00:00,  579.01it/s]
 86%|████████▋ | Scoring GeneralizingEstimator : 1120/1296 [00:02<00:00,  571.91it/s]
 88%|████████▊ | Scoring GeneralizingEstimator : 1134/1296 [00:02<00:00,  562.73it/s]
 89%|████████▊ | Scoring GeneralizingEstimator : 1147/1296 [00:02<00:00,  552.78it/s]
 90%|████████▉ | Scoring GeneralizingEstimator : 1161/1296 [00:02<00:00,  545.44it/s]
 91%|█████████ | Scoring GeneralizingEstimator : 1174/1296 [00:02<00:00,  537.02it/s]
 92%|█████████▏| Scoring GeneralizingEstimator : 1189/1296 [00:02<00:00,  531.51it/s]
 93%|█████████▎| Scoring GeneralizingEstimator : 1204/1296 [00:02<00:00,  526.01it/s]
 94%|█████████▍| Scoring GeneralizingEstimator : 1219/1296 [00:02<00:00,  518.71it/s]
 96%|█████████▌| Scoring GeneralizingEstimator : 1239/1296 [00:02<00:00,  522.35it/s]
 97%|█████████▋| Scoring GeneralizingEstimator : 1257/1296 [00:02<00:00,  519.46it/s]
 98%|█████████▊| Scoring GeneralizingEstimator : 1271/1296 [00:02<00:00,  513.97it/s]
100%|█████████▉| Scoring GeneralizingEstimator : 1292/1296 [00:02<00:00,  519.38it/s]
100%|██████████| Scoring GeneralizingEstimator : 1296/1296 [00:02<00:00,  539.07it/s]

  0%|          | Fitting GeneralizingEstimator : 0/36 [00:00<?,       ?it/s]
 11%|█         | Fitting GeneralizingEstimator : 4/36 [00:00<00:00,  117.13it/s]
 22%|██▏       | Fitting GeneralizingEstimator : 8/36 [00:00<00:00,  117.47it/s]
 33%|███▎      | Fitting GeneralizingEstimator : 12/36 [00:00<00:00,  117.75it/s]
 47%|████▋     | Fitting GeneralizingEstimator : 17/36 [00:00<00:00,  125.85it/s]
 64%|██████▍   | Fitting GeneralizingEstimator : 23/36 [00:00<00:00,  137.22it/s]
 78%|███████▊  | Fitting GeneralizingEstimator : 28/36 [00:00<00:00,  139.21it/s]
 92%|█████████▏| Fitting GeneralizingEstimator : 33/36 [00:00<00:00,  140.12it/s]
100%|██████████| Fitting GeneralizingEstimator : 36/36 [00:00<00:00,  140.74it/s]
100%|██████████| Fitting GeneralizingEstimator : 36/36 [00:00<00:00,  139.07it/s]

  0%|          | Scoring GeneralizingEstimator : 0/1296 [00:00<?,       ?it/s]
  1%|          | Scoring GeneralizingEstimator : 15/1296 [00:00<00:02,  438.17it/s]
  2%|▏         | Scoring GeneralizingEstimator : 27/1296 [00:00<00:03,  395.37it/s]
  3%|▎         | Scoring GeneralizingEstimator : 39/1296 [00:00<00:03,  381.44it/s]
  4%|▍         | Scoring GeneralizingEstimator : 51/1296 [00:00<00:03,  372.12it/s]
  5%|▌         | Scoring GeneralizingEstimator : 67/1296 [00:00<00:03,  393.87it/s]
  6%|▋         | Scoring GeneralizingEstimator : 83/1296 [00:00<00:02,  408.28it/s]
  8%|▊         | Scoring GeneralizingEstimator : 99/1296 [00:00<00:02,  418.02it/s]
  9%|▉         | Scoring GeneralizingEstimator : 118/1296 [00:00<00:02,  438.14it/s]
 11%|█         | Scoring GeneralizingEstimator : 138/1296 [00:00<00:02,  458.72it/s]
 12%|█▏        | Scoring GeneralizingEstimator : 159/1296 [00:00<00:02,  477.35it/s]
 14%|█▍        | Scoring GeneralizingEstimator : 180/1296 [00:00<00:02,  492.98it/s]
 15%|█▌        | Scoring GeneralizingEstimator : 200/1296 [00:00<00:02,  500.44it/s]
 17%|█▋        | Scoring GeneralizingEstimator : 214/1296 [00:00<00:02,  490.94it/s]
 18%|█▊        | Scoring GeneralizingEstimator : 234/1296 [00:00<00:02,  500.47it/s]
 19%|█▉        | Scoring GeneralizingEstimator : 252/1296 [00:00<00:02,  502.10it/s]
 21%|██        | Scoring GeneralizingEstimator : 268/1296 [00:00<00:02,  499.41it/s]
 22%|██▏       | Scoring GeneralizingEstimator : 282/1296 [00:00<00:02,  490.70it/s]
 23%|██▎       | Scoring GeneralizingEstimator : 296/1296 [00:00<00:02,  484.33it/s]
 24%|██▍       | Scoring GeneralizingEstimator : 308/1296 [00:00<00:02,  474.08it/s]
 25%|██▌       | Scoring GeneralizingEstimator : 329/1296 [00:00<00:01,  485.38it/s]
 27%|██▋       | Scoring GeneralizingEstimator : 347/1296 [00:00<00:01,  487.46it/s]
 28%|██▊       | Scoring GeneralizingEstimator : 360/1296 [00:00<00:01,  479.70it/s]
 29%|██▉       | Scoring GeneralizingEstimator : 380/1296 [00:00<00:01,  487.02it/s]
 30%|███       | Scoring GeneralizingEstimator : 395/1296 [00:00<00:01,  484.00it/s]
 32%|███▏      | Scoring GeneralizingEstimator : 411/1296 [00:00<00:01,  483.11it/s]
 33%|███▎      | Scoring GeneralizingEstimator : 432/1296 [00:00<00:01,  491.77it/s]
 35%|███▍      | Scoring GeneralizingEstimator : 448/1296 [00:00<00:01,  490.05it/s]
 36%|███▌      | Scoring GeneralizingEstimator : 465/1296 [00:00<00:01,  490.87it/s]
 38%|███▊      | Scoring GeneralizingEstimator : 486/1296 [00:00<00:01,  499.20it/s]
 39%|███▉      | Scoring GeneralizingEstimator : 506/1296 [00:01<00:01,  504.71it/s]
 41%|████      | Scoring GeneralizingEstimator : 527/1296 [00:01<00:01,  511.49it/s]
 42%|████▏     | Scoring GeneralizingEstimator : 548/1296 [00:01<00:01,  517.58it/s]
 44%|████▎     | Scoring GeneralizingEstimator : 566/1296 [00:01<00:01,  518.27it/s]
 45%|████▌     | Scoring GeneralizingEstimator : 588/1296 [00:01<00:01,  526.26it/s]
 47%|████▋     | Scoring GeneralizingEstimator : 608/1296 [00:01<00:01,  530.19it/s]
 48%|████▊     | Scoring GeneralizingEstimator : 627/1296 [00:01<00:01,  531.55it/s]
 50%|█████     | Scoring GeneralizingEstimator : 649/1296 [00:01<00:01,  538.49it/s]
 52%|█████▏    | Scoring GeneralizingEstimator : 668/1296 [00:01<00:01,  539.61it/s]
 53%|█████▎    | Scoring GeneralizingEstimator : 690/1296 [00:01<00:01,  545.96it/s]
 55%|█████▍    | Scoring GeneralizingEstimator : 711/1296 [00:01<00:01,  550.28it/s]
 56%|█████▌    | Scoring GeneralizingEstimator : 728/1296 [00:01<00:01,  547.19it/s]
 58%|█████▊    | Scoring GeneralizingEstimator : 750/1296 [00:01<00:00,  553.02it/s]
 59%|█████▉    | Scoring GeneralizingEstimator : 771/1296 [00:01<00:00,  556.77it/s]
 61%|██████    | Scoring GeneralizingEstimator : 790/1296 [00:01<00:00,  557.01it/s]
 63%|██████▎   | Scoring GeneralizingEstimator : 811/1296 [00:01<00:00,  560.30it/s]
 64%|██████▍   | Scoring GeneralizingEstimator : 832/1296 [00:01<00:00,  563.69it/s]
 65%|██████▌   | Scoring GeneralizingEstimator : 846/1296 [00:01<00:00,  555.51it/s]
 67%|██████▋   | Scoring GeneralizingEstimator : 862/1296 [00:01<00:00,  550.96it/s]
 68%|██████▊   | Scoring GeneralizingEstimator : 884/1296 [00:01<00:00,  555.71it/s]
 70%|██████▉   | Scoring GeneralizingEstimator : 904/1296 [00:01<00:00,  557.06it/s]
 71%|███████   | Scoring GeneralizingEstimator : 919/1296 [00:01<00:00,  550.64it/s]
 72%|███████▏  | Scoring GeneralizingEstimator : 938/1296 [00:01<00:00,  551.25it/s]
 74%|███████▍  | Scoring GeneralizingEstimator : 957/1296 [00:01<00:00,  550.38it/s]
 75%|███████▍  | Scoring GeneralizingEstimator : 971/1296 [00:01<00:00,  542.77it/s]
 76%|███████▋  | Scoring GeneralizingEstimator : 991/1296 [00:01<00:00,  545.39it/s]
 78%|███████▊  | Scoring GeneralizingEstimator : 1009/1296 [00:01<00:00,  544.41it/s]
 79%|███████▉  | Scoring GeneralizingEstimator : 1022/1296 [00:01<00:00,  535.20it/s]
 80%|████████  | Scoring GeneralizingEstimator : 1043/1296 [00:01<00:00,  539.44it/s]
 82%|████████▏ | Scoring GeneralizingEstimator : 1060/1296 [00:02<00:00,  536.63it/s]
 83%|████████▎ | Scoring GeneralizingEstimator : 1074/1296 [00:02<00:00,  530.03it/s]
 85%|████████▍ | Scoring GeneralizingEstimator : 1096/1296 [00:02<00:00,  535.48it/s]
 86%|████████▌ | Scoring GeneralizingEstimator : 1114/1296 [00:02<00:00,  534.91it/s]
 87%|████████▋ | Scoring GeneralizingEstimator : 1131/1296 [00:02<00:00,  532.81it/s]
 89%|████████▉ | Scoring GeneralizingEstimator : 1153/1296 [00:02<00:00,  538.85it/s]
 90%|█████████ | Scoring GeneralizingEstimator : 1170/1296 [00:02<00:00,  536.90it/s]
 91%|█████████▏| Scoring GeneralizingEstimator : 1184/1296 [00:02<00:00,  530.49it/s]
 93%|█████████▎| Scoring GeneralizingEstimator : 1206/1296 [00:02<00:00,  535.61it/s]
 94%|█████████▍| Scoring GeneralizingEstimator : 1221/1296 [00:02<00:00,  529.66it/s]
 96%|█████████▌| Scoring GeneralizingEstimator : 1239/1296 [00:02<00:00,  529.77it/s]
 97%|█████████▋| Scoring GeneralizingEstimator : 1260/1296 [00:02<00:00,  534.21it/s]
 98%|█████████▊| Scoring GeneralizingEstimator : 1274/1296 [00:02<00:00,  528.09it/s]
100%|█████████▉| Scoring GeneralizingEstimator : 1291/1296 [00:02<00:00,  526.59it/s]
100%|██████████| Scoring GeneralizingEstimator : 1296/1296 [00:02<00:00,  523.47it/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.0,
    vmax=1.0,
)
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")
cbar = plt.colorbar(im, ax=ax)
cbar.set_label("AUC")
Temporal generalization

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.0)
del epochs
fwd = mne.read_forward_solution(meg_path / "sample_audvis-meg-eeg-oct-6-fwd.fif")
inv = mne.minimum_norm.make_inverse_operator(evoked_time_gen.info, fwd, cov, loose=0.0)
stc = mne.minimum_norm.apply_inverse(evoked_time_gen, inv, 1.0 / 9.0, "dSPM")
del fwd, inv
Computing rank from data with rank=None
    Using tolerance 3.1e-10 (2.2e-16 eps * 203 dim * 7e+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 : 1353
[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)
    Forward solutions combined: MEG, EEG
    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.91709
    scaling factor to adjust the trace = 6.26373e+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.4% 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
)
50 decoding
Using control points [1.98776221 2.41838256 8.06628583]

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.

Exercise#

  • Explore other datasets from MNE (e.g. Face dataset from SPM to predict Face vs. Scrambled)

References#

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

Estimated memory usage: 129 MB

Gallery generated by Sphinx-Gallery