【发布时间】:2014-07-14 09:26:58
【问题描述】:
我使用以下 python 脚本进行层次聚类并打印树状图。请考虑我是数据挖掘的新手。
import numpy as np
import distance
import scipy.cluster.hierarchy
import matplotlib.pyplot as plt
from scipy.cluster.hierarchy import dendrogram, linkage
mat = np.array([[ 0. , 1. , 3. ,0. ,2. ,3. ,1.],
[ 1. , 0. , 3. , 1., 1. , 2. , 2.],
[ 3., 3. , 0., 3. , 3., 3. , 4.],
[ 0. , 1. , 3., 0. , 2. , 3., 1.],
[ 2. , 1., 3. , 2., 0. , 1., 3.],
[ 3. , 2., 3. , 3. , 1. , 0. , 3.],
[ 1. , 2., 4. , 1. , 3., 3. , 0.]])
linkage_matrix = linkage(mat, "single")
dendrogram(linkage_matrix,
color_threshold=1,
truncate_mode='lastp',
distance_sort='ascending')
plt.show()
以下是我得到的树状图。我需要打印集群和属于每个集群的数据吗?
cluster1 4,5
cluster2 ..,..
cluster3 ..,..
【问题讨论】:
标签: python cluster-analysis hierarchical-clustering dendrogram