Selected Reading

SciPy - maxRstat() Method



The SciPy maxRstat() method is used to perform the task of maximum value obtained by a column R for each non-singleton cluster and its children. The R contain various statistical information such as distances, sizes, or other metrics.

This method work upon a hierarchical cluster which create the series of nested cluster and it is commonly as tree structure. The main purpose of this method is to determine the properties and characteristics of a clusters and see how they are merged.

The non-singleton clusters means the collection of data that contain more than one element.

Syntax

Following is the syntax of the SciPy maxRstat() method −

maxRstat(Z, R, i)

Parameters

This method accepts the three parameter −

  • Z: This parameter define the median of given array.
  • R: This parameter measure the inconsistency matrix.
  • i: Here, i can be denoted by integer value which defines the statistics.

Return value

This method returns the n-dimensional array.

Example 1

Following is the basic example that illustrate the usage of SciPy maxRstat() method.

from scipy.cluster.hierarchy import median, inconsistent, maxRstat
from scipy.spatial.distance import pdist
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)
print(R)
maxRstat(Z, R, 0)

Output

The above code produces the following output −

[[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.        ]]
array([1.        , 1.        , 1.        , 1.        , 1.05901699,
       1.05901699, 1.05901699, 1.05901699, 1.74535599, 1.91202266,
       3.25      ])

Example 2

Here, we perform the same line of code but change the integer value from 0 to 1 within the method maxRstat() and get the result of n dimensional array.

from scipy.cluster.hierarchy import median, inconsistent, maxRstat
from scipy.spatial.distance import pdist
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)
print(R)
maxRstat(Z, R, 1)

Output

The above code produces the following output −

array([0.        , 0.        , 0.        , 0.        , 0.08346263,
       0.08346263, 0.08346263, 0.08346263, 1.08655358, 1.37522872,
       1.37522872])

Example 3

This program again follow the same code and put the integer value as 3 within the function maxRstat().

from scipy.cluster.hierarchy import median, inconsistent, maxRstat
from scipy.spatial.distance import pdist
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)
print(R)
maxRstat(Z, R, 3)

Output

The above code produces the following output −

array([0.        , 0.        , 0.        , 0.        , 0.70710678,
       0.70710678, 0.70710678, 0.70710678, 1.15470054, 1.15470054,
       1.15470054])
scipy_reference.htm
Advertisements