8000 Added Parameter Validation for metrics.cluster.adjusted_mutual_info_score() by ZeeshanLone · Pull Request #25898 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Added Parameter Validation for metrics.cluster.adjusted_mutual_info_score() #25898

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 2 commits into from
Mar 21, 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 8000
Diff view
Diff view
16 changes: 11 additions & 5 deletions sklearn/metrics/cluster/_supervised.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from ...utils.multiclass import type_of_target
from ...utils.validation import check_array, check_consistent_length
from ...utils._param_validation import validate_params
from ...utils._param_validation import Interval
from ...utils._param_validation import Interval, StrOptions


def check_clusterings(labels_true, labels_pred):
Expand Down Expand Up @@ -847,6 +847,13 @@ def mutual_info_score(labels_true, labels_pred, *, contingency=None):
return np.clip(mi.sum(), 0.0, None)


@validate_params(
{
"labels_true": ["array-like"],
"labels_pred": ["array-like"],
"average_method": [StrOptions({"arithmetic", "max", "min", "geometric"})],
}
)
def adjusted_mutual_info_score(
labels_true, labels_pred, *, average_method="arithmetic"
):
Expand Down Expand Up @@ -876,17 +883,16 @@ def adjusted_mutual_info_score(

Parameters
----------
labels_true : int array, shape = [n_samples]
labels_true : int array-like of shape (n_samples,)
A clustering of the data into disjoint subsets, called :math:`U` in
the above formula.

labels_pred : int array-like of shape (n_samples,)
A clustering of the data into disjoint subsets, called :math:`V` in
the above formula.

average_method : str, default='arithmetic'
How to compute the normalizer in the denominator. Possible options
are 'min', 'geometric', 'arithmetic', and 'max'.
average_method : {'min', 'geometric', 'arithmetic', 'max'}, default='arithmetic'
How to compute the normalizer in the denominator.

.. versionadded:: 0.20

Expand Down
1 change: 1 addition & 0 deletions sklearn/tests/test_public_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _check_function_param_validation(
"sklearn.metrics.brier_score_loss",
"sklearn.metrics.class_likelihood_ratios",
"sklearn.metrics.classification_report",
"sklearn.metrics.cluster.adjusted_mutual_info_score",
"sklearn.metrics.cluster.contingency_matrix",
"sklearn.metrics.cohen_kappa_score",
"sklearn.metrics.confusion_matrix",
Expand Down
0