Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error importing scikit-learn modules

I'm trying to call a function from the cluster module, like so:

import sklearn
db = sklearn.cluster.DBSCAN()

and I get the following error:

AttributeError: 'module' object has no attribute 'cluster'

Tab-completing in IPython, I seem to have access to the base, clone, externals, re, setup_module, sys, and warning modules. Nothing else, though others (including cluster) are in the sklearn directory.

Following pbu's advice below and using

from sklearn import cluster

I get:

Traceback (most recent call last):
  File "test.py", line 2, in <module>
    from sklearn import cluster
  File "C:\Python34\lib\site-packages\sklearn\cluster\__init__.py", line 6, in <module>
    from .spectral import spectral_clustering, SpectralClustering
  File "C:\Python34\lib\site-packages\sklearn\cluster\spectral.py", line 13, in <module>
    from ..utils import check_random_state, as_float_array
  File "C:\Python34\lib\site-packages\sklearn\utils\__init__.py", line 16, in <module>
    from .class_weight import compute_class_weight, compute_sample_weight
  File "C:\Python34\lib\site-packages\sklearn\utils\class_weight.py", line 7, in <module>
    from ..utils.fixes import in1d
  File "C:\Python34\lib\site-packages\sklearn\utils\fixes.py", line 318, in <module>
    from scipy.sparse.linalg import lsqr as sparse_lsqr
  File "C:\Python34\lib\site-packages\scipy\sparse\linalg\__init__.py", line 109, in <module>
    from .isolve import *
  File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\__init__.py", line 6, in <module>
    from .iterative import *
  File "C:\Python34\lib\site-packages\scipy\sparse\linalg\isolve\iterative.py", line 7, in <module>
    from . import _iterative
ImportError: DLL load failed: The specified module could not be found.

I'm using Python 3.4 on Windows, scikit-learn 0.16.1.

like image 590
Jon Rein Avatar asked Jun 10 '15 20:06

Jon Rein


People also ask

How do I fix sklearn error?

To solve the error, install the module by running the pip install scikit-learn command. Open your terminal in your project's root directory and install the scikit-learn module. Copied! The commands also install the scipy , matplotlib and numpy packages but you can only install the packages you intend to use.


2 Answers

You probably don't use Numpy+MKL, but only Numpy.

I had the same problem and reinstalling Numpy with MKL

pip install --upgrade --force-reinstall "numpy‑1.16.3+mkl‑cp37‑cp37m‑win32.whl"

fixed it.

Note: update the file to the latest version, possibly 64bit - see the list of available Windows binaries

like image 93
Jirka Avatar answered Oct 18 '22 21:10

Jirka


Problem was with scipy/numpy install. I'd been using the (normally excellent!) unofficial installers from http://www.lfd.uci.edu/~gohlke/pythonlibs/. Uninstall/re-install from there made no difference, but installing with the official installers (linked from http://www.scipy.org/install.html) did the trick.

like image 6
Jon Rein Avatar answered Oct 18 '22 21:10

Jon Rein