我正在尝试使用分层聚类对nxm数据集进行聚类,并显示树形图和热图。
基于在线示例,以下代码根据dat中的数据集生成我的链接图(Y1):
import scipy.cluster.hierarchy as sch
import scipy.spatial.distance as ssd
d1 = ssd.pdist(dat)
D1 = ssd.squareform(d1) # full matrix
Y1 = sch.linkage(D1, method=method, metric=metric)
然后我使用Y1重新排序我的热图,这有效。
然后我使用
生成树状图sch.dendrogram(Y1, orientation='top', color_threshold=0.0)
然而,现在,我现在想要翻转"一个给定的节点(这样就保留了链接,但是簇的顺序是相反的)。在下面的示例中,我将翻转节点x。
|
|----x---|
| |
| |-----|
|-----| | |
a b c d
应该成为
|
|----x---|
| |
|-----| |
| | |-----|
c d a b
dendgrogram方法有一个按距离排序的选项,但这不允许任意节点翻转。
我似乎无法找到任何人这样做的例子 - 我们将非常感谢任何建议。
谢谢!