Selected Reading

SciPy - from_mlab_linkage() Method



The SciPy from_mlab_linkage() method is works upon the clustering algorithm(mlab.linkage) and converts it into a format that can be used for the references of other scipy clustering functions.

Syntax

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

from_mlab_linkage(Z)

Parameters

This method accepts only a single parameter −

  • Z: This parameter store the n-dimensional array and is also known as linkage matrix.

Return value

This method return the converted linkage matrix.

Example

Following is the basic program that illustrate the usage of SciPy from_mlab_linkage() method.

import numpy as np
from scipy.cluster.hierarchy import ward, from_mlab_linkage
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]])
res = from_mlab_linkage(mZ)
print(res)

Output

The above code produces the following output −

[[ 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.        ]]
scipy_reference.htm
Advertisements