Python快速集群模块中的距离度量

时间:2013-09-29 11:32:11

标签: python scipy hierarchical-clustering

我想使用fastcluster模块进行分层聚类。当我的默认(欧几里德)距离度量,它工作正常:

import fastcluster
import scipy.cluster.hierarchy
distance = spatial.distance.pdist(data)
linkage = fastcluster.linkage(distance,method="complete")

但问题是当我想使用“余弦相似度”作为距离度量时:

distance = spatial.distance.pdist(data,'cosine')
linkage = fastcluster.linkage(distance,method="complete")

输出结果为:

Traceback (most recent call last):
  File "C:\djcode\mysite\mysite\scipytest.py", line 52, in <module>
    linkage = fastcluster.linkage(distance,method="complete")
  File "C:\Python33\lib\site-packages\fastcluster.py", line 245, in linkage
    linkage_wrap(N, X, Z, mthidx[method])
FloatingPointError: NaN dissimilarity value.

0 个答案:

没有答案