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/