【发布时间】:2018-04-18 03:59:46
【问题描述】:
我对 pandas 很陌生,对 scipy 聚类完全陌生。我有一个使用 pd.read_csv 读取的熊猫数据框,它是一个看起来像这样的矩阵(值表示彼此之间的距离:
dog cat squ mea che
dog 0 .6 .5 .3 .2
cat 1 0 .3 .7 .9
squ .6 .3 0 .3 .8
mea .1 .1 .3 0 .9
che .4 .3 .4 .7 0
我想使用 scipy 对我的矩阵进行聚类,以最终创建一个具有层次/凝聚聚类的树状图,我尝试了
from scipy.cluster.hierarchy import dendrogram, linkage
from matplotlib import pyplot as plt
Z = linkage(df)
但我立即遇到此值错误,不知道如何继续
ValueError: could not convert string to float: "'dog'"
我知道我没有正确地对这些矩阵进行聚类,但不确定如何继续。
【问题讨论】:
标签: python pandas matrix scipy cluster-computing