We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 53b8fca commit 6e768d6Copy full SHA for 6e768d6
sica/mutualknn.py
@@ -100,9 +100,11 @@ def compute_distance(
100
101
if metric in ["pearson", "spearman", "kendall"]:
102
corr = pd.concat([X, Y], keys=["X", "Y"]).T.corr(method=metric)
103
- return 1 - np.abs((corr.loc["X", "Y"]).values)
+ distance = 1 - np.abs((corr.loc["X", "Y"]).values)
104
else:
105
- return cdist(X, Y, metric=metric)
+ distance = cdist(X, Y, metric=metric)
106
+ # we add a small term to deal with 0 distances
107
+ return np.where(distance == 0, 10 ** (-5), distance)
108
109
def adjacency_matrix(self, weighted: bool) -> Union[np.ndarray, None]:
110
"""Compute the undirected adjacency matrix with the Mutual Nearest Neighbors method (``k`` neighbors)
0 commit comments