diff --git a/sklearn/datasets/_california_housing.py b/sklearn/datasets/_california_housing.py index f3f7d0e57c502..98e3bfcb37a98 100644 --- a/sklearn/datasets/_california_housing.py +++ b/sklearn/datasets/_california_housing.py @@ -37,6 +37,7 @@ from ._base import RemoteFileMetadata from ._base import load_descr from ..utils import Bunch +from ..utils._param_validation import validate_params # The original data can be found at: @@ -50,6 +51,14 @@ logger = logging.getLogger(__name__) +@validate_params( + { + "data_home": [str, None], + "download_if_missing": ["boolean"], + "return_X_y": ["boolean"], + "as_frame": ["boolean"], + } +) def fetch_california_housing( *, data_home=None, download_if_missing=True, return_X_y=False, as_frame=False ): diff --git a/sklearn/metrics/_ranking.py b/sklearn/metrics/_ranking.py index ebe477a7e2de7..4ca4aa15257c5 100644 --- a/sklearn/metrics/_ranking.py +++ b/sklearn/metrics/_ranking.py @@ -34,7 +34,7 @@ from ..utils.multiclass import type_of_target from ..utils.extmath import stable_cumsum from ..utils.sparsefuncs import count_nonzero -from ..utils._param_validation import validate_params +from ..utils._param_validation import validate_params, StrOptions from ..exceptions import UndefinedMetricWarning from ..preprocessing import label_binarize from ..utils._encode import _encode, _unique @@ -112,6 +112,15 @@ def auc(x, y): return area +@validate_params( + { + "y_true": ["array-like"], + "y_score": ["array-like"], + "average": [StrOptions({"micro", "samples", "weighted", "macro"}), None], + "pos_label": [Real, str, "boolean"], + "sample_weight": ["array-like", None], + } +) def average_precision_score( y_true, y_score, *, average="macro", pos_label=1, sample_weight=None ): @@ -137,10 +146,10 @@ def average_precision_score( Parameters ---------- - y_true : ndarray of shape (n_samples,) or (n_samples, n_classes) + y_true : array-like of shape (n_samples,) or (n_samples, n_classes) True binary labels or binary label indicators. - y_score : ndarray of shape (n_samples,) or (n_samples, n_classes) + y_score : array-like of shape (n_samples,) or (n_samples, n_classes) Target scores, can either be probability estimates of the positive class, confidence values, or non-thresholded measure of decisions (as returned by :term:`decision_function` on some classifiers). diff --git a/sklearn/tests/test_public_functions.py b/sklearn/tests/test_public_functions.py index f2c19a53731d9..3f07a47fd4d1e 100644 --- a/sklearn/tests/test_public_functions.py +++ b/sklearn/tests/test_public_functions.py @@ -100,6 +100,7 @@ def _check_function_param_validation( "sklearn.cluster.kmeans_plusplus", "sklearn.covariance.empirical_covariance", "sklearn.covariance.shrunk_covariance", + "sklearn.datasets.fetch_california_housing", "sklearn.datasets.make_sparse_coded_signal", "sklearn.decomposition.sparse_encode", "sklearn.feature_extraction.grid_to_graph", @@ -107,6 +108,7 @@ def _check_function_param_validation( "sklearn.feature_extraction.image.extract_patches_2d", "sklearn.metrics.accuracy_score", "sklearn.metrics.auc", + "sklearn.metrics.average_precision_score", "sklearn.metrics.cohen_kappa_score", "sklearn.metrics.confusion_matrix", "sklearn.metrics.det_curve",