You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Adding support of GridSearchCV for mne.decoding.LinearModel #7027
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:
fromsklearnimportpreprocessing, svmfromsklearn.pipelineimportmake_pipelinefromsklearn.model_selectionimportGridSearchCVfrommne.decodingimportSlidingEstimator, LinearModel, get_coefparameters= {'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.
Activity
agramfort commentedon Nov 17, 2019
@iamsc sorry for the response delay. Yes you are right.
can you try to update https://github.com/mne-tools/mne-python/blob/master/mne/decoding/base.py accordingly and send us a pull request to fix this?
what I would suggest is to try to find .coef_ with
hasattrand if not try with.best_estimator_.coef_before failing due to missing coef_