python - 指定凝聚聚类中的最大距离(scikit 学习)

标签 python algorithm scikit-learn hierarchical-clustering

使用聚类算法时,您始终必须指定关闭参数。

我目前正在将凝聚聚类与 scikit learn 结合使用,我能看到的唯一关闭参数是聚类数。

agg_clust = AgglomerativeClustering(n_clusters=N)
y_pred = agg_clust.fit_predict(matrix)

但我想找到一种算法,您可以在其中指定集群元素内的最大距离,而不是集群的数量。 因此,该算法将简单地聚集集群,直到达到最大距离。

有什么建议吗?

最佳答案

你正在寻找的是在 scipy.cluster.hierarchy 中实现的,参见 here .

那么你可以这样做:

from scipy.cluster.hierarchy import linkage, fcluster
y_pred = fcluster(linkage(matrix), t, criterion='distance')  

# or more direct way
from scipy.cluster.hierarchy import fclusterdata
y_pred = fclusterdata(matrix, t, criterion='distance')

关于python - 指定凝聚聚类中的最大距离(scikit 学习),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41824968/

相关文章:

python - 如何迭代字典列表并合并字典以形成新的较短的字典列表?

algorithm - 友情关系追踪算法

c++ - 如何比较c++列表中的两个连续元素

python - 对同一数据框中的分类和连续特征使用带有 fill_value 的 reindex

python - 导入错误 : cannot import name RemovedInDjango19Warning

python - 连续 True 区间的开始和结束索引

algorithm - 如何在多个服务器之间复制一个大文件?

python - 使用 scikit learn 检索错误分类的文档

python - 为什么我在使用 SVM Predict() 函数时出现错误?

Python 应用程序和 Python 解释器?