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.
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
SlidingEstimatorto classify my experimental conditions. I also used theGridSearchCV(Scikit-learn's function) to find out the best hyper-parameter c of SVM. However, I found that theLinearModelof MNE cannot obtain thecoef_parameter in refitted estimator ofGridSearchCVwhen I tried to observe the spatial pattern of refitted estimator.Here is part of my code:
Describe your solution
From the source code of MNE, we know that the function
get_coefinLinearModeldoes not consider the refitted estimator ofGridSearchCV. As we use theGridSearchCV, we encounter the ValueError problem because thecoef_of refitted estimator is located intime_decoder._final_estimator.best_estimator_.coef_. Therefore, I was wondering if we can add support ofGridSearchCVfor the classLinearModel.