问题
I would like to use AgglomerativeClustering from sklearn but I am not able to import it.
>>> from sklearn.cluster import AgglomerativeClustering
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name AgglomerativeClustering
The message dosen't give much information on what's causing the issue, can you help?
Python version
Python 2.7.6 (default, Jun 22 2015, 17:58:13)
[GCC 4.8.2] on linux2
OS info:
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 version
$ pip freeze | grep scikit-learn
scikit-learn==0.14.1
Further infos
>>> import sklearn.cluster; print(sklearn.cluster.__file__)
/usr/lib/python2.7/dist-packages/sklearn/cluster/__init__.pyc
回答1:
Looking at the changelog for version 0.15 it looks like the AgglomerativeClustering
class was introduced in this version:
Changelog
New Features
[...]
- Added
cluster.AgglomerativeClustering
for hierarchical agglomerative clustering with average linkage, complete linkage and ward strategies. [...]
So the only fix is to install a newer version of sklearn
.
来源:https://stackoverflow.com/questions/32219881/why-cant-i-import-the-agglomerativeclustering-class