I am using sklearn to fit a SVM to some data. Since I wanted to use cross-validation and evaluate my classification accuracy using permutations, I am using the permutation_test_score() function (https://scikit-learn.org/stable/modules/generated/sklearn.model_selection.permutation_test_score.html#sklearn.model_selection.permutation_test_score)
I have implemented my SVM like this:
svc = SVC(kernel='linear', verbose=True) nr_perm = 100 cv = StratifiedKFold(n_splits=5) score, pscores, pvalue = permutation_test_score(svc, X, y, scoring="accuracy", cv=cv, n_permutations=nr_perm)
According to the documentation, this function fits and evaluates the model using cross-validation. However, even after using permutation_test_score I cannot use coef_ to get the weights of the features of my model. I get the following error message:
AttributeError: 'SVC' object has no attribute 'dual_coef_'
If I use svc.fit(X, y), I can then use svc.coef_ to access them:
svc = SVC(kernel='linear', verbose=True) svc.fit(X,y) coefs = svc.coef_
I have encountered the same problem when using other functions from sklearn.model_selection.
Does anyone know how I can access the feature weights?