hdbscan
hdbscan copied to clipboard
Shield against breaking changes from scikit-learn 1.3.0 release
This PR is a possible fix for https://github.com/scikit-learn-contrib/hdbscan/issues/597 - following the approach mentioned in https://github.com/scikit-learn/scikit-learn/issues/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 https://github.com/scikit-learn-contrib/hdbscan/issues/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']