diff --git a/doc/modules/neighbors.rst b/doc/modules/neighbors.rst index 7112c2a697651..ba8ff5747025f 100644 --- a/doc/modules/neighbors.rst +++ b/doc/modules/neighbors.rst @@ -142,7 +142,7 @@ of valid metrics use :meth:`KDTree.valid_metrics` and :meth:`BallTree.valid_metr >>> 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', 'rogerstanimoto', 'russellrao', 'sokalmichener', 'sokalsneath', 'haversine', 'pyfunc'] + ['euclidean', 'l2', 'minkowski', 'p', 'manhattan', 'cityblock', 'l1', 'chebyshev', 'infinity', 'seuclidean', 'mahalanobis', 'wminkowski', 'hamming', 'canberra', 'braycurtis', 'jaccard', 'dice', 'rogerstanimoto', 'russellrao', 'sokalmichener', 'sokalsneath', 'haversine', 'pyfunc'] .. _classification: diff --git a/doc/whats_new/v1.3.rst b/doc/whats_new/v1.3.rst index b319d5096ca8c..a4cc3fa690474 100644 --- a/doc/whats_new/v1.3.rst +++ b/doc/whats_new/v1.3.rst @@ -428,6 +428,11 @@ Changelog `tpr=0` and `fpr=0`. :pr:`26194` by :user:`Guillaume Lemaitre `. +- |Fix| The `'matching'` metric has been removed when using SciPy>=1.9 + to be consistent with `scipy.spatial.distance` which does not support + `'matching'` anymore. + :pr:`26264` by :user:`Barata T. Onggo ` + :mod:`sklearn.model_selection` .............................. diff --git a/sklearn/metrics/_dist_metrics.pyx.tp b/sklearn/metrics/_dist_metrics.pyx.tp index ed09552ed5914..2dde3e8d9343c 100644 --- a/sklearn/metrics/_dist_metrics.pyx.tp +++ b/sklearn/metrics/_dist_metrics.pyx.tp @@ -50,7 +50,6 @@ def newObj(obj): BOOL_METRICS = [ "hamming", - "matching", "jaccard", "dice", "rogerstanimoto", @@ -61,6 +60,9 @@ BOOL_METRICS = [ if sp_base_version < parse_version("1.11"): # Deprecated in SciPy 1.9 and removed in SciPy 1.11 BOOL_METRICS += ["kulsinski"] +if sp_base_version < parse_version("1.9"): + # Deprecated in SciPy 1.0 and removed in SciPy 1.9 + BOOL_METRICS += ["matching"] def get_valid_metric_ids(L): """Given an iterable of metric class names or class identifiers, diff --git a/sklearn/metrics/pairwise.py b/sklearn/metrics/pairwise.py index 0605c99c9536d..b59d733f81723 100644 --- a/sklearn/metrics/pairwise.py +++ b/sklearn/metrics/pairwise.py @@ -663,6 +663,9 @@ def pairwise_distances_argmin_min( .. note:: `'kulsinski'` is deprecated from SciPy 1.9 and will be removed in SciPy 1.11. + .. note:: + `'matching'` has been removed in SciPy 1.9 (use `'hamming'` instead). + metric_kwargs : dict, default=None Keyword arguments to pass to specified metric function. @@ -783,6 +786,9 @@ def pairwise_distances_argmin(X, Y, *, axis=1, metric="euclidean", metric_kwargs .. note:: `'kulsinski'` is deprecated from SciPy 1.9 and will be removed in SciPy 1.11. + .. note:: + `'matching'` has been removed in SciPy 1.9 (use `'hamming'` instead). + metric_kwargs : dict, default=None Keyword arguments to pass to specified metric function. @@ -1750,7 +1756,6 @@ def _pairwise_callable(X, Y, metric, force_all_finite=True, **kwds): "hamming", "jaccard", "mahalanobis", - "matching", "minkowski", "rogerstanimoto", "russellrao", @@ -1766,6 +1771,9 @@ def _pairwise_callable(X, Y, metric, force_all_finite=True, **kwds): if sp_base_version < parse_version("1.11"): # Deprecated in SciPy 1.9 and removed in SciPy 1.11 _VALID_METRICS += ["kulsinski"] +if sp_base_version < parse_version("1.9"): + # Deprecated in SciPy 1.0 and removed in SciPy 1.9 + _VALID_METRICS += ["matching"] _NAN_METRICS = ["nan_euclidean"] @@ -2023,6 +2031,9 @@ def pairwise_distances( .. note:: `'kulsinski'` is deprecated from SciPy 1.9 and will be removed in SciPy 1.11. + .. note:: + `'matching'` has been removed in SciPy 1.9 (use `'hamming'` instead). + Note that in the case of 'cityblock', 'cosine' and 'euclidean' (which are valid scipy.spatial.distance metrics), the scikit-learn implementation will be used, which is faster and has support for sparse matrices (except @@ -2158,7 +2169,6 @@ def pairwise_distances( PAIRWISE_BOOLEAN_FUNCTIONS = [ "dice", "jaccard", - "matching", "rogerstanimoto", "russellrao", "sokalmichener", @@ -2168,6 +2178,9 @@ def pairwise_distances( if sp_base_version < parse_version("1.11"): # Deprecated in SciPy 1.9 and removed in SciPy 1.11 PAIRWISE_BOOLEAN_FUNCTIONS += ["kulsinski"] +if sp_base_version < parse_version("1.9"): + # Deprecated in SciPy 1.0 and removed in SciPy 1.9 + PAIRWISE_BOOLEAN_FUNCTIONS += ["matching"] # Helper functions - distance PAIRWISE_KERNEL_FUNCTIONS = { diff --git a/sklearn/neighbors/_ball_tree.pyx b/sklearn/neighbors/_ball_tree.pyx index ef7033709d410..cf02bd37c5829 100644 --- a/sklearn/neighbors/_ball_tree.pyx +++ b/sklearn/neighbors/_ball_tree.pyx @@ -10,8 +10,7 @@ VALID_METRICS = ['EuclideanDistance', 'SEuclideanDistance', 'MinkowskiDistance', 'WMinkowskiDistance', 'MahalanobisDistance', 'HammingDistance', 'CanberraDistance', 'BrayCurtisDistance', - 'JaccardDistance', 'MatchingDistance', - 'DiceDistance', + 'JaccardDistance', 'DiceDistance', 'RogersTanimotoDistance', 'RussellRaoDistance', 'SokalMichenerDistance', 'SokalSneathDistance', 'PyFuncDistance', 'HaversineDistance'] diff --git a/sklearn/neighbors/_base.py b/sklearn/neighbors/_base.py index 9af85a38f0b6c..96c78da02059f 100644 --- a/sklearn/neighbors/_base.py +++ b/sklearn/neighbors/_base.py @@ -51,7 +51,6 @@ "hamming", "jaccard", "mahalanobis", - "matching", "minkowski", "rogerstanimoto", "russellrao", @@ -64,6 +63,9 @@ if sp_base_version < parse_version("1.11"): # Deprecated in SciPy 1.9 and removed in SciPy 1.11 SCIPY_METRICS += ["kulsinski"] +if sp_base_version < parse_version("1.9"): + # Deprecated in SciPy 1.0 and removed in SciPy 1.9 + SCIPY_METRICS += ["matching"] VALID_METRICS = dict( ball_tree=BallTree._valid_metrics, diff --git a/sklearn/neighbors/tests/test_ball_tree.py b/sklearn/neighbors/tests/test_ball_tree.py index 8d665f799e9d8..8fc1e58a0f40f 100644 --- a/sklearn/neighbors/tests/test_ball_tree.py +++ b/sklearn/neighbors/tests/test_ball_tree.py @@ -27,7 +27,6 @@ DISCRETE_METRICS = ["hamming", "canberra", "braycurtis"] BOOLEAN_METRICS = [ - "matching", "jaccard", "dice", "rogerstanimoto",