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

Skip to content

MAINT Parameter validation for metrics.cluster._supervised #26258

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
merged 4 commits into from
Apr 25, 2023
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
27 changes: 23 additions & 4 deletions sklearn/metrics/cluster/_supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ def homogeneity_completeness_v_measure(labels_true, labels_pred, *, beta=1.0):

Parameters
----------
labels_true : int array, shape = [n_samples]
labels_true : array-like of shape (n_samples,)
Ground truth class labels to be used as a reference.

labels_pred : array-like of shape (n_samples,)
Expand Down Expand Up @@ -532,6 +532,12 @@ def homogeneity_completeness_v_measure(labels_true, labels_pred, *, beta=1.0):
return homogeneity, completeness, v_measure_score


@validate_params(
{
"labels_true": ["array-like"],
"labels_pred": ["array-like"],
}
)
def homogeneity_score(labels_true, labels_pred):
"""Homogeneity metric of a cluster labeling given a ground truth.

Expand All @@ -550,7 +556,7 @@ def homogeneity_score(labels_true, labels_pred):

Parameters
----------
labels_true : int array, shape = [n_samples]
labels_true : array-like of shape (n_samples,)
Ground truth class labels to be used as a reference.

labels_pred : array-like of shape (n_samples,)
Expand Down Expand Up @@ -601,6 +607,12 @@ def homogeneity_score(labels_true, labels_pred):
return homogeneity_completeness_v_measure(labels_true, labels_pred)[0]


@validate_params(
{
"labels_true": ["array-like"],
"labels_pred": ["array-like"],
}
)
def completeness_score(labels_true, labels_pred):
"""Compute completeness metric of a cluster labeling given a ground truth.

Expand All @@ -619,7 +631,7 @@ def completeness_score(labels_true, labels_pred):

Parameters
----------
labels_true : int array, shape = [n_samples]
labels_true : array-like of shape (n_samples,)
Ground truth class labels to be used as a reference.

labels_pred : array-like of shape (n_samples,)
Expand Down Expand Up @@ -670,6 +682,13 @@ def completeness_score(labels_true, labels_pred):
return homogeneity_completeness_v_measure(labels_true, labels_pred)[1]


@validate_params(
{
"labels_true": ["array-like"],
"labels_pred": ["array-like"],
"beta": [Interval(Real, 0, None, closed="left")],
}
)
def v_measure_score(labels_true, labels_pred, *, beta=1.0):
"""V-measure cluster labeling given a ground truth.

Expand All @@ -694,7 +713,7 @@ def v_measure_score(labels_true, labels_pred, *, beta=1.0):

Parameters
----------
labels_true : int array, shape = [n_samples]
labels_true : array-like of shape (n_samples,)
Ground truth class labels to be used as a reference.

labels_pred : array-like of shape (n_samples,)
Expand Down
3 changes: 3 additions & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def _check_function_param_validation(
"sklearn.metrics.balanced_accuracy_score",
"sklearn.metrics.brier_score_loss",
"sklearn.metrics.calinski_harabasz_score",
"sklearn.metrics.completeness_score",
"sklearn.metrics.class_likelihood_ratios",
"sklearn.metrics.classification_report",
"sklearn.metrics.cluster.adjusted_mutual_info_score",
Expand All @@ -205,6 +206,7 @@ def _check_function_param_validation(
"sklearn.metrics.get_scorer",
"sklearn.metrics.hamming_loss",
"sklearn.metrics.hinge_loss",
"sklearn.metrics.homogeneity_score",
"sklearn.metrics.jaccard_score",
"sklearn.metrics.label_ranking_average_precision_score",
"sklearn.metrics.label_ranking_loss",
Expand Down Expand Up @@ -248,6 +250,7 @@ def _check_function_param_validation(
"sklearn.metrics.roc_auc_score",
"sklearn.metrics.roc_curve",
"sklearn.metrics.top_k_accuracy_score",
"sklearn.metrics.v_measure_score",
"sklearn.metrics.zero_one_loss",
"sklearn.model_selection.cross_validate",
"sklearn.model_selection.permutation_test_score",
Expand Down