def calc_mahalanobis(x, y, n_neighbors):
from sklearn.neighbors import DistanceMetric, NearestNeighbors
DistanceMetric.get_metric('mahalanobis', V=np.cov(x))
nn = NearestNeighbors(n_neighbors=n_neighbors,
algorithm='brute',
metric='mahalanobis',
metric_params={'V': np.cov(x)})
return nn.fit(x).kneighbors(y)
评论列表
文章目录