NearestNeighbors doesn't work with algorithm="auto" when using mahalanobis distance
See original GitHub issueWhen I use NearestNeighbors with mahalanobis distance, I find setting algorithm=‘auto’ (which defaults to ‘ball_tree’) doesn’t seem to work. This throw an error: ValueError: Mahalanobis dist: size of V does not match
import numpy as np
from sklearn.datasets import make_classification
from sklearn.neighbors import DistanceMetric
X, y = make_classification()
nn = NearestNeighbors(algorithm='auto',
metric='mahalanobis',
metric_params={'V': np.cov(X)})
nn.fit(X)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to use mahalanobis distance in sklearn DistanceMetrics?
how do you use the distance metric, in, say nearest neighbors or clustering? When I try to use it, I get ValueError: Metric...
Read more >Nearest Neighbor- Including Mahalanobis Distance
We were discussing various distance algorithms for a nearest neighbor algorithm. Our prof discussed one called the Mahalanobis distance.
Read more >K-Nearest Neighbors: Part 1 Introduction | by Walid Hadri
The Mahalanobis distance measures distance relative to the centroid — a base or central point which can be thought of as an overall...
Read more >Python – How to use mahalanobis distance in sklearn ... - iTecNote
Is there an example of using the Mahalanobis distance that I can see? ... setting algorithm='auto' (which defaults to 'ball_tree' ) doesn't seem...
Read more >Guide to the K-Nearest Neighbors Algorithm in Python and ...
Note: The distance can be measured in different ways. You can use a Minkowski, Euclidean, Manhattan, Mahalanobis or Hamming formula, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I suspect it wants covariance between the features, not the samples. I.e. use rowvar=False
Thank you @cmarmo for following up on this issue. From https://github.com/scikit-learn/scikit-learn/issues/11807#issuecomment-1302822458, I agree this issue can be closed.