Running into ImportError with sklearn while doing tutorial

两盒软妹~` 提交于 2019-12-02 13:16:45

问题


Hi I'm trying to follow the machine learning 101 tutorial provided by sklearn, and I keep running into an error.

I have the most the sklearn version downloaded from here: https://github.com/scikit-learn/scikit-learn

I run Windows

python: 2.7.5 (32bit)

scipy: .12

numpy: 1.7.0

When I run

from sklearn.linear_model import LinearRegression
model = LinearRegression()

I get

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-7-9f5ae92552bb> in <module>()
----> 1 from sklearn.linear_model import LinearRegression
      2 model = LinearRegression()

C:\WinPython-32bit-2.7.5.1\python-2.7.5\lib\site-packages\sklearn\linear_model\__init__.py in <module>()
     10 # complete documentation.
     11 
---> 12 from .base import LinearRegression
     13 
     14 from .bayes import BayesianRidge, ARDRegression

C:\WinPython-32bit-2.7.5.1\python-2.7.5\lib\site-packages\sklearn\linear_model\base.py in <module>()
     28 from ..utils.sparsefuncs import (csc_mean_variance_axis0,
     29                                  inplace_csc_column_scale)
---> 30 from .cd_fast import sparse_std
     31 
     32 

ImportError: No module named cd_fast

And based on this: https://github.com/scikit-learn/scikit-learn/issues/1202

It might be an error with blas? But that's in scipy, and I had problems with that earlier, but I just updated scipy and it should be fine.

Please help! Thanks in advance


回答1:


You forgot to compile. Run python setup.py install in the source directory, or python setup.py build_ext --inplace, or grab a binary distribution.

(Much of scikit-learn is actually implemented in Cython, C or C++. You need C and C++ compilers to install it from source.)




回答2:


Copy paste answer from different question: In case you are using the binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/#scikit-learn. They require numpy-MKL, as indicated on the download page. The official numpy binaries won't work.



来源:https://stackoverflow.com/questions/17328386/running-into-importerror-with-sklearn-while-doing-tutorial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!