本文簡要介紹 python 語言中 scipy.cluster.hierarchy.complete
的用法。
用法:
scipy.cluster.hierarchy.complete(y)#
在壓縮距離矩陣上執行完整/最大/最遠點鏈接。
- y: ndarray
距離矩陣的上三角。
pdist
的結果以這種形式返回。
- Z: ndarray
包含層次聚類的鏈接矩陣。有關其結構的更多信息,請參閱
linkage
函數文檔。
參數 ::
返回 ::
例子:
>>> from scipy.cluster.hierarchy import complete, fcluster >>> from scipy.spatial.distance import pdist
首先,我們需要一個玩具數據集來玩:
x x x x x x x x x x x x
>>> 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]]
然後,我們從這個數據集中得到一個壓縮的距離矩陣:
>>> y = pdist(X)
最後,我們可以執行聚類:
>>> Z = complete(y) >>> Z array([[ 0. , 1. , 1. , 2. ], [ 3. , 4. , 1. , 2. ], [ 6. , 7. , 1. , 2. ], [ 9. , 10. , 1. , 2. ], [ 2. , 12. , 1.41421356, 3. ], [ 5. , 13. , 1.41421356, 3. ], [ 8. , 14. , 1.41421356, 3. ], [11. , 15. , 1.41421356, 3. ], [16. , 17. , 4.12310563, 6. ], [18. , 19. , 4.12310563, 6. ], [20. , 21. , 5.65685425, 12. ]])
鏈接矩陣
Z
表示樹狀圖 - 有關其內容的詳細說明,請參閱scipy.cluster.hierarchy.linkage
。我們可以使用
scipy.cluster.hierarchy.fcluster
來查看給定距離閾值的每個初始點屬於哪個集群:>>> fcluster(Z, 0.9, criterion='distance') array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], dtype=int32) >>> fcluster(Z, 1.5, criterion='distance') array([1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4], dtype=int32) >>> fcluster(Z, 4.5, criterion='distance') array([1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2], dtype=int32) >>> fcluster(Z, 6, criterion='distance') array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=int32)
此外,
scipy.cluster.hierarchy.dendrogram
可用於生成樹狀圖。
相關用法
- Python SciPy hierarchy.correspond用法及代碼示例
- Python SciPy hierarchy.cophenet用法及代碼示例
- Python SciPy hierarchy.cut_tree用法及代碼示例
- Python SciPy hierarchy.centroid用法及代碼示例
- 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.is_isomorphic用法及代碼示例
- Python SciPy hierarchy.optimal_leaf_ordering用法及代碼示例
- Python SciPy hierarchy.maxinconsts用法及代碼示例
- 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.linkage用法及代碼示例
- Python SciPy hierarchy.maxdists用法及代碼示例
- Python SciPy hierarchy.is_valid_im用法及代碼示例
- Python SciPy hierarchy.single用法及代碼示例
- Python SciPy hierarchy.is_monotonic用法及代碼示例
- Python SciPy hierarchy.leaves_list用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.cluster.hierarchy.complete。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。