Skip to content

MAINT Deprecate matching as metric #26264

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

Merged
2 changes: 1 addition & 1 deletion doc/modules/neighbors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
5 changes: 5 additions & 0 deletions doc/whats_new/v1.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ Changelog
`tpr=0` and `fpr=0`.
:pr:`26194` by :user:`Guillaume Lemaitre <glemaitre>`.

- |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 <magnusbarata>`

:mod:`sklearn.model_selection`
..............................

Expand Down
4 changes: 3 additions & 1 deletion sklearn/metrics/_dist_metrics.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ def newObj(obj):

BOOL_METRICS = [
"hamming",
"matching",
"jaccard",
"dice",
"rogerstanimoto",
Expand All @@ -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,
Expand Down
17 changes: 15 additions & 2 deletions sklearn/metrics/pairwise.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.

Expand Down Expand Up @@ -1750,7 +1756,6 @@ def _pairwise_callable(X, Y, metric, force_all_finite=True, **kwds):
"hamming",
"jaccard",
"mahalanobis",
"matching",
"minkowski",
"rogerstanimoto",
"russellrao",
Expand All @@ -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"]

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2158,7 +2169,6 @@ def pairwise_distances(
PAIRWISE_BOOLEAN_FUNCTIONS = [
"dice",
"jaccard",
"matching",
"rogerstanimoto",
"russellrao",
"sokalmichener",
Expand All @@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions sklearn/neighbors/_ball_tree.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down
4 changes: 3 additions & 1 deletion sklearn/neighbors/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
"hamming",
"jaccard",
"mahalanobis",
"matching",
"minkowski",
"rogerstanimoto",
"russellrao",
Expand All @@ -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,
Expand Down
1 change: 0 additions & 1 deletion sklearn/neighbors/tests/test_ball_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
DISCRETE_METRICS = ["hamming", "canberra", "braycurtis"]

BOOLEAN_METRICS = [
"matching",
"jaccard",
"dice",
"rogerstanimoto",
Expand Down