本文簡要介紹 python 語言中 scipy.cluster.hierarchy.leaders
的用法。
用法:
scipy.cluster.hierarchy.leaders(Z, T)#
返回層次聚類中的根節點。
返回與平麵集群分配向量
T
定義的切割相對應的層次聚類中的根節點。有關T
格式的更多信息,請參見fcluster
函數。對於n-sized平麵簇分配向量
T
中表示的 平麵簇中的每個平麵簇 ,此函數在鏈接樹Z中找到最低的簇節點 ,使得:leaf descendants belong only to flat cluster j (i.e.,
T[p]==j
for all in , where is the set of leaf ids of descendant leaf nodes with cluster node )there does not exist a leaf that is not a descendant with
that also belongs to cluster (i.e.,T[q]!=j
for all not in ). If this condition is violated,T
is not a valid cluster assignment vector, and an exception will be thrown.
- Z: ndarray
層次聚類編碼為矩陣。有關詳細信息,請參閱
linkage
。- T: ndarray
平麵集群分配向量。
- L: ndarray
領導者鏈接節點 id 存儲為 k-element 一維數組,其中
k
是在T
中找到的平麵集群的數量。L[j]=i
是鏈接集群節點id,它是id為M[j]的扁平集群的領導者。如果i < n
,i
對應於原始觀察,否則對應於非單例集群。- M: ndarray
領導者鏈接節點 id 存儲為 k-element 一維數組,其中
k
是在T
中找到的平麵集群的數量。這允許平麵集群 ID 集是任意的k
整數集。例如:如果
L[3]=2
和M[3]=8
,則 id 為 8 的扁平集群的領導者是鏈接節點 2。
參數 ::
返回 ::
例子:
>>> from scipy.cluster.hierarchy import ward, fcluster, leaders >>> from scipy.spatial.distance import pdist
給定一個鏈接矩陣
Z
- 在將聚類方法應用於數據集X
後獲得 - 和一個平麵聚類分配數組T
:>>> 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 array([[ 0. , 1. , 1. , 2. ], [ 3. , 4. , 1. , 2. ], [ 6. , 7. , 1. , 2. ], [ 9. , 10. , 1. , 2. ], [ 2. , 12. , 1.29099445, 3. ], [ 5. , 13. , 1.29099445, 3. ], [ 8. , 14. , 1.29099445, 3. ], [11. , 15. , 1.29099445, 3. ], [16. , 17. , 5.77350269, 6. ], [18. , 19. , 5.77350269, 6. ], [20. , 21. , 8.16496581, 12. ]])
>>> T = fcluster(Z, 3, criterion='distance') >>> T array([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4], dtype=int32)
scipy.cluster.hierarchy.leaders
返回樹狀圖中作為每個平麵簇的領導者的節點的索引:>>> L, M = leaders(Z, T) >>> L array([16, 17, 18, 19], dtype=int32)
(請記住,索引 0-11 指向
X
中的 12 個數據點,而索引 12-22 指向Z
中的 11 行)scipy.cluster.hierarchy.leaders
還返回T
中平坦簇的索引:>>> M array([1, 2, 3, 4], dtype=int32)
相關用法
- Python SciPy hierarchy.leaves_list用法及代碼示例
- Python SciPy hierarchy.linkage用法及代碼示例
- Python SciPy hierarchy.ward用法及代碼示例
- Python SciPy hierarchy.maxRstat用法及代碼示例
- Python SciPy hierarchy.set_link_color_palette用法及代碼示例
- Python SciPy hierarchy.fclusterdata用法及代碼示例
- Python SciPy hierarchy.median用法及代碼示例
- Python SciPy hierarchy.DisjointSet用法及代碼示例
- Python SciPy hierarchy.correspond用法及代碼示例
- Python SciPy hierarchy.is_isomorphic用法及代碼示例
- Python SciPy hierarchy.optimal_leaf_ordering用法及代碼示例
- Python SciPy hierarchy.maxinconsts用法及代碼示例
- Python SciPy hierarchy.cut_tree用法及代碼示例
- Python SciPy hierarchy.fcluster用法及代碼示例
- Python SciPy hierarchy.to_tree用法及代碼示例
- Python SciPy hierarchy.average用法及代碼示例
- Python SciPy hierarchy.dendrogram用法及代碼示例
- Python SciPy hierarchy.num_obs_linkage用法及代碼示例
- Python SciPy hierarchy.inconsistent用法及代碼示例
- Python SciPy hierarchy.complete用法及代碼示例
- Python SciPy hierarchy.maxdists用法及代碼示例
- Python SciPy hierarchy.is_valid_im用法及代碼示例
- Python SciPy hierarchy.centroid用法及代碼示例
- Python SciPy hierarchy.single用法及代碼示例
- Python SciPy hierarchy.is_monotonic用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.cluster.hierarchy.leaders。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。