sica.mutualknn.MNN¶
- class sica.mutualknn.MNN(k, metric, X, Y=None)[source]¶
Given two arrays X and Y or a precomputed distance matrix computes the undirected adjacency matrix using the Mutual Nearest Neighbors method.
- Parameters:
- X2D array of shape (n_components_1 , n_features_1), 2D array of shape (n_components_1 , n_components_2)
if metric = “precomputed”.
- Y2D array of shape (n_components_2 , n_features_2), optional
The default is None.
- kint > 0
Parameter for the Mutual Nearest Neighbor method (i.e. number of neighbors that we consider).
- metricstring
Metric for the computation of the adjacency matrix (e.g “pearson” , “spearman” or any metric accepted by
scipy.spatial.distance.cdsit).
- Attributes:
- min_dist_float
minimal non-null distance between two different components.
- max_dist_float
maximal non-null distance between two different components.
Notes
In the case where the distance matrix is not precomputed, we compute the distance between each rows of X and Y.
In the case X and Y are dataframes, we consider only the common columns of X and Y. Otherwise, we assume that the
columns are the same for X and Y.
Methods
adjacency_matrix(weighted)Compute the undirected adjacency matrix with the Mutual Nearest Neighbors method (
kneighbors)compute_distance(X, Y, metric)Compute the distance between each pair of rows of X and Y
- adjacency_matrix(weighted)[source]¶
Compute the undirected adjacency matrix with the Mutual Nearest Neighbors method (
kneighbors)- Parameters:
- weightedbool
- If True each coefficient of the adjacency matrix is weighted by the associated
distance, otherwise the coefficients are 0 or 1.
- If True each coefficient of the adjacency matrix is weighted by the associated
- Returns:
- 2D array of shape (n_components_1 , n_components_2)