1

I am trying to get started with machine learning, so I have installed the packages: numpy, Scikit-learn, matplotlib, scipy. Some I have installed directly from pip with:

python -m pip install "package name"

and and others i have downloaded the binary files and then installed with pip. It shows no errors when I import matplotlib, numpy and sklearn, but when I write:

from sklearn import svm

it gives me the error:

ImportError: cannot import name 'svm'  

I am on Python 3.5.1 and on Windows 10. Does anyone have any solutions?

Leb
  • 15,483
  • 10
  • 56
  • 75
  • Have you tried simply `import sklearn` from your other comment below it doesn't seem that you installed it properly. – Leb Jan 07 '16 at 15:25
  • @Leb Yes i have tried that and it works just fine, that is why i am so confused :/ I might just reinstall python or something... Now even if i open a new file and just write `import sklearn` it gives me no errors but for some reason it writes: hello world.. I am so confused – Marc Erhardtsen Jan 07 '16 at 15:48
  • Try this then: `from sklearn.svm import SVC`. Does that work? – Leb Jan 07 '16 at 15:49
  • No it still does not work, I guess I must have installed them incorrectly like Chris said – Marc Erhardtsen Jan 07 '16 at 16:14

2 Answers2

1
import sklearn.svm as svm

model = svm.SVC()
....

http://scikit-learn.org/stable/modules/classes.html#module-sklearn.svm

Chris
  • 957
  • 5
  • 10
  • 1
    It still gives me an error. `ImportError: No module named 'sklearn.svm'; 'sklearn' is not a package` – Marc Erhardtsen Jan 07 '16 at 14:51
  • There must be an installation issue. Given you say it writes hello world when you import the module, something must be incorrect. I recommend anaconda if you have the flexibility to do so, it makes managing these things much easier. – Chris Jan 07 '16 at 16:04
  • @Chis Should i just delete the packages and try with anaconda then? Also would it make a difference that i installed some of them through pip and others i downloaded from [here](http://www.lfd.uci.edu/~gohlke/pythonlibs)? – Marc Erhardtsen Jan 07 '16 at 16:10
  • uninstall python then install anaconda, it has easy installation for a tonne of packages. you just do conda install sklearn and it will get the correct version for your python, OS and architecture. you can also use pip and binary installs for some less popular modules, but 90% of the stuff you need is a one line install, no need to worry about selecting the correct dist etc. In fact it already comes with sklearn installed. http://docs.continuum.io/anaconda/pkg-docs – Chris Jan 08 '16 at 08:55
0

It does seem that you didn't install it properly. Since you're on windows I would recommend using the Unofficial Windows Binaries for Python Extension Packages website to install future packages.

Make sure you also install the proper binaries as I pointed out in this post Installing scipy in Python 3.5 on 32-bit Windows 7 Machine. The windows version doesn't matter just make sure you're downloading Visual C++ 2015 redistributable package.

Community
  • 1
  • 1
Leb
  • 15,483
  • 10
  • 56
  • 75