10

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

0 回答 0