python - 无法识别凝聚聚类的新 distance_threshold 参数

标签 python scikit-learn

Scikit 包似乎无法识别我尝试使用的距离阈值参数,而不是 n-clusters 参数,因为我不知道最终会得到多少个簇,这取决于数据。

我想知道这是否是因为 distance_threshold 参数是最近推出的,但我在文件顶部导入了 scikit,所以我不明白为什么这会成为问题。只要我不包含此参数,一切都会正常。

import matplotlib.pyplot as plt   
%matplotlib inline
from sklearn.cluster import AgglomerativeClustering

cluster = AgglomerativeClustering(affinity='euclidean', linkage='ward', 
distance_threshold = 400.0)  #the last bit here is the problem
cluster.fit_predict(Revs) 
labels = np.array(cluster.labels_).tolist()

它应该运行集群,但我收到此错误消息:

**TypeError**: __init__() got an unexpected keyword argument 'distance_threshold'

最佳答案

最新版本的 sci-kit learn 中新增了 distance_threshold 参数。

New in version 0.21.

确保您的库已更新到最新版本。此错误主要是因为您使用的是旧版本。

您可以通过以下方式查看版本

import sklearn

# Check version
print(sklearn.__version__)
0.21.

它将显示您的 sci-kit 学习库的版本。要使用 distance_threshold 参数,版本必须为 0.21。

关于python - 无法识别凝聚聚类的新 distance_threshold 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56675127/

相关文章:

python - scikit KernelPCA 结果不稳定

python - 关闭 scikit-learn k-近邻中的警告消息

python - 修复 python 中的 ValueError : shapes (1, 2) 和 (4,4) 未对齐 : 2 (dim 1) ! = 4 (dim 0)

python - 在使用 kmeans 创建集群时,有没有办法输出每行的失真?

python - Python 中迭代列表的行为如何?

python - 打印在 python 中具有最低值的字典中的键的名称

python - 在没有命令行访问权限的 Linux 托管服务提供商上安装 CherryPy

python - 如何使用Python的替换模式

python - np.argsort() 排名紧密

python - scitkit-learn.ensemble.GradientBoostingRegressor 的均方根对数平方误差问题