当使用
scipy.spatial.distance.pdist
创建压缩距离矩阵并将其传递给ward
时,我遇到了这个错误:Valid methods when the raw observations are omitted are 'single', 'complete', 'weighted', and 'average' error.
虽然文档中指出linkage()
函数需要一个压缩的距离矩阵,但我该如何解决这个问题?
foo = np.random.randint(3, size=(10,10))
scipy.spatial.distance.pdist(foo)
scipy.cluster.hierarchy.linkage(foo)
bar = scipy.spatial.distance.pdist(foo)
scipy.cluster.hierarchy.linkage(bar, method='ward')
提供:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/dist-packages/scipy /cluster/hierarchy.py", line 627, in linkage
raise ValueError("Valid methods when the raw observations are "
ValueError: Valid methods when the raw observations are omitted are 'single', 'complete', 'weighted', and 'average'.
我搜索了一下,找到了这个链接,表明还有其他人遇到了这个问题,但是我无法找到解决方法来提供数据以使scipy接受。