Scikit-learn in Python (svm function)

rado picture rado · Apr 20, 2015 · Viewed 15k times · Source

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.

Answer

Joe picture Joe · Apr 20, 2015

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()