在python中打印带有详细信息的聚类结果

在python中打印带有详细信息的聚类结果,python,numpy,scipy,cluster-analysis,hierarchical-clustering,Python,Numpy,Scipy,Cluster Analysis,Hierarchical Clustering,我只是尝试用python(2D数组Numpy)打印集群结果。但是我找不到任何关于打印结果的解决方案 我绘制了树状图,但我需要结果,例如: 第1组: 第2组: 第3组: 我的代码是: from matplotlib import pyplot as plt from scipy.cluster.hierarchy import dendrogram, linkage from scipy.spatial.distance import pdist as dx import scipy.cluste

我只是尝试用python(2D数组Numpy)打印集群结果。但是我找不到任何关于打印结果的解决方案

我绘制了树状图,但我需要结果,例如:

第1组:

第2组:

第3组:

我的代码是:

from matplotlib import pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
from scipy.spatial.distance import pdist as dx
import scipy.cluster.hierarchy as ch
import scipy.spatial.distance as dx
import csv
import numpy as np

if __name__ == "__main__":

from numpy import genfromtxt

df = genfromtxt('Booking.csv', delimiter=',')

tridf=np.triu(df)
overdf=Z = linkage(tridf,'complete','chebychev')
plt.figure(figsize=(25, 10))
plt.title('Dendrogram')
plt.xlabel('Row No')
plt.ylabel('Dist')


dendrogram(
    Z,
     truncate_mode='level',
     show_leaf_counts=True,
     show_contracted=True,
    leaf_rotation=90.,  # rotates the x axis labels
    leaf_font_size=10.,  # font size for the x axis labels
)

plt.show()
plt.savefig('Dendogram.jpg')

with open("outputZ.csv", "wb") as f:
writer = csv.writer(f)
writer.writerows(Z) # I just want to print clustering results to csv file  but it comes meaningless numbers.

如果您在以下位置阅读文档:

您将注意到第一种方法:

fcluster(Z,t[,criteria,depth,R,monocrit])通过链接矩阵Z定义的层次聚类形成扁平聚类


您想要的是扁平群集。

您的问题不清楚。你的“聚类结果”是什么?请用输入示例、预期输出和到目前为止的代码编辑您的问题。对不起,我只是添加了我的代码。