Nilearn sklearn classification problem/error


I adapted the SVM tutorial in nilearn ( to my data.

After step
coef_ = svc.coef_

I get the error message: “AttributeError: ‘SVC’ object has no attribute ‘dual_coef_’”

However, sklearn.svm.svc should return the “coef_” attribute (see

I’ve also updated the sklearn version without success…

thanks for help!

Are you sure that the svc you use has been trained already ?

Also, what happens when you run the python script (plot_decoding_tutorial) at the bottom of the page ?


@Mike_Myers What is your Python version? If it is 3.6 I suggest downgrading to 3.4 and re-running the code. There seems to be some compatibility issues with sklearn svm module in 3.6. Hope this helps :slight_smile:.

Hi Bertrand

Yes, model is trained as I can get the cv_scores. Due to some reason, I can’t get svc.coef_ which makes its impossible to plot as I have first to inverse it with masker.

Thanks Sanjula. I have version 3.7.6.
Scikit-learn from 0.23 requires Python 3.6 or greater…

It seems to be a nightmare to downgrade my Python version to 3.4…I use Anaconda. I’ll keep trying…

No, please don’t downgrade.
If you haven’t run explicitly[:-30], conditions[:-30])
the model has not been fit, hence the error.
Simply running
cv_score = cross_val_score(svc, fmri_masked, conditions)
is not enough.


That’s it. Many thanks Bertrand. I somehow missed this line of code (which is indeed important :))

1 Like

Great to hear it’s been resolved @Mike_Myers! I assumed you already ran the function, hence the suggestion to downgrade python. Thanks @bthirion for the solution!

1 Like