Skip to content

Commit 7cc6032

Browse files
cynddljeremiedbb
andauthored
FIX ‘sparse’ kwarg was not used by fowlkes_mallows_score (scikit-learn#28981)
Co-authored-by: Jérémie du Boisberranger <jeremie@probabl.ai>
1 parent d8095e6 commit 7cc6032

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
- The `sparse` parameter of :func:`metrics.fowlkes_mallows_score` is deprecated and
2+
will be removed in 1.9. It has no effect.
3+
By :user:`Luc Rocher <cynddl>`.

sklearn/metrics/cluster/_supervised.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from scipy import sparse as sp
1616

1717
from ...utils._array_api import _max_precision_float_dtype, get_namespace_and_device
18-
from ...utils._param_validation import Interval, StrOptions, validate_params
18+
from ...utils._param_validation import Hidden, Interval, StrOptions, validate_params
1919
from ...utils.multiclass import type_of_target
2020
from ...utils.validation import check_array, check_consistent_length
2121
from ._expected_mutual_info_fast import expected_mutual_information
@@ -1178,11 +1178,11 @@ def normalized_mutual_info_score(
11781178
{
11791179
"labels_true": ["array-like"],
11801180
"labels_pred": ["array-like"],
1181-
"sparse": ["boolean"],
1181+
"sparse": ["boolean", Hidden(StrOptions({"deprecated"}))],
11821182
},
11831183
prefer_skip_nested_validation=True,
11841184
)
1185-
def fowlkes_mallows_score(labels_true, labels_pred, *, sparse=False):
1185+
def fowlkes_mallows_score(labels_true, labels_pred, *, sparse="deprecated"):
11861186
"""Measure the similarity of two clusterings of a set of points.
11871187
11881188
.. versionadded:: 0.18
@@ -1216,6 +1216,10 @@ def fowlkes_mallows_score(labels_true, labels_pred, *, sparse=False):
12161216
sparse : bool, default=False
12171217
Compute contingency matrix internally with sparse matrix.
12181218
1219+
.. deprecated:: 1.7
1220+
The ``sparse`` parameter is deprecated and will be removed in 1.9. It has
1221+
no effect.
1222+
12191223
Returns
12201224
-------
12211225
score : float
@@ -1249,6 +1253,14 @@ def fowlkes_mallows_score(labels_true, labels_pred, *, sparse=False):
12491253
>>> fowlkes_mallows_score([0, 0, 0, 0], [0, 1, 2, 3])
12501254
0.0
12511255
"""
1256+
# TODO(1.9): remove the sparse parameter
1257+
if sparse != "deprecated":
1258+
warnings.warn(
1259+
"The 'sparse' parameter was deprecated in 1.7 and will be removed in 1.9. "
1260+
"It has no effect. Leave it to its default value to silence this warning.",
1261+
FutureWarning,
1262+
)
1263+
12521264
labels_true, labels_pred = check_clusterings(labels_true, labels_pred)
12531265
(n_samples,) = labels_true.shape
12541266

sklearn/metrics/cluster/tests/test_supervised.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,3 +510,13 @@ def test_normalized_mutual_info_score_bounded(average_method):
510510
# non constant, non perfect matching labels
511511
nmi = normalized_mutual_info_score(labels2, labels3, average_method=average_method)
512512
assert 0 <= nmi < 1
513+
514+
515+
# TODO(1.9): remove
516+
@pytest.mark.parametrize("sparse", [True, False])
517+
def test_fowlkes_mallows_sparse_deprecated(sparse):
518+
"""Check deprecation warning for 'sparse' parameter of fowlkes_mallows_score."""
519+
with pytest.warns(
520+
FutureWarning, match="The 'sparse' parameter was deprecated in 1.7"
521+
):
522+
fowlkes_mallows_score([0, 1], [1, 1], sparse=sparse)

0 commit comments

Comments
 (0)