我想使用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.