SciPy - inconsistent() 方法



SciPy inconsistent() 方法用於對連結矩陣執行不一致性統計計算。我們也可以說,透過提供對不同層次的層次聚類的有用見解。

語法

以下是 SciPy inconsistent() 方法的語法 −

inconsistent(Z)

引數

此函式只接受一個引數 −

  • Z: 此引數確定連結矩陣。

返回值

此方法返回 n 維陣列。

示例 1

以下是 SciPy inconsistent() 方法的基本用法。

from scipy.cluster.hierarchy import linkage, inconsistent
import numpy as np

# given data
inp = np.array([[1, 2], [2, 3], [3, 4], [5, 6], [8, 9]])

# hierarchical clustering
Z = linkage(inp, method = 'single')
# inconsistency statistics
res = inconsistent(Z)
print(res)

輸出

以上程式碼產生以下輸出 -

[[1.41421356 0.         1.         0.        ]
 [1.41421356 0.         2.         0.        ]
 [2.12132034 1.         2.         0.70710678]
 [3.53553391 1.         2.         0.70710678]]

示例 2

此程式執行隨機資料集,顯示使用完全連結方法的層次聚類。此處,我們插入統計資料 (d = 4)。

from scipy.cluster.hierarchy import linkage, inconsistent
import numpy as np

# given data
X = np.random.rand(10, 2)

# hierarchical clustering
Z = linkage(X, method = 'complete')

# inconsistency statistics with depth 3
res = inconsistent(Z, d = 4)
print(res)

輸出

以上程式碼產生以下輸出 -

[[0.11686734 0.         1.         0.        ]
 [0.12320749 0.         1.         0.        ]
 [0.15625215 0.05569854 2.         0.70710678]
 [0.25072888 0.         1.         0.        ]
 [0.24700603 0.12197973 3.         0.98439051]
 [0.2431393  0.15556122 3.         1.1170798 ]
 [0.33971115 0.21046693 4.         1.32142073]
 [0.38888022 0.31795366 4.         1.37511476]
 [0.46547574 0.29610456 8.         1.55631532]]
scipy_reference.htm
廣告
© . All rights reserved.