本文簡要介紹 python 語言中 scipy.cluster.hierarchy.is_valid_im
的用法。
用法:
scipy.cluster.hierarchy.is_valid_im(R, warning=False, throw=False, name=None)#
如果傳遞的不一致矩陣有效,則返回 True。
它必須是
R[:,1]
必須為非負數。鏈接計數R[:,2]
必須為正且不大於 。 乘以 4 個雙精度數組。標準差- R: ndarray
用於檢查有效性的不一致矩陣。
- warning: 布爾型,可選
當為 True 時,如果傳遞的鏈接矩陣無效,則發出 Python 警告。
- throw: 布爾型,可選
為 True 時,如果傳遞的鏈接矩陣無效,則引發 Python 異常。
- name: str,可選
該字符串引用無效鏈接矩陣的變量名。
- b: bool
如果不一致矩陣有效,則為真。
參數 ::
返回 ::
例子:
>>> from scipy.cluster.hierarchy import ward, inconsistent, is_valid_im >>> from scipy.spatial.distance import pdist
給定數據集
X
,我們可以應用聚類方法來獲得鏈接矩陣Z
。scipy.cluster.hierarchy.inconsistent
也可用於獲取與此聚類過程相關的不一致矩陣R
:>>> 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)) >>> R = inconsistent(Z) >>> 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. ]]) >>> R array([[1. , 0. , 1. , 0. ], [1. , 0. , 1. , 0. ], [1. , 0. , 1. , 0. ], [1. , 0. , 1. , 0. ], [1.14549722, 0.20576415, 2. , 0.70710678], [1.14549722, 0.20576415, 2. , 0.70710678], [1.14549722, 0.20576415, 2. , 0.70710678], [1.14549722, 0.20576415, 2. , 0.70710678], [2.78516386, 2.58797734, 3. , 1.15470054], [2.78516386, 2.58797734, 3. , 1.15470054], [6.57065706, 1.38071187, 3. , 1.15470054]])
現在我們可以使用
scipy.cluster.hierarchy.is_valid_im
來驗證R
是否正確:>>> is_valid_im(R) True
但是,如果
R
構造錯誤(例如,標準差之一設置為負值),則檢查將失敗:>>> R[-1,1] = R[-1,1] * -1 >>> is_valid_im(R) False
相關用法
- Python SciPy hierarchy.is_valid_linkage用法及代碼示例
- 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_im。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。