scipy.cluster.hierarchy.leaves_list

scipy.cluster.hierarchy.leaves_list(Z)[源代码]

返回叶节点ID列表。

返回对应于从左到右出现在树中的观测矢量索引。Z是链接矩阵。

参数
Zndarray

分层聚类被编码为矩阵。 Z 是一个链接矩阵。看见 linkage 了解更多信息。

退货
leaves_listndarray

叶节点ID列表。

参见

dendrogram

有关树状图结构的信息,请参阅。

示例

>>> from scipy.cluster.hierarchy import ward, dendrogram, leaves_list
>>> from scipy.spatial.distance import pdist
>>> from matplotlib import pyplot as plt
>>> X = [[0, 0], [0, 1], [1, 0],
...      [0, 4], [0, 3], [1, 4],
...      [4, 0], [3, 0], [4, 1],
...      [4, 4], [3, 4], [4, 3]]
>>> Z = ward(pdist(X))

链接矩阵 Z 表示树状图,即对执行的群集的结构进行编码的树。 scipy.cluster.hierarchy.leaves_list 中的索引之间的映射。 X 树状图中的数据集和树叶:

>>> leaves_list(Z)
array([ 2,  0,  1,  5,  3,  4,  8,  6,  7, 11,  9, 10], dtype=int32)
>>> fig = plt.figure(figsize=(25, 10))
>>> dn = dendrogram(Z)
>>> plt.show()
../../_images/scipy-cluster-hierarchy-leaves_list-1.png