Running into ImportError with sklearn while doing

2020-04-30 02:35发布

问题:

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.