为什么我不能导入 AgglomerativeClustering class?

Why can't I import the AgglomerativeClustering class?

我想使用 sklearn 中的 AgglomerativeClustering,但我无法导入它。

>>> from sklearn.cluster import AgglomerativeClustering
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name AgglomerativeClustering

该消息没有提供太多有关问题原因的信息,你能帮忙吗?


Python版本

Python 2.7.6 (default, Jun 22 2015, 17:58:13) 
[GCC 4.8.2] on linux2

OS 信息:

3.13.0-55-generic #94-Ubuntu SMP Thu Jun 18 00:27:10 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux

Scikit-learn 版本

$ pip freeze | grep scikit-learn
scikit-learn==0.14.1

更多信息

>>> import sklearn.cluster; print(sklearn.cluster.__file__)
/usr/lib/python2.7/dist-packages/sklearn/cluster/__init__.pyc

查看 changelog for version 0.15 似乎 AgglomerativeClustering class 是在此版本中引入的:

Changelog

New Features

[...]

  • Added cluster.AgglomerativeClustering for hierarchical agglomerative clustering with average linkage, complete linkage and ward strategies. [...]

所以唯一的解决方法是安装更新版本的 sklearn