2

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.

2 Answers 2

12

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()
Sign up to request clarification or add additional context in comments.

2 Comments

when I try 'from sklearn.svm import SVC' I got the error message cannot import name 'SVC'. Does this mean there is something wrong with the installation of sklearn ?
Can you try "pip freeze" in a command line and confirm that you can see the "sklearn" package?
0

According to this thread that i had refereed to a couple of days ago,perhaps you can try installing Scipy and then try to restart the python shell.

If it still gives the error try to add the respective package path's to the environment PATH variables.

In any case the link i shared should have multiple solutions to your query.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.