本文簡要介紹 python 語言中 scipy.cluster.hierarchy.from_mlab_linkage
的用法。
用法:
scipy.cluster.hierarchy.from_mlab_linkage(Z)#
將 MATLAB(TM) 生成的鏈接矩陣轉換為與該模塊兼容的新鏈接矩陣。
轉換做了兩件事:
the indices are converted from
1..N
to0..(N-1)
form, anda fourth column
Z[:,3]
is added whereZ[i,3]
represents the number of original observations (leaves) in the non-singleton clusteri
.
當從 MATLAB 生成的舊數據文件加載鏈接時,此函數很有用。
- Z: ndarray
由 MATLAB(TM) 生成的鏈接矩陣。
- ZS: ndarray
與
scipy.cluster.hierarchy
兼容的鏈接矩陣。
參數 ::
返回 ::
例子:
>>> import numpy as np >>> from scipy.cluster.hierarchy import ward, from_mlab_linkage
給定 MATLAB 格式
mZ
的鏈接矩陣,我們可以使用scipy.cluster.hierarchy.from_mlab_linkage
將其導入為 SciPy 格式:>>> mZ = np.array([[1, 2, 1], [4, 5, 1], [7, 8, 1], ... [10, 11, 1], [3, 13, 1.29099445], ... [6, 14, 1.29099445], ... [9, 15, 1.29099445], ... [12, 16, 1.29099445], ... [17, 18, 5.77350269], ... [19, 20, 5.77350269], ... [21, 22, 8.16496581]])
>>> Z = from_mlab_linkage(mZ) >>> 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. ]])
正如預期的那樣,返回的鏈接矩陣
Z
包括一個額外的列,用於計算每個集群中原始樣本的數量。此外,所有集群索引都減 1(MATLAB 格式使用 1 索引,而 SciPy 使用 0 索引)。
相關用法
- Python SciPy hierarchy.fclusterdata用法及代碼示例
- Python SciPy hierarchy.fcluster用法及代碼示例
- Python SciPy hierarchy.ward用法及代碼示例
- Python SciPy hierarchy.maxRstat用法及代碼示例
- Python SciPy hierarchy.set_link_color_palette用法及代碼示例
- 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.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.linkage用法及代碼示例
- Python SciPy hierarchy.maxdists用法及代碼示例
- Python SciPy hierarchy.is_valid_im用法及代碼示例
- Python SciPy hierarchy.centroid用法及代碼示例
- Python SciPy hierarchy.single用法及代碼示例
- Python SciPy hierarchy.is_monotonic用法及代碼示例
- Python SciPy hierarchy.cophenet用法及代碼示例
注:本文由純淨天空篩選整理自scipy.org大神的英文原創作品 scipy.cluster.hierarchy.from_mlab_linkage。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。