问题描述
我正在尝试从集群模块调用一个函数,如下所示:
I'm trying to call a function from the cluster module, like so:
import sklearn
db = sklearn.cluster.DBSCAN()
我收到以下错误:
AttributeError: 'module' object has no attribute 'cluster'
在 IPython 中完成选项卡,我似乎可以访问 base、clone、externals、re、setup_module、sys 和 warning 模块.没有别的,尽管其他(包括集群)在 sklearn 目录中.
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.
遵循以下 pbu 的建议并使用
Following pbu's advice below and using
from sklearn import cluster
我明白了:
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.
我在 Windows 上使用 Python 3.4,scikit-learn 0.16.1.
I'm using Python 3.4 on Windows, scikit-learn 0.16.1.
推荐答案
问题在于 scipy/numpy 安装.我一直在使用来自 http://www.lfd 的(通常非常好!)非官方安装程序.uci.edu/~gohlke/pythonlibs/.从那里卸载/重新安装没有区别,但使用官方安装程序进行安装(链接自 http://www.scipy.org/install.html) 成功了.
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.
这篇关于导入 scikit-learn 模块时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!