本文簡要介紹 python 語言中 scipy.cluster.hierarchy.is_valid_linkage
的用法。
用法:
scipy.cluster.hierarchy.is_valid_linkage(Z, warning=False, throw=False, name=None)#
檢查鏈接矩陣的有效性。
如果鏈接矩陣是具有
i
,必須滿足以下兩個表達式: 行和 4 列的二維數組(雙精度類型),則它是有效的。前兩列必須包含 0 和 之間的索引。對於給定的行即,除非已生成要加入的集群,否則集群無法加入另一個集群。
- Z: array_like
聯動矩陣。
- warning: 布爾型,可選
當為 True 時,如果傳遞的鏈接矩陣無效,則發出 Python 警告。
- throw: 布爾型,可選
為 True 時,如果傳遞的鏈接矩陣無效,則引發 Python 異常。
- name: str,可選
該字符串引用無效鏈接矩陣的變量名。
- b: bool
如果不一致矩陣有效,則為真。
參數 ::
返回 ::
例子:
>>> from scipy.cluster.hierarchy import ward, is_valid_linkage >>> from scipy.spatial.distance import pdist
此模塊中的聚類方法生成的所有鏈接矩陣都是有效的(即,它們將具有適當的維度,並且兩個必需的表達式將適用於所有行)。
我們可以使用
scipy.cluster.hierarchy.is_valid_linkage
檢查這一點:>>> 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. ]]) >>> is_valid_linkage(Z) True
然而,如果我們以錯誤的方式創建了一個鏈接矩陣——或者如果我們修改了一個有效的矩陣,使得任何所需的表達式不再成立,那麽檢查將失敗:
>>> Z[3][1] = 20 # the cluster number 20 is not defined at this point >>> is_valid_linkage(Z) False
相關用法
- Python SciPy hierarchy.is_valid_im用法及代碼示例
- Python SciPy hierarchy.is_isomorphic用法及代碼示例
- Python SciPy hierarchy.is_monotonic用法及代碼示例
- Python SciPy hierarchy.inconsistent用法及代碼示例
- 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.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.complete用法及代碼示例
- Python SciPy hierarchy.linkage用法及代碼示例
- Python SciPy hierarchy.maxdists用法及代碼示例
- Python SciPy hierarchy.centroid用法及代碼示例
- Python SciPy hierarchy.single用法及代碼示例
- Python SciPy hierarchy.cophenet用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.cluster.hierarchy.is_valid_linkage。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。