Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats_new/upcoming_changes/sklearn.metrics/28981.api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- The `sparse` parameter of :func:`metrics.fowlkes_mallows_score` is deprecated and
will be removed in 1.9. It has no effect.
By :user:`Luc Rocher <cynddl>`.
18 changes: 15 additions & 3 deletions sklearn/metrics/cluster/_supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from scipy import sparse as sp

from ...utils._array_api import _max_precision_float_dtype, get_namespace_and_device
from ...utils._param_validation import Interval, StrOptions, validate_params
from ...utils._param_validation import Hidden, Interval, StrOptions, validate_params
from ...utils.multiclass import type_of_target
from ...utils.validation import check_array, check_consistent_length
from ._expected_mutual_info_fast import expected_mutual_information
Expand Down Expand Up @@ -1178,11 +1178,11 @@ def normalized_mutual_info_score(
{
"labels_true": ["array-like"],
"labels_pred": ["array-like"],
"sparse": ["boolean"],
"sparse": ["boolean", Hidden(StrOptions({"deprecated"}))],
},
prefer_skip_nested_validation=True,
)
def fowlkes_mallows_score(labels_true, labels_pred, *, sparse=False):
def fowlkes_mallows_score(labels_true, labels_pred, *, sparse="deprecated"):
"""Measure the similarity of two clusterings of a set of points.

.. versionadded:: 0.18
Expand Down Expand Up @@ -1216,6 +1216,10 @@ def fowlkes_mallows_score(labels_true, labels_pred, *, sparse=False):
sparse : bool, default=False
Compute contingency matrix internally with sparse matrix.

.. deprecated:: 1.7
The ``sparse`` parameter is deprecated and will be removed in 1.9. It has
no effect.

Returns
-------
score : float
Expand Down Expand Up @@ -1249,6 +1253,14 @@ def fowlkes_mallows_score(labels_true, labels_pred, *, sparse=False):
>>> fowlkes_mallows_score([0, 0, 0, 0], [0, 1, 2, 3])
0.0
"""
# TODO(1.9): remove the sparse parameter
if sparse != "deprecated":
warnings.warn(
"The 'sparse' parameter was deprecated in 1.7 and will be removed in 1.9. "
"It has no effect. Leave it to its default value to silence this warning.",
FutureWarning,
)

labels_true, labels_pred = check_clusterings(labels_true, labels_pred)
(n_samples,) = labels_true.shape

Expand Down
10 changes: 10 additions & 0 deletions sklearn/metrics/cluster/tests/test_supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,3 +510,13 @@ def test_normalized_mutual_info_score_bounded(average_method):
# non constant, non perfect matching labels
nmi = normalized_mutual_info_score(labels2, labels3, average_method=average_method)
assert 0 <= nmi < 1


# TODO(1.9): remove
@pytest.mark.parametrize("sparse", [True, False])
def test_fowlkes_mallows_sparse_deprecated(sparse):
"""Check deprecation warning for 'sparse' parameter of fowlkes_mallows_score."""
with pytest.warns(
FutureWarning, match="The 'sparse' parameter was deprecated in 1.7"
):
fowlkes_mallows_score([0, 1], [1, 1], sparse=sparse)