python - 导入 scikit-learn 模块时出错

标签 python scikit-learn

我正在尝试从集群模块调用函数,如下所示:

import sklearn
db = sklearn.cluster.DBSCAN()

我收到以下错误:

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

IPython 中的 Tab 完成,我似乎可以访问 base、clone、externals、re、setup_module、sys 和 warning 模块。没有别的,尽管其他(包括集群)在 sklearn 目录中。

遵循以下 pbu 的建议并使用

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。

最佳答案

您可能不会使用 Numpy+MKL,而只会使用 Numpy。

我有同样的问题,用 MKL 重新安装 Numpy

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

修好了。

注意:将文件更新到最新版本,可能是 64 位 - 参见 the list of available Windows binaries

关于python - 导入 scikit-learn 模块时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31720340/

相关文章:

python - 使用批处理文件运行当前文件夹中的脚本

python - Keras - 'Node' 对象没有属性 'output_masks'

python - 网格搜索CV : can't pickle function error when trying to pass lambda in parameter

python - DataFrame.index.levels 在削减数据帧后显示 "extra"值

python - Django 1.8 模板文件中图像显示问题

python - QApplication 实例已经存在

python - 如何在sklearn中调整score_func(特征选择)的超参数?

scikit-learn - DP-GMM和在线群集分配

python - Scikit-学习: "The least populated class in y has only 1 member"

python - 自动编码器分类绘制 Roc 曲线