Skip to content

Adding support of GridSearchCV for mne.decoding.LinearModel #7027

@iamsc

Description

@iamsc

Describe the problem

Hi, all~
I recently worked on the decoding analysis using MNE. In my analysis, I used the SVM (linear kernel) and function SlidingEstimator to classify my experimental conditions. I also used the GridSearchCV (Scikit-learn's function) to find out the best hyper-parameter c of SVM. However, I found that the LinearModel of MNE cannot obtain the coef_ parameter in refitted estimator of GridSearchCV when I tried to observe the spatial pattern of refitted estimator.

Here is part of my code:

from sklearn import preprocessing, svm
from sklearn.pipeline import make_pipeline
from sklearn.model_selection import GridSearchCV
from mne.decoding import SlidingEstimator, LinearModel, get_coef

parameters = {'kernel':['linear'], 'C':[1, 10, 100, 1000, 10000]}
# X is a trials*sensors*time matrix.
# y is a vector of condition labels.

clf = make_pipeline(preprocessing.StandardScaler(), LinearModel(GridSearchCV(svm.SVC(), parameters, cv=5, refit=True, iid=False, n_jobs= 5)))
time_decoder = SlidingEstimator(clf, n_jobs=5, scoring='roc_auc', verbose=True)
time_decoder.fit(X, y)
coef = get_coef(time_decoder, 'patterns_', inverse_transform=True) # ValueError

Describe your solution

From the source code of MNE, we know that the function get_coef in LinearModel does not consider the refitted estimator of GridSearchCV. As we use the GridSearchCV, we encounter the ValueError problem because the coef_ of refitted estimator is located in time_decoder._final_estimator.best_estimator_.coef_. Therefore, I was wondering if we can add support of GridSearchCV for the class LinearModel.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions