-
-
Notifications
You must be signed in to change notification settings - Fork 25.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'cosine' metric computation bug #21939
Comments
That's because the output is cosine distance, which is defined as 1.0 minus the cosine similarity |
Is this documented somewhere? |
Edit Looking at the code, I think it's undocumented. |
then why is |
Looking closely at the code, I was mistaken. I think we have support "cosine" and we currently test for it here:
In this case, we need to update the documentation for @BrandonLiang Are you interested in opening a PR to update the docstring for |
Yes I can make a PR and will request your review |
@thomasjpfan can you point me to the documentation file for https://scikit-learn.org/stable/modules/generated/sklearn.neighbors.DistanceMetric.html#sklearn.neighbors.DistanceMetric (I think it's better to add the documentation here) |
Since For scikit-learn/sklearn/neighbors/_unsupervised.py Lines 44 to 45 in f21f1d7
where we state: "metrics in There will still be the issue where it is unclear that import sklearn.metrics.pairwise as pairwise
pairwise.PAIRWISE_DISTANCE_FUNCTIONS['cosine']
<function sklearn.metrics.pairwise.cosine_distances(X, Y=None)> and see that |
Update documentation per scikit-learn#21939
@thomasjpfan just created #22073, don't have permission to add you as reviewer |
Closing because #22073 resolves this issue. |
Describe the bug
In my unit test for a feature using
sklearn.neighbors.NearestNeighbors
andcosine
as the metric, i have a test to assert that the nearest neighbor of a datapoint itself is itself. So I would expect the return similarity to be 1. However, that's not the case (in fact, it's 0 for high-dimensional features).Steps/Code to Reproduce
Expected Results
I would expect
[[1]]
Actual Results
which is approximately 0
Versions
The text was updated successfully, but these errors were encountered: