gpt4 book ai didi

python - 值错误 : Linkage 'Z' uses the same cluster more than once in Python scipy fcluster

转载 作者:行者123 更新时间:2023-11-28 19:11:02 25 4
gpt4 key购买 nike

我收到 ValueError: Linkage 'Z' uses the same cluster more than once. 当我试图在 Python 中使用 scipy.cluster.hierarchy.fcluster 获得平面集群时。这个错误只是偶尔发生,通常只发生在非常大的矩阵上,比如 10000x10000。

import scipy.cluster.hierarchy as sch
Z = sch.linkage(d, method="ward")
# some computation here, returning n (usually between 5-30)
clusters = sch.fcluster(Z, t=n, criterion='maxclust')

为什么会这样?我怎样才能避免它?不幸的是,我无法通过谷歌搜索找到任何有用的信息......

EDIT 尝试获取树状图时也会发生错误。如果使用 method='average' 则不会出现此类错误。

最佳答案

似乎使用了 fastcluster而不是 scipy.cluster.hierarchy 解决了这个问题。此外,fastcluster 实现比scipy 稍微快一些。
有关详细信息,请查看 the paper .

import fastcluster
Z = fastcluster.linkage(d, method="ward")
# some computation here, returning n (usually between 5-30)
clusters = fastcluster.fcluster(Z, t=n, criterion='maxclust')

关于python - 值错误 : Linkage 'Z' uses the same cluster more than once in Python scipy fcluster,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40165477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com