我为我的数据集生成了一个树状图,我不高兴某些级别的拆分是如何排序的。因此,我正在寻找一种方法来交换单个分支的两个分支(或叶)。在
如果我们看一下底部的代码和树状图,有两个标签11
和{11
和{
这能做到吗?怎么办?我特别赞成手动干预,因为在这种情况下,最优叶排序算法(按推测是不起作用)。在
import numpy as np
# random data set with two clusters
np.random.seed(65) # for repeatability of this tutorial
a = np.random.multivariate_normal([10, 0], [[3, 1], [1, 4]], size=[10,])
b = np.random.multivariate_normal([0, 20], [[3, 1], [1, 4]], size=[20,])
X = np.concatenate((a, b),)
# create linkage and plot dendrogram
from scipy.cluster.hierarchy import dendrogram, linkage
Z = linkage(X, 'ward')
plt.figure(figsize=(15, 5))
plt.title('Hierarchical Clustering Dendrogram')
plt.xlabel('sample index')
plt.ylabel('distance')
dendrogram(
Z,
leaf_rotation=90., # rotates the x axis labels
leaf_font_size=12., # font size for the x axis labels
)
plt.show()
目前没有回答
相关问题 更多 >
编程相关推荐