maxinconsts#
- scipy.cluster.hierarchy.maxinconsts(Z, R)[source]#
Return the maximum inconsistency coefficient for each non-singleton cluster and its children.
- Parameters:
- Zndarray
The hierarchical clustering encoded as a matrix. See
linkage
for more information.- Rndarray
The inconsistency matrix.
- Returns:
- MIndarray
A monotonic
(n-1)
-sized numpy array of doubles.
See also
linkage
for a description of what a linkage matrix is.
inconsistent
for the creation of a inconsistency matrix.
Notes
Array API Standard Support
maxinconsts
has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variableSCIPY_ARRAY_API=1
and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.Library
CPU
GPU
NumPy
✅
n/a
CuPy
n/a
⛔
PyTorch
✅
⛔
JAX
✅
⛔
Dask
⚠️ merges chunks
n/a
See Support for the array API standard for more information.
Examples
>>> from scipy.cluster.hierarchy import median, inconsistent, maxinconsts >>> from scipy.spatial.distance import pdist
Given a data set
X
, we can apply a clustering method to obtain a linkage matrixZ
.scipy.cluster.hierarchy.inconsistent
can be also used to obtain the inconsistency matrixR
associated to this clustering process:>>> 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 = median(pdist(X)) >>> R = inconsistent(Z) >>> Z array([[ 0. , 1. , 1. , 2. ], [ 3. , 4. , 1. , 2. ], [ 9. , 10. , 1. , 2. ], [ 6. , 7. , 1. , 2. ], [ 2. , 12. , 1.11803399, 3. ], [ 5. , 13. , 1.11803399, 3. ], [ 8. , 15. , 1.11803399, 3. ], [11. , 14. , 1.11803399, 3. ], [18. , 19. , 3. , 6. ], [16. , 17. , 3.5 , 6. ], [20. , 21. , 3.25 , 12. ]]) >>> R array([[1. , 0. , 1. , 0. ], [1. , 0. , 1. , 0. ], [1. , 0. , 1. , 0. ], [1. , 0. , 1. , 0. ], [1.05901699, 0.08346263, 2. , 0.70710678], [1.05901699, 0.08346263, 2. , 0.70710678], [1.05901699, 0.08346263, 2. , 0.70710678], [1.05901699, 0.08346263, 2. , 0.70710678], [1.74535599, 1.08655358, 3. , 1.15470054], [1.91202266, 1.37522872, 3. , 1.15470054], [3.25 , 0.25 , 3. , 0. ]])
Here,
scipy.cluster.hierarchy.maxinconsts
can be used to compute the maximum value of the inconsistency statistic (the last column ofR
) for each non-singleton cluster and its children:>>> maxinconsts(Z, R) array([0. , 0. , 0. , 0. , 0.70710678, 0.70710678, 0.70710678, 0.70710678, 1.15470054, 1.15470054, 1.15470054])