Skip to content
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

Shield against breaking changes from scikit-learn 1.3.0 release #598

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

exs-avianello
Copy link

@exs-avianello exs-avianello commented Jul 2, 2023

This PR is a possible fix for #597 - following the approach mentioned in scikit-learn/scikit-learn#26742

It replaces all references to the KDTree and BallTree .valid_metrics attribute (which is not available anymore since scikit-learn==1.3.0) with calls to the new equivalent .valid_metrics() method:

# scikit-learn==1.3.0
>>> from sklearn.neighbors import KDTree, BallTree
>>> KDTree.valid_metrics()
['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev', 'infinity']
>>> BallTree.valid_metrics()
['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev', 'infinity', 'seuclidean', 'mahalanobis', 'hamming', 'canberra', 'braycurtis', 'jaccard', 'dice', 'rogerstanimoto', 'russellrao', 'sokalmichener', 'sokalsneath', 'haversine', 'pyfunc']
# scikit-learn<1.3.0
>>> from sklearn.neighbors import KDTree, BallTree
>>> KDTree.valid_metrics
['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev', 'infinity']
>>> BallTree.valid_metrics
['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev', 'infinity', 'seuclidean', 'mahalanobis', 'wminkowski', 'hamming', 'canberra', 'braycurtis', 'matching', 'jaccard', 'dice', 'kulsinski', 'rogerstanimoto', 'russellrao', 'sokalmichener', 'sokalsneath', 'haversine', 'pyfunc']

As suggested in #597, another completely valid approach would be to hard-code the lists of acceptable metric names instead 🙌

Note that the following metrics are not available anymore in BallTree.valid_metrics(): ['wminkowski', 'matching', 'kulsinski']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant