Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scikit-learn in Python (svm function)

I have this little problem with sklearn in python. It seems that I installed it correctly and indeed when I do from sklearn import svm python seems to be ok with that (no error message). However my function is not working well as I got the message AttributeError: 'module' object has no attribute 'SVC' I'm trying to use svm optimisation function. It is a little bit awkward but this would mean that SVC is not inside sklearn which is not possible. Can anyone help me please.

like image 253
rado Avatar asked Mar 08 '26 14:03

rado


1 Answers

if you:

from sklearn import svm

You are importing the "svm" name from within the sklearn package, into your module as 'svm'. To access objects on it, keep the svm prefix:

svc = svm.SVC()

Another example, you could also do it like this:

import sklearn
svc = sklearn.svm.SVC()

And maybe, you could do this (depends how the package is setup):

from sklearn.svm import SVC
svc = SVC()
like image 120
Joe Avatar answered Mar 10 '26 02:03

Joe