8000 MAINT Parameters validation for sklearn.metrics.silhouette_score (#26… · scikit-learn/scikit-learn@2175ce5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2175ce5

Browse files
MAINT Parameters validation for sklearn.metrics.silhouette_score (#26054)
Co-authored-by: Jérémie du Boisberranger <34657725+jeremiedbb@users.noreply.github.com>
1 parent f097f43 commit 2175ce5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

sklearn/metrics/cluster/_unsupervised.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# License: BSD 3 clause
77

88

9+
from numbers import Integral
910
import functools
1011

1112
import numpy as np
@@ -15,6 +16,7 @@
1516
from ...utils import check_X_y
1617
from ...utils import _safe_indexing
1718
from ...utils._param_validation import (
19+
Interval,
1820
StrOptions,
1921
validate_params,
2022
)
@@ -42,6 +44,15 @@ def check_number_of_labels(n_labels, n_samples):
4244
)
4345

4446

47+
@validate_params(
48+
{
49+
"X": ["array-like", "sparse matrix"],
50+
"labels": ["array-like"],
51+
"metric": [StrOptions(set(_VALID_METRICS) | {"precomputed"}), callable],
52+
"sample_size": [Interval(Integral, 1, None, closed="left"), None],
53+
"random_state": ["random_state"],
54+
}
55+
)
4556
def silhouette_score(
4657
X, labels, *, metric="euclidean", sample_size=None, random_state=None, **kwds
4758
):
@@ -66,7 +77,7 @@ def silhouette_score(
6677
6778
Parameters
6879
----------
69-
X : array-like of shape (n_samples_a, n_samples_a) if metric == \
80+
X : {array-like, sparse matrix} of shape (n_samples_a, n_samples_a) if metric == \
7081
"precomputed" or (n_samples_a, n_features) otherwise
7182
An array of pairwise distances between samples, or a feature array.
7283

sklearn/tests/test_public_functions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ def _check_function_param_validation(
172172
"sklearn.metrics.cluster.contingency_matrix",
173173
"sklearn.metrics.cluster.normalized_mutual_info_score",
174174
"sklearn.metrics.cluster.silhouette_samples",
175+
"sklearn.metrics.cluster.silhouette_score",
175176
"sklearn.metrics.cohen_kappa_score",
176177
"sklearn.metrics.confusion_matrix",
177178
"sklearn.metrics.coverage_error",

0 commit comments

Comments
 (0)
0