{"instance_id": "scikit-learn__scikit-learn-14983", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/model_selection/_split.py b/sklearn/model_selection/_split.py\nindex c49a3ce6ae..ceee1a0814 100644\n--- a/sklearn/model_selection/_split.py\n+++ b/sklearn/model_selection/_split.py\n@@ -1163,6 +1163,9 @@ class _RepeatedSplits(metaclass=ABCMeta):\n                      **self.cvargs)\n         return cv.get_n_splits(X, y, groups) * self.n_repeats\n \n+    def __repr__(self):\n+        return _build_repr(self)\n+\n \n class RepeatedKFold(_RepeatedSplits):\n     \"\"\"Repeated K-Fold cross validator.\n@@ -2158,6 +2161,8 @@ def _build_repr(self):\n         try:\n             with warnings.catch_warnings(record=True) as w:\n                 value = getattr(self, key, None)\n+                if value is None and hasattr(self, 'cvargs'):\n+                    value = self.cvargs.get(key, None)\n             if len(w) and w[0].category == DeprecationWarning:\n                 # if the parameter is deprecated, don't show it\n                 continue\n", "model": "claude-sonnet-5-5", "steps": 12, "finished": true, "patch_lines": 23, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 23, "steps": 12}], "ms": 29994}
{"instance_id": "scikit-learn__scikit-learn-15100", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py\nindex bb5a9d6467..11236d9582 100644\n--- a/sklearn/feature_extraction/text.py\n+++ b/sklearn/feature_extraction/text.py\n@@ -130,10 +130,7 @@ def strip_accents_unicode(s):\n         ASCII equivalent.\n     \"\"\"\n     normalized = unicodedata.normalize('NFKD', s)\n-    if normalized == s:\n-        return s\n-    else:\n-        return ''.join([c for c in normalized if not unicodedata.combining(c)])\n+    return ''.join([c for c in normalized if not unicodedata.combining(c)])\n \n \n def strip_accents_ascii(s):\n", "model": "claude-haiku-5-5", "steps": 20, "finished": true, "patch_lines": 16, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 16, "steps": 20}], "ms": 99827}
{"instance_id": "scikit-learn__scikit-learn-25102", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/feature_selection/_base.py b/sklearn/feature_selection/_base.py\nindex da2185eac3..75dfd55a81 100644\n--- a/sklearn/feature_selection/_base.py\n+++ b/sklearn/feature_selection/_base.py\n@@ -30,6 +30,10 @@ class SelectorMixin(TransformerMixin, metaclass=ABCMeta):\n     `_get_support_mask`.\n     \"\"\"\n \n+    # Selectors do not modify values: keep the dtypes of a DataFrame input\n+    # when the output container is configured as pandas.\n+    _sklearn_preserve_dtypes = True\n+\n     def get_support(self, indices=False):\n         \"\"\"\n         Get a mask, or integer index, of the features selected.\ndiff --git a/sklearn/utils/_set_output.py b/sklearn/utils/_set_output.py\nindex 335773c6af..01acba520a 100644\n--- a/sklearn/utils/_set_output.py\n+++ b/sklearn/utils/_set_output.py\n@@ -12,6 +12,7 @@ def _wrap_in_pandas_container(\n     *,\n     columns,\n     index=None,\n+    dtypes=None,\n ):\n     \"\"\"Create a Pandas DataFrame.\n \n@@ -36,6 +37,10 @@ def _wrap_in_pandas_container(\n     index : array-like, default=None\n         Index for data.\n \n+    dtypes : Series, default=None\n+        Mapping from column name to dtype. If not None, the columns of the\n+        output that are found in `dtypes` are cast to the given dtype.\n+\n     Returns\n     -------\n     dataframe : DataFrame\n@@ -57,9 +62,19 @@ def _wrap_in_pandas_container(\n             data_to_wrap.columns = columns\n         if index is not None:\n             data_to_wrap.index = index\n-        return data_to_wrap\n+        df = data_to_wrap\n+    else:\n+        df = pd.DataFrame(data_to_wrap, index=index, columns=columns)\n \n-    return pd.DataFrame(data_to_wrap, index=index, columns=columns)\n+    if dtypes is not None:\n+        dtypes_to_set = {\n+            name: dtypes[name]\n+            for name in df.columns\n+            if name in dtypes.index and df[name].dtype != dtypes[name]\n+        }\n+        if dtypes_to_set and df.columns.is_unique:\n+            df = df.astype(dtypes_to_set)\n+    return df\n \n \n def _get_output_config(method, estimator=None):\n@@ -127,10 +142,16 @@ def _wrap_data_with_container(method, data_to_wrap, original_input, estimator):\n         return data_to_wrap\n \n     # dense_config == \"pandas\"\n+    dtypes = None\n+    if getattr(estimator, \"_sklearn_preserve_dtypes\", False):\n+        dtypes = getattr(original_input, \"dtypes\", None)\n+        if not hasattr(dtypes, \"index\"):\n+            dtypes = None\n     return _wrap_in_pandas_container(\n         data_to_wrap=data_to_wrap,\n         index=getattr(original_input, \"index\", None),\n         columns=estimator.get_feature_names_out,\n+        dtypes=dtypes,\n     )\n \n \n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 77, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 2, "diff_lines": 77, "steps": 9}], "ms": 52763}
{"instance_id": "scikit-learn__scikit-learn-25232", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/impute/_iterative.py b/sklearn/impute/_iterative.py\nindex 1d918bc0c4..8f958b8e09 100644\n--- a/sklearn/impute/_iterative.py\n+++ b/sklearn/impute/_iterative.py\n@@ -117,6 +117,15 @@ class IterativeImputer(_BaseImputer):\n         Which strategy to use to initialize the missing values. Same as the\n         `strategy` parameter in :class:`~sklearn.impute.SimpleImputer`.\n \n+    fill_value : str or numerical value, default=None\n+        When `initial_strategy=\"constant\"`, `fill_value` is used to replace all\n+        occurrences of missing_values. For string or object data types,\n+        `fill_value` must be a string. If `None`, `fill_value` will be 0 when\n+        imputing numerical data and \"missing_value\" for strings or object data\n+        types. `np.nan` is allowed.\n+\n+        .. versionadded:: 1.3\n+\n     imputation_order : {'ascending', 'descending', 'roman', 'arabic', \\\n             'random'}, default='ascending'\n         The order in which the features will be imputed. Possible values:\n@@ -281,6 +290,7 @@ class IterativeImputer(_BaseImputer):\n         \"initial_strategy\": [\n             StrOptions({\"mean\", \"median\", \"most_frequent\", \"constant\"})\n         ],\n+        \"fill_value\": \"no_validation\",  # any object is valid\n         \"imputation_order\": [\n             StrOptions({\"ascending\", \"descending\", \"roman\", \"arabic\", \"random\"})\n         ],\n@@ -301,6 +311,7 @@ class IterativeImputer(_BaseImputer):\n         tol=1e-3,\n         n_nearest_features=None,\n         initial_strategy=\"mean\",\n+        fill_value=None,\n         imputation_order=\"ascending\",\n         skip_complete=False,\n         min_value=-np.inf,\n@@ -322,6 +333,7 @@ class IterativeImputer(_BaseImputer):\n         self.tol = tol\n         self.n_nearest_features = n_nearest_features\n         self.initial_strategy = initial_strategy\n+        self.fill_value = fill_value\n         self.imputation_order = imputation_order\n         self.skip_complete = skip_complete\n         self.min_value = min_value\n@@ -613,15 +625,21 @@ class IterativeImputer(_BaseImputer):\n             self.initial_imputer_ = SimpleImputer(\n                 missing_values=self.missing_values,\n                 strategy=self.initial_strategy,\n+                fill_value=self.fill_value,\n                 keep_empty_features=self.keep_empty_features,\n             )\n             X_filled = self.initial_imputer_.fit_transform(X)\n         else:\n             X_filled = self.initial_imputer_.transform(X)\n \n-        valid_mask = np.flatnonzero(\n-            np.logical_not(np.isnan(self.initial_imputer_.statistics_))\n-        )\n+        # with the constant strategy, statistics_ holds `fill_value`, which can\n+        # legitimately be NaN, so it cannot be used to detect empty features\n+        if self.initial_strategy == \"constant\":\n+            valid_mask = np.arange(X.shape[1])\n+        else:\n+            valid_mask = np.flatnonzero(\n+                np.logical_not(np.isnan(self.initial_imputer_.statistics_))\n+            )\n \n         if not self.keep_empty_features:\n             # drop empty features\n", "model": "claude-sonnet-5-5", "steps": 13, "finished": true, "patch_lines": 69, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 69, "steps": 13}], "ms": 35862}
{"instance_id": "scikit-learn__scikit-learn-25931", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/ensemble/_iforest.py b/sklearn/ensemble/_iforest.py\nindex 4d6c1c3f0b..c051f93e9c 100644\n--- a/sklearn/ensemble/_iforest.py\n+++ b/sklearn/ensemble/_iforest.py\n@@ -345,7 +345,7 @@ class IsolationForest(OutlierMixin, BaseBagging):\n             return self\n \n         # else, define offset_ wrt contamination parameter\n-        self.offset_ = np.percentile(self.score_samples(X), 100.0 * self.contamination)\n+        self.offset_ = np.percentile(self._score_samples(X), 100.0 * self.contamination)\n \n         return self\n \n@@ -435,6 +435,11 @@ class IsolationForest(OutlierMixin, BaseBagging):\n         # Check data\n         X = self._validate_data(X, accept_sparse=\"csr\", dtype=np.float32, reset=False)\n \n+        # Take the opposite of the scores as bigger is better (here less\n+        # abnormal)\n+        return self._score_samples(X)\n+\n+    def _score_samples(self, X):\n         # Take the opposite of the scores as bigger is better (here less\n         # abnormal)\n         return -self._compute_chunked_score_samples(X)\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 25, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 25, "steps": 7}], "ms": 17746}
{"instance_id": "scikit-learn__scikit-learn-25973", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/feature_selection/_sequential.py b/sklearn/feature_selection/_sequential.py\nindex e983c55de7..8501db6dbe 100644\n--- a/sklearn/feature_selection/_sequential.py\n+++ b/sklearn/feature_selection/_sequential.py\n@@ -8,12 +8,12 @@ import numpy as np\n import warnings\n \n from ._base import SelectorMixin\n-from ..base import BaseEstimator, MetaEstimatorMixin, clone\n+from ..base import BaseEstimator, MetaEstimatorMixin, clone, is_classifier\n from ..utils._param_validation import HasMethods, Hidden, Interval, StrOptions\n from ..utils._param_validation import RealNotInt\n from ..utils._tags import _safe_tags\n from ..utils.validation import check_is_fitted\n-from ..model_selection import cross_val_score\n+from ..model_selection import cross_val_score, check_cv\n from ..metrics import get_scorer_names\n \n \n@@ -271,11 +271,13 @@ class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator\n             else n_features - self.n_features_to_select_\n         )\n \n+        cv = check_cv(self.cv, y, classifier=is_classifier(cloned_estimator))\n+\n         old_score = -np.inf\n         is_auto_select = self.tol is not None and self.n_features_to_select == \"auto\"\n         for _ in range(n_iterations):\n             new_feature_idx, new_score = self._get_best_new_feature_score(\n-                cloned_estimator, X, y, current_mask\n+                cloned_estimator, X, y, cv, current_mask\n             )\n             if is_auto_select and ((new_score - old_score) < self.tol):\n                 break\n@@ -291,7 +293,7 @@ class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator\n \n         return self\n \n-    def _get_best_new_feature_score(self, estimator, X, y, current_mask):\n+    def _get_best_new_feature_score(self, estimator, X, y, cv, current_mask):\n         # Return the best new feature and its score to add to the current_mask,\n         # i.e. return the best new feature and its score to add (resp. remove)\n         # when doing forward selection (resp. backward selection).\n@@ -309,7 +311,7 @@ class SequentialFeatureSelector(SelectorMixin, MetaEstimatorMixin, BaseEstimator\n                 estimator,\n                 X_new,\n                 y,\n-                cv=self.cv,\n+                cv=cv,\n                 scoring=self.scoring,\n                 n_jobs=self.n_jobs,\n             ).mean()\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 52, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 52, "steps": 6}], "ms": 16915}
{"instance_id": "scikit-learn__scikit-learn-26194", "model_name_or_path": "cain-70b-e124", "model_patch": "diff --git a/sklearn/metrics/_ranking.py b/sklearn/metrics/_ranking.py\nindex 0cdead9233..81308dc221 100644\n--- a/sklearn/metrics/_ranking.py\n+++ b/sklearn/metrics/_ranking.py\n@@ -1,1955 +1,2 @@\n-\"\"\"Metrics to assess performance on classification task given scores.\n-\n-Functions named as ``*_score`` return a scalar value to maximize: the higher\n-the better.\n-\n-Function named as ``*_error`` or ``*_loss`` return a scalar value to minimize:\n-the lower the better.\n-\"\"\"\n-\n-# Authors: Alexandre Gramfort <alexandre.gramfort@inria.fr>\n-#          Mathieu Blondel <mathieu@mblondel.org>\n-#          Olivier Grisel <olivier.grisel@ensta.org>\n-#          Arnaud Joly <a.joly@ulg.ac.be>\n-#          Jochen Wersdorfer <jochen@wersdoerfer.de>\n-#          Lars Buitinck\n-#          Joel Nothman <joel.nothman@gmail.com>\n-#          Noel Dawe <noel@dawe.me>\n-#          Michal Karbownik <michakarbownik@gmail.com>\n-# License: BSD 3 clause\n-\n-\n-import warnings\n-from functools import partial\n-from numbers import Real, Integral\n-\n-import numpy as np\n-from scipy.sparse import csr_matrix, issparse\n-from scipy.stats import rankdata\n-\n-from ..utils import assert_all_finite\n-from ..utils import check_consistent_length\n-from ..utils.validation import _check_pos_label_consistency, _check_sample_weight\n-from ..utils import column_or_1d, check_array\n-from ..utils.multiclass import type_of_target\n-from ..utils.extmath import stable_cumsum\n-from ..utils.sparsefuncs import count_nonzero\n-from ..utils._param_validation import validate_params, StrOptions, Interval\n-from ..exceptions import UndefinedMetricWarning\n-from ..preprocessing import label_binarize\n-from ..utils._encode import _encode, _unique\n-\n-from ._base import _average_binary_score, _average_multiclass_ovo_score\n-\n-\n-@validate_params({\"x\": [\"array-like\"], \"y\": [\"array-like\"]})\n-def auc(x, y):\n-    \"\"\"Compute Area Under the Curve (AUC) using the trapezoidal rule.\n-\n-    This is a general function, given points on a curve.  For computing the\n-    area under the ROC-curve, see :func:`roc_auc_score`.  For an alternative\n-    way to summarize a precision-recall curve, see\n-    :func:`average_precision_score`.\n-\n-    Parameters\n-    ----------\n-    x : array-like of shape (n,)\n-        X coordinates. These must be either monotonic increasing or monotonic\n-        decreasing.\n-    y : array-like of shape (n,)\n-        Y coordinates.\n-\n-    Returns\n-    -------\n-    auc : float\n-        Area Under the Curve.\n-\n-    See Also\n-    --------\n-    roc_auc_score : Compute the area under the ROC curve.\n-    average_precision_score : Compute average precision from prediction scores.\n-    precision_recall_curve : Compute precision-recall pairs for different\n-        probability thresholds.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn import metrics\n-    >>> y = np.array([1, 1, 2, 2])\n-    >>> pred = np.array([0.1, 0.4, 0.35, 0.8])\n-    >>> fpr, tpr, thresholds = metrics.roc_curve(y, pred, pos_label=2)\n-    >>> metrics.auc(fpr, tpr)\n-    0.75\n-    \"\"\"\n-    check_consistent_length(x, y)\n-    x = column_or_1d(x)\n-    y = column_or_1d(y)\n-\n-    if x.shape[0] < 2:\n-        raise ValueError(\n-            \"At least 2 points are needed to compute area under curve, but x.shape = %s\"\n-            % x.shape\n-        )\n-\n-    direction = 1\n-    dx = np.diff(x)\n-    if np.any(dx < 0):\n-        if np.all(dx <= 0):\n-            direction = -1\n-        else:\n-            raise ValueError(\"x is neither increasing nor decreasing : {}.\".format(x))\n-\n-    area = direction * np.trapz(y, x)\n-    if isinstance(area, np.memmap):\n-        # Reductions such as .sum used internally in np.trapz do not return a\n-        # scalar by default for numpy.memmap instances contrary to\n-        # regular numpy.ndarray instances.\n-        area = area.dtype.type(area)\n-    return area\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"average\": [StrOptions({\"micro\", \"samples\", \"weighted\", \"macro\"}), None],\n-        \"pos_label\": [Real, str, \"boolean\"],\n-        \"sample_weight\": [\"array-like\", None],\n-    }\n-)\n-def average_precision_score(\n-    y_true, y_score, *, average=\"macro\", pos_label=1, sample_weight=None\n-):\n-    \"\"\"Compute average precision (AP) from prediction scores.\n-\n-    AP summarizes a precision-recall curve as the weighted mean of precisions\n-    achieved at each threshold, with the increase in recall from the previous\n-    threshold used as the weight:\n-\n-    .. math::\n-        \\\\text{AP} = \\\\sum_n (R_n - R_{n-1}) P_n\n-\n-    where :math:`P_n` and :math:`R_n` are the precision and recall at the nth\n-    threshold [1]_. This implementation is not interpolated and is different\n-    from computing the area under the precision-recall curve with the\n-    trapezoidal rule, which uses linear interpolation and can be too\n-    optimistic.\n-\n-    Note: this implementation is restricted to the binary classification task\n-    or multilabel classification task.\n-\n-    Read more in the :ref:`User Guide <precision_recall_f_measure_metrics>`.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples,) or (n_samples, n_classes)\n-        True binary labels or binary label indicators.\n-\n-    y_score : array-like of shape (n_samples,) or (n_samples, n_classes)\n-        Target scores, can either be probability estimates of the positive\n-        class, confidence values, or non-thresholded measure of decisions\n-        (as returned by :term:`decision_function` on some classifiers).\n-\n-    average : {'micro', 'samples', 'weighted', 'macro'} or None, \\\n-            default='macro'\n-        If ``None``, the scores for each class are returned. Otherwise,\n-        this determines the type of averaging performed on the data:\n-\n-        ``'micro'``:\n-            Calculate metrics globally by considering each element of the label\n-            indicator matrix as a label.\n-        ``'macro'``:\n-            Calculate metrics for each label, and find their unweighted\n-            mean.  This does not take label imbalance into account.\n-        ``'weighted'``:\n-            Calculate metrics for each label, and find their average, weighted\n-            by support (the number of true instances for each label).\n-        ``'samples'``:\n-            Calculate metrics for each instance, and find their average.\n-\n-        Will be ignored when ``y_true`` is binary.\n-\n-    pos_label : int, float, bool or str, default=1\n-        The label of the positive class. Only applied to binary ``y_true``.\n-        For multilabel-indicator ``y_true``, ``pos_label`` is fixed to 1.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    Returns\n-    -------\n-    average_precision : float\n-        Average precision score.\n-\n-    See Also\n-    --------\n-    roc_auc_score : Compute the area under the ROC curve.\n-    precision_recall_curve : Compute precision-recall pairs for different\n-        probability thresholds.\n-\n-    Notes\n-    -----\n-    .. versionchanged:: 0.19\n-      Instead of linearly interpolating between operating points, precisions\n-      are weighted by the change in recall since the last operating point.\n-\n-    References\n-    ----------\n-    .. [1] `Wikipedia entry for the Average precision\n-           <https://en.wikipedia.org/w/index.php?title=Information_retrieval&\n-           oldid=793358396#Average_precision>`_\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn.metrics import average_precision_score\n-    >>> y_true = np.array([0, 0, 1, 1])\n-    >>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])\n-    >>> average_precision_score(y_true, y_scores)\n-    0.83...\n-    \"\"\"\n-\n-    def _binary_uninterpolated_average_precision(\n-        y_true, y_score, pos_label=1, sample_weight=None\n-    ):\n-        precision, recall, _ = precision_recall_curve(\n-            y_true, y_score, pos_label=pos_label, sample_weight=sample_weight\n-        )\n-        # Return the step function integral\n-        # The following works because the last entry of precision is\n-        # guaranteed to be 1, as returned by precision_recall_curve\n-        return -np.sum(np.diff(recall) * np.array(precision)[:-1])\n-\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    if y_type == \"multilabel-indicator\" and pos_label != 1:\n-        raise ValueError(\n-            \"Parameter pos_label is fixed to 1 for \"\n-            \"multilabel-indicator y_true. Do not set \"\n-            \"pos_label or set pos_label to 1.\"\n-        )\n-    elif y_type == \"binary\":\n-        # Convert to Python primitive type to avoid NumPy type / Python str\n-        # comparison. See https://github.com/numpy/numpy/issues/6784\n-        present_labels = np.unique(y_true).tolist()\n-        if len(present_labels) == 2 and pos_label not in present_labels:\n-            raise ValueError(\n-                f\"pos_label={pos_label} is not a valid label. It should be \"\n-                f\"one of {present_labels}\"\n-            )\n-    average_precision = partial(\n-        _binary_uninterpolated_average_precision, pos_label=pos_label\n-    )\n-    return _average_binary_score(\n-        average_precision, y_true, y_score, average, sample_weight=sample_weight\n-    )\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"pos_label\": [Real, str, \"boolean\", None],\n-        \"sample_weight\": [\"array-like\", None],\n-    }\n-)\n-def det_curve(y_true, y_score, pos_label=None, sample_weight=None):\n-    \"\"\"Compute error rates for different probability thresholds.\n-\n-    .. note::\n-       This metric is used for evaluation of ranking and error tradeoffs of\n-       a binary classification task.\n-\n-    Read more in the :ref:`User Guide <det_curve>`.\n-\n-    .. versionadded:: 0.24\n-\n-    Parameters\n-    ----------\n-    y_true : ndarray of shape (n_samples,)\n-        True binary labels. If labels are not either {-1, 1} or {0, 1}, then\n-        pos_label should be explicitly given.\n-\n-    y_score : ndarray of shape of (n_samples,)\n-        Target scores, can either be probability estimates of the positive\n-        class, confidence values, or non-thresholded measure of decisions\n-        (as returned by \"decision_function\" on some classifiers).\n-\n-    pos_label : int, float, bool or str, default=None\n-        The label of the positive class.\n-        When ``pos_label=None``, if `y_true` is in {-1, 1} or {0, 1},\n-        ``pos_label`` is set to 1, otherwise an error will be raised.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    Returns\n-    -------\n-    fpr : ndarray of shape (n_thresholds,)\n-        False positive rate (FPR) such that element i is the false positive\n-        rate of predictions with score >= thresholds[i]. This is occasionally\n-        referred to as false acceptance propability or fall-out.\n-\n-    fnr : ndarray of shape (n_thresholds,)\n-        False negative rate (FNR) such that element i is the false negative\n-        rate of predictions with score >= thresholds[i]. This is occasionally\n-        referred to as false rejection or miss rate.\n-\n-    thresholds : ndarray of shape (n_thresholds,)\n-        Decreasing score values.\n-\n-    See Also\n-    --------\n-    DetCurveDisplay.from_estimator : Plot DET curve given an estimator and\n-        some data.\n-    DetCurveDisplay.from_predictions : Plot DET curve given the true and\n-        predicted labels.\n-    DetCurveDisplay : DET curve visualization.\n-    roc_curve : Compute Receiver operating characteristic (ROC) curve.\n-    precision_recall_curve : Compute precision-recall curve.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn.metrics import det_curve\n-    >>> y_true = np.array([0, 0, 1, 1])\n-    >>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])\n-    >>> fpr, fnr, thresholds = det_curve(y_true, y_scores)\n-    >>> fpr\n-    array([0.5, 0.5, 0. ])\n-    >>> fnr\n-    array([0. , 0.5, 0.5])\n-    >>> thresholds\n-    array([0.35, 0.4 , 0.8 ])\n-    \"\"\"\n-    fps, tps, thresholds = _binary_clf_curve(\n-        y_true, y_score, pos_label=pos_label, sample_weight=sample_weight\n-    )\n-\n-    if len(np.unique(y_true)) != 2:\n-        raise ValueError(\n-            \"Only one class present in y_true. Detection error \"\n-            \"tradeoff curve is not defined in that case.\"\n-        )\n-\n-    fns = tps[-1] - tps\n-    p_count = tps[-1]\n-    n_count = fps[-1]\n-\n-    # start with false positives zero\n-    first_ind = (\n-        fps.searchsorted(fps[0], side=\"right\") - 1\n-        if fps.searchsorted(fps[0], side=\"right\") > 0\n-        else None\n-    )\n-    # stop with false negatives zero\n-    last_ind = tps.searchsorted(tps[-1]) + 1\n-    sl = slice(first_ind, last_ind)\n-\n-    # reverse the output such that list of false positives is decreasing\n-    return (fps[sl][::-1] / n_count, fns[sl][::-1] / p_count, thresholds[sl][::-1])\n-\n-\n-def _binary_roc_auc_score(y_true, y_score, sample_weight=None, max_fpr=None):\n-    \"\"\"Binary roc auc score.\"\"\"\n-    if len(np.unique(y_true)) != 2:\n-        raise ValueError(\n-            \"Only one class present in y_true. ROC AUC score \"\n-            \"is not defined in that case.\"\n-        )\n-\n-    fpr, tpr, _ = roc_curve(y_true, y_score, sample_weight=sample_weight)\n-    if max_fpr is None or max_fpr == 1:\n-        return auc(fpr, tpr)\n-    if max_fpr <= 0 or max_fpr > 1:\n-        raise ValueError(\"Expected max_fpr in range (0, 1], got: %r\" % max_fpr)\n-\n-    # Add a single point at max_fpr by linear interpolation\n-    stop = np.searchsorted(fpr, max_fpr, \"right\")\n-    x_interp = [fpr[stop - 1], fpr[stop]]\n-    y_interp = [tpr[stop - 1], tpr[stop]]\n-    tpr = np.append(tpr[:stop], np.interp(max_fpr, x_interp, y_interp))\n-    fpr = np.append(fpr[:stop], max_fpr)\n-    partial_auc = auc(fpr, tpr)\n-\n-    # McClish correction: standardize result to be 0.5 if non-discriminant\n-    # and 1 if maximal\n-    min_area = 0.5 * max_fpr**2\n-    max_area = max_fpr\n-    return 0.5 * (1 + (partial_auc - min_area) / (max_area - min_area))\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"average\": [StrOptions({\"micro\", \"macro\", \"samples\", \"weighted\"}), None],\n-        \"sample_weight\": [\"array-like\", None],\n-        \"max_fpr\": [Interval(Real, 0.0, 1, closed=\"right\"), None],\n-        \"multi_class\": [StrOptions({\"raise\", \"ovr\", \"ovo\"})],\n-        \"labels\": [\"array-like\", None],\n-    }\n-)\n-def roc_auc_score(\n-    y_true,\n-    y_score,\n-    *,\n-    average=\"macro\",\n-    sample_weight=None,\n-    max_fpr=None,\n-    multi_class=\"raise\",\n-    labels=None,\n-):\n-    \"\"\"Compute Area Under the Receiver Operating Characteristic Curve (ROC AUC) \\\n-    from prediction scores.\n-\n-    Note: this implementation can be used with binary, multiclass and\n-    multilabel classification, but some restrictions apply (see Parameters).\n-\n-    Read more in the :ref:`User Guide <roc_metrics>`.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples,) or (n_samples, n_classes)\n-        True labels or binary label indicators. The binary and multiclass cases\n-        expect labels with shape (n_samples,) while the multilabel case expects\n-        binary label indicators with shape (n_samples, n_classes).\n-\n-    y_score : array-like of shape (n_samples,) or (n_samples, n_classes)\n-        Target scores.\n-\n-        * In the binary case, it corresponds to an array of shape\n-          `(n_samples,)`. Both probability estimates and non-thresholded\n-          decision values can be provided. The probability estimates correspond\n-          to the **probability of the class with the greater label**,\n-          i.e. `estimator.classes_[1]` and thus\n-          `estimator.predict_proba(X, y)[:, 1]`. The decision values\n-          corresponds to the output of `estimator.decision_function(X, y)`.\n-          See more information in the :ref:`User guide <roc_auc_binary>`;\n-        * In the multiclass case, it corresponds to an array of shape\n-          `(n_samples, n_classes)` of probability estimates provided by the\n-          `predict_proba` method. The probability estimates **must**\n-          sum to 1 across the possible classes. In addition, the order of the\n-          class scores must correspond to the order of ``labels``,\n-          if provided, or else to the numerical or lexicographical order of\n-          the labels in ``y_true``. See more information in the\n-          :ref:`User guide <roc_auc_multiclass>`;\n-        * In the multilabel case, it corresponds to an array of shape\n-          `(n_samples, n_classes)`. Probability estimates are provided by the\n-          `predict_proba` method and the non-thresholded decision values by\n-          the `decision_function` method. The probability estimates correspond\n-          to the **probability of the class with the greater label for each\n-          output** of the classifier. See more information in the\n-          :ref:`User guide <roc_auc_multilabel>`.\n-\n-    average : {'micro', 'macro', 'samples', 'weighted'} or None, \\\n-            default='macro'\n-        If ``None``, the scores for each class are returned.\n-        Otherwise, this determines the type of averaging performed on the data.\n-        Note: multiclass ROC AUC currently only handles the 'macro' and\n-        'weighted' averages. For multiclass targets, `average=None` is only\n-        implemented for `multi_class='ovr'` and `average='micro'` is only\n-        implemented for `multi_class='ovr'`.\n-\n-        ``'micro'``:\n-            Calculate metrics globally by considering each element of the label\n-            indicator matrix as a label.\n-        ``'macro'``:\n-            Calculate metrics for each label, and find their unweighted\n-            mean.  This does not take label imbalance into account.\n-        ``'weighted'``:\n-            Calculate metrics for each label, and find their average, weighted\n-            by support (the number of true instances for each label).\n-        ``'samples'``:\n-            Calculate metrics for each instance, and find their average.\n-\n-        Will be ignored when ``y_true`` is binary.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    max_fpr : float > 0 and <= 1, default=None\n-        If not ``None``, the standardized partial AUC [2]_ over the range\n-        [0, max_fpr] is returned. For the multiclass case, ``max_fpr``,\n-        should be either equal to ``None`` or ``1.0`` as AUC ROC partial\n-        computation currently is not supported for multiclass.\n-\n-    multi_class : {'raise', 'ovr', 'ovo'}, default='raise'\n-        Only used for multiclass targets. Determines the type of configuration\n-        to use. The default value raises an error, so either\n-        ``'ovr'`` or ``'ovo'`` must be passed explicitly.\n-\n-        ``'ovr'``:\n-            Stands for One-vs-rest. Computes the AUC of each class\n-            against the rest [3]_ [4]_. This\n-            treats the multiclass case in the same way as the multilabel case.\n-            Sensitive to class imbalance even when ``average == 'macro'``,\n-            because class imbalance affects the composition of each of the\n-            'rest' groupings.\n-        ``'ovo'``:\n-            Stands for One-vs-one. Computes the average AUC of all\n-            possible pairwise combinations of classes [5]_.\n-            Insensitive to class imbalance when\n-            ``average == 'macro'``.\n-\n-    labels : array-like of shape (n_classes,), default=None\n-        Only used for multiclass targets. List of labels that index the\n-        classes in ``y_score``. If ``None``, the numerical or lexicographical\n-        order of the labels in ``y_true`` is used.\n-\n-    Returns\n-    -------\n-    auc : float\n-        Area Under the Curve score.\n-\n-    See Also\n-    --------\n-    average_precision_score : Area under the precision-recall curve.\n-    roc_curve : Compute Receiver operating characteristic (ROC) curve.\n-    RocCurveDisplay.from_estimator : Plot Receiver Operating Characteristic\n-        (ROC) curve given an estimator and some data.\n-    RocCurveDisplay.from_predictions : Plot Receiver Operating Characteristic\n-        (ROC) curve given the true and predicted values.\n-\n-    References\n-    ----------\n-    .. [1] `Wikipedia entry for the Receiver operating characteristic\n-            <https://en.wikipedia.org/wiki/Receiver_operating_characteristic>`_\n-\n-    .. [2] `Analyzing a portion of the ROC curve. McClish, 1989\n-            <https://www.ncbi.nlm.nih.gov/pubmed/2668680>`_\n-\n-    .. [3] Provost, F., Domingos, P. (2000). Well-trained PETs: Improving\n-           probability estimation trees (Section 6.2), CeDER Working Paper\n-           #IS-00-04, Stern School of Business, New York University.\n-\n-    .. [4] `Fawcett, T. (2006). An introduction to ROC analysis. Pattern\n-            Recognition Letters, 27(8), 861-874.\n-            <https://www.sciencedirect.com/science/article/pii/S016786550500303X>`_\n-\n-    .. [5] `Hand, D.J., Till, R.J. (2001). A Simple Generalisation of the Area\n-            Under the ROC Curve for Multiple Class Classification Problems.\n-            Machine Learning, 45(2), 171-186.\n-            <http://link.springer.com/article/10.1023/A:1010920819831>`_\n-\n-    Examples\n-    --------\n-    Binary case:\n-\n-    >>> from sklearn.datasets import load_breast_cancer\n-    >>> from sklearn.linear_model import LogisticRegression\n-    >>> from sklearn.metrics import roc_auc_score\n-    >>> X, y = load_breast_cancer(return_X_y=True)\n-    >>> clf = LogisticRegression(solver=\"liblinear\", random_state=0).fit(X, y)\n-    >>> roc_auc_score(y, clf.predict_proba(X)[:, 1])\n-    0.99...\n-    >>> roc_auc_score(y, clf.decision_function(X))\n-    0.99...\n-\n-    Multiclass case:\n-\n-    >>> from sklearn.datasets import load_iris\n-    >>> X, y = load_iris(return_X_y=True)\n-    >>> clf = LogisticRegression(solver=\"liblinear\").fit(X, y)\n-    >>> roc_auc_score(y, clf.predict_proba(X), multi_class='ovr')\n-    0.99...\n-\n-    Multilabel case:\n-\n-    >>> import numpy as np\n-    >>> from sklearn.datasets import make_multilabel_classification\n-    >>> from sklearn.multioutput import MultiOutputClassifier\n-    >>> X, y = make_multilabel_classification(random_state=0)\n-    >>> clf = MultiOutputClassifier(clf).fit(X, y)\n-    >>> # get a list of n_output containing probability arrays of shape\n-    >>> # (n_samples, n_classes)\n-    >>> y_pred = clf.predict_proba(X)\n-    >>> # extract the positive columns for each output\n-    >>> y_pred = np.transpose([pred[:, 1] for pred in y_pred])\n-    >>> roc_auc_score(y, y_pred, average=None)\n-    array([0.82..., 0.86..., 0.94..., 0.85... , 0.94...])\n-    >>> from sklearn.linear_model import RidgeClassifierCV\n-    >>> clf = RidgeClassifierCV().fit(X, y)\n-    >>> roc_auc_score(y, clf.decision_function(X), average=None)\n-    array([0.81..., 0.84... , 0.93..., 0.87..., 0.94...])\n-    \"\"\"\n-\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    y_true = check_array(y_true, ensure_2d=False, dtype=None)\n-    y_score = check_array(y_score, ensure_2d=False)\n-\n-    if y_type == \"multiclass\" or (\n-        y_type == \"binary\" and y_score.ndim == 2 and y_score.shape[1] > 2\n-    ):\n-        # do not support partial ROC computation for multiclass\n-        if max_fpr is not None and max_fpr != 1.0:\n-            raise ValueError(\n-                \"Partial AUC computation not available in \"\n-                \"multiclass setting, 'max_fpr' must be\"\n-                \" set to `None`, received `max_fpr={0}` \"\n-                \"instead\".format(max_fpr)\n-            )\n-        if multi_class == \"raise\":\n-            raise ValueError(\"multi_class must be in ('ovo', 'ovr')\")\n-        return _multiclass_roc_auc_score(\n-            y_true, y_score, labels, multi_class, average, sample_weight\n-        )\n-    elif y_type == \"binary\":\n-        labels = np.unique(y_true)\n-        y_true = label_binarize(y_true, classes=labels)[:, 0]\n-        return _average_binary_score(\n-            partial(_binary_roc_auc_score, max_fpr=max_fpr),\n-            y_true,\n-            y_score,\n-            average,\n-            sample_weight=sample_weight,\n-        )\n-    else:  # multilabel-indicator\n-        return _average_binary_score(\n-            partial(_binary_roc_auc_score, max_fpr=max_fpr),\n-            y_true,\n-            y_score,\n-            average,\n-            sample_weight=sample_weight,\n-        )\n-\n-\n-def _multiclass_roc_auc_score(\n-    y_true, y_score, labels, multi_class, average, sample_weight\n-):\n-    \"\"\"Multiclass roc auc score.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples,)\n-        True multiclass labels.\n-\n-    y_score : array-like of shape (n_samples, n_classes)\n-        Target scores corresponding to probability estimates of a sample\n-        belonging to a particular class\n-\n-    labels : array-like of shape (n_classes,) or None\n-        List of labels to index ``y_score`` used for multiclass. If ``None``,\n-        the lexical order of ``y_true`` is used to index ``y_score``.\n-\n-    multi_class : {'ovr', 'ovo'}\n-        Determines the type of multiclass configuration to use.\n-        ``'ovr'``:\n-            Calculate metrics for the multiclass case using the one-vs-rest\n-            approach.\n-        ``'ovo'``:\n-            Calculate metrics for the multiclass case using the one-vs-one\n-            approach.\n-\n-    average : {'micro', 'macro', 'weighted'}\n-        Determines the type of averaging performed on the pairwise binary\n-        metric scores\n-        ``'micro'``:\n-            Calculate metrics for the binarized-raveled classes. Only supported\n-            for `multi_class='ovr'`.\n-\n-        .. versionadded:: 1.2\n-\n-        ``'macro'``:\n-            Calculate metrics for each label, and find their unweighted\n-            mean. This does not take label imbalance into account. Classes\n-            are assumed to be uniformly distributed.\n-        ``'weighted'``:\n-            Calculate metrics for each label, taking into account the\n-            prevalence of the classes.\n-\n-    sample_weight : array-like of shape (n_samples,) or None\n-        Sample weights.\n-\n-    \"\"\"\n-    # validation of the input y_score\n-    if not np.allclose(1, y_score.sum(axis=1)):\n-        raise ValueError(\n-            \"Target scores need to be probabilities for multiclass \"\n-            \"roc_auc, i.e. they should sum up to 1.0 over classes\"\n-        )\n-\n-    # validation for multiclass parameter specifications\n-    average_options = (\"macro\", \"weighted\", None)\n-    if multi_class == \"ovr\":\n-        average_options = (\"micro\",) + average_options\n-    if average not in average_options:\n-        raise ValueError(\n-            \"average must be one of {0} for multiclass problems\".format(average_options)\n-        )\n-\n-    multiclass_options = (\"ovo\", \"ovr\")\n-    if multi_class not in multiclass_options:\n-        raise ValueError(\n-            \"multi_class='{0}' is not supported \"\n-            \"for multiclass ROC AUC, multi_class must be \"\n-            \"in {1}\".format(multi_class, multiclass_options)\n-        )\n-\n-    if average is None and multi_class == \"ovo\":\n-        raise NotImplementedError(\n-            \"average=None is not implemented for multi_class='ovo'.\"\n-        )\n-\n-    if labels is not None:\n-        labels = column_or_1d(labels)\n-        classes = _unique(labels)\n-        if len(classes) != len(labels):\n-            raise ValueError(\"Parameter 'labels' must be unique\")\n-        if not np.array_equal(classes, labels):\n-            raise ValueError(\"Parameter 'labels' must be ordered\")\n-        if len(classes) != y_score.shape[1]:\n-            raise ValueError(\n-                \"Number of given labels, {0}, not equal to the number \"\n-                \"of columns in 'y_score', {1}\".format(len(classes), y_score.shape[1])\n-            )\n-        if len(np.setdiff1d(y_true, classes)):\n-            raise ValueError(\"'y_true' contains labels not in parameter 'labels'\")\n-    else:\n-        classes = _unique(y_true)\n-        if len(classes) != y_score.shape[1]:\n-            raise ValueError(\n-                \"Number of classes in y_true not equal to the number of \"\n-                \"columns in 'y_score'\"\n-            )\n-\n-    if multi_class == \"ovo\":\n-        if sample_weight is not None:\n-            raise ValueError(\n-                \"sample_weight is not supported \"\n-                \"for multiclass one-vs-one ROC AUC, \"\n-                \"'sample_weight' must be None in this case.\"\n-            )\n-        y_true_encoded = _encode(y_true, uniques=classes)\n-        # Hand & Till (2001) implementation (ovo)\n-        return _average_multiclass_ovo_score(\n-            _binary_roc_auc_score, y_true_encoded, y_score, average=average\n-        )\n-    else:\n-        # ovr is same as multi-label\n-        y_true_multilabel = label_binarize(y_true, classes=classes)\n-        return _average_binary_score(\n-            _binary_roc_auc_score,\n-            y_true_multilabel,\n-            y_score,\n-            average,\n-            sample_weight=sample_weight,\n-        )\n-\n-\n-def _binary_clf_curve(y_true, y_score, pos_label=None, sample_weight=None):\n-    \"\"\"Calculate true and false positives per binary classification threshold.\n-\n-    Parameters\n-    ----------\n-    y_true : ndarray of shape (n_samples,)\n-        True targets of binary classification.\n-\n-    y_score : ndarray of shape (n_samples,)\n-        Estimated probabilities or output of a decision function.\n-\n-    pos_label : int, float, bool or str, default=None\n-        The label of the positive class.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    Returns\n-    -------\n-    fps : ndarray of shape (n_thresholds,)\n-        A count of false positives, at index i being the number of negative\n-        samples assigned a score >= thresholds[i]. The total number of\n-        negative samples is equal to fps[-1] (thus true negatives are given by\n-        fps[-1] - fps).\n-\n-    tps : ndarray of shape (n_thresholds,)\n-        An increasing count of true positives, at index i being the number\n-        of positive samples assigned a score >= thresholds[i]. The total\n-        number of positive samples is equal to tps[-1] (thus false negatives\n-        are given by tps[-1] - tps).\n-\n-    thresholds : ndarray of shape (n_thresholds,)\n-        Decreasing score values.\n-    \"\"\"\n-    # Check to make sure y_true is valid\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    if not (y_type == \"binary\" or (y_type == \"multiclass\" and pos_label is not None)):\n-        raise ValueError(\"{0} format is not supported\".format(y_type))\n-\n-    check_consistent_length(y_true, y_score, sample_weight)\n-    y_true = column_or_1d(y_true)\n-    y_score = column_or_1d(y_score)\n-    assert_all_finite(y_true)\n-    assert_all_finite(y_score)\n-\n-    # Filter out zero-weighted samples, as they should not impact the result\n-    if sample_weight is not None:\n-        sample_weight = column_or_1d(sample_weight)\n-        sample_weight = _check_sample_weight(sample_weight, y_true)\n-        nonzero_weight_mask = sample_weight != 0\n-        y_true = y_true[nonzero_weight_mask]\n-        y_score = y_score[nonzero_weight_mask]\n-        sample_weight = sample_weight[nonzero_weight_mask]\n-\n-    pos_label = _check_pos_label_consistency(pos_label, y_true)\n-\n-    # make y_true a boolean vector\n-    y_true = y_true == pos_label\n-\n-    # sort scores and corresponding truth values\n-    desc_score_indices = np.argsort(y_score, kind=\"mergesort\")[::-1]\n-    y_score = y_score[desc_score_indices]\n-    y_true = y_true[desc_score_indices]\n-    if sample_weight is not None:\n-        weight = sample_weight[desc_score_indices]\n-    else:\n-        weight = 1.0\n-\n-    # y_score typically has many tied values. Here we extract\n-    # the indices associated with the distinct values. We also\n-    # concatenate a value for the end of the curve.\n-    distinct_value_indices = np.where(np.diff(y_score))[0]\n-    threshold_idxs = np.r_[distinct_value_indices, y_true.size - 1]\n-\n-    # accumulate the true positives with decreasing threshold\n-    tps = stable_cumsum(y_true * weight)[threshold_idxs]\n-    if sample_weight is not None:\n-        # express fps as a cumsum to ensure fps is increasing even in\n-        # the presence of floating point errors\n-        fps = stable_cumsum((1 - y_true) * weight)[threshold_idxs]\n-    else:\n-        fps = 1 + threshold_idxs - tps\n-    return fps, tps, y_score[threshold_idxs]\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"probas_pred\": [\"array-like\"],\n-        \"pos_label\": [Real, str, \"boolean\", None],\n-        \"sample_weight\": [\"array-like\", None],\n-        \"drop_intermediate\": [\"boolean\"],\n-    }\n-)\n-def precision_recall_curve(\n-    y_true, probas_pred, *, pos_label=None, sample_weight=None, drop_intermediate=False\n-):\n-    \"\"\"Compute precision-recall pairs for different probability thresholds.\n-\n-    Note: this implementation is restricted to the binary classification task.\n-\n-    The precision is the ratio ``tp / (tp + fp)`` where ``tp`` is the number of\n-    true positives and ``fp`` the number of false positives. The precision is\n-    intuitively the ability of the classifier not to label as positive a sample\n-    that is negative.\n-\n-    The recall is the ratio ``tp / (tp + fn)`` where ``tp`` is the number of\n-    true positives and ``fn`` the number of false negatives. The recall is\n-    intuitively the ability of the classifier to find all the positive samples.\n-\n-    The last precision and recall values are 1. and 0. respectively and do not\n-    have a corresponding threshold. This ensures that the graph starts on the\n-    y axis.\n-\n-    The first precision and recall values are precision=class balance and recall=1.0\n-    which corresponds to a classifier that always predicts the positive class.\n-\n-    Read more in the :ref:`User Guide <precision_recall_f_measure_metrics>`.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples,)\n-        True binary labels. If labels are not either {-1, 1} or {0, 1}, then\n-        pos_label should be explicitly given.\n-\n-    probas_pred : array-like of shape (n_samples,)\n-        Target scores, can either be probability estimates of the positive\n-        class, or non-thresholded measure of decisions (as returned by\n-        `decision_function` on some classifiers).\n-\n-    pos_label : int, float, bool or str, default=None\n-        The label of the positive class.\n-        When ``pos_label=None``, if y_true is in {-1, 1} or {0, 1},\n-        ``pos_label`` is set to 1, otherwise an error will be raised.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    drop_intermediate : bool, default=False\n-        Whether to drop some suboptimal thresholds which would not appear\n-        on a plotted precision-recall curve. This is useful in order to create\n-        lighter precision-recall curves.\n-\n-        .. versionadded:: 1.3\n-\n-    Returns\n-    -------\n-    precision : ndarray of shape (n_thresholds + 1,)\n-        Precision values such that element i is the precision of\n-        predictions with score >= thresholds[i] and the last element is 1.\n-\n-    recall : ndarray of shape (n_thresholds + 1,)\n-        Decreasing recall values such that element i is the recall of\n-        predictions with score >= thresholds[i] and the last element is 0.\n-\n-    thresholds : ndarray of shape (n_thresholds,)\n-        Increasing thresholds on the decision function used to compute\n-        precision and recall where `n_thresholds = len(np.unique(probas_pred))`.\n-\n-    See Also\n-    --------\n-    PrecisionRecallDisplay.from_estimator : Plot Precision Recall Curve given\n-        a binary classifier.\n-    PrecisionRecallDisplay.from_predictions : Plot Precision Recall Curve\n-        using predictions from a binary classifier.\n-    average_precision_score : Compute average precision from prediction scores.\n-    det_curve: Compute error rates for different probability thresholds.\n-    roc_curve : Compute Receiver operating characteristic (ROC) curve.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn.metrics import precision_recall_curve\n-    >>> y_true = np.array([0, 0, 1, 1])\n-    >>> y_scores = np.array([0.1, 0.4, 0.35, 0.8])\n-    >>> precision, recall, thresholds = precision_recall_curve(\n-    ...     y_true, y_scores)\n-    >>> precision\n-    array([0.5       , 0.66666667, 0.5       , 1.        , 1.        ])\n-    >>> recall\n-    array([1. , 1. , 0.5, 0.5, 0. ])\n-    >>> thresholds\n-    array([0.1 , 0.35, 0.4 , 0.8 ])\n-    \"\"\"\n-    fps, tps, thresholds = _binary_clf_curve(\n-        y_true, probas_pred, pos_label=pos_label, sample_weight=sample_weight\n-    )\n-\n-    if drop_intermediate and len(fps) > 2:\n-        # Drop thresholds corresponding to points where true positives (tps)\n-        # do not change from the previous or subsequent point. This will keep\n-        # only the first and last point for each tps value. All points\n-        # with the same tps value have the same recall and thus x coordinate.\n-        # They appear as a vertical line on the plot.\n-        optimal_idxs = np.where(\n-            np.concatenate(\n-                [[True], np.logical_or(np.diff(tps[:-1]), np.diff(tps[1:])), [True]]\n-            )\n-        )[0]\n-        fps = fps[optimal_idxs]\n-        tps = tps[optimal_idxs]\n-        thresholds = thresholds[optimal_idxs]\n-\n-    ps = tps + fps\n-    # Initialize the result array with zeros to make sure that precision[ps == 0]\n-    # does not contain uninitialized values.\n-    precision = np.zeros_like(tps)\n-    np.divide(tps, ps, out=precision, where=(ps != 0))\n-\n-    # When no positive label in y_true, recall is set to 1 for all thresholds\n-    # tps[-1] == 0 <=> y_true == all negative labels\n-    if tps[-1] == 0:\n-        warnings.warn(\n-            \"No positive class found in y_true, \"\n-            \"recall is set to one for all thresholds.\"\n-        )\n-        recall = np.ones_like(tps)\n-    else:\n-        recall = tps / tps[-1]\n-\n-    # reverse the outputs so recall is decreasing\n-    sl = slice(None, None, -1)\n-    return np.hstack((precision[sl], 1)), np.hstack((recall[sl], 0)), thresholds[sl]\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"pos_label\": [Real, str, \"boolean\", None],\n-        \"sample_weight\": [\"array-like\", None],\n-        \"drop_intermediate\": [\"boolean\"],\n-    }\n-)\n-def roc_curve(\n-    y_true, y_score, *, pos_label=None, sample_weight=None, drop_intermediate=True\n-):\n-    \"\"\"Compute Receiver operating characteristic (ROC).\n-\n-    Note: this implementation is restricted to the binary classification task.\n-\n-    Read more in the :ref:`User Guide <roc_metrics>`.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples,)\n-        True binary labels. If labels are not either {-1, 1} or {0, 1}, then\n-        pos_label should be explicitly given.\n-\n-    y_score : array-like of shape (n_samples,)\n-        Target scores, can either be probability estimates of the positive\n-        class, confidence values, or non-thresholded measure of decisions\n-        (as returned by \"decision_function\" on some classifiers).\n-\n-    pos_label : int, float, bool or str, default=None\n-        The label of the positive class.\n-        When ``pos_label=None``, if `y_true` is in {-1, 1} or {0, 1},\n-        ``pos_label`` is set to 1, otherwise an error will be raised.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    drop_intermediate : bool, default=True\n-        Whether to drop some suboptimal thresholds which would not appear\n-        on a plotted ROC curve. This is useful in order to create lighter\n-        ROC curves.\n-\n-        .. versionadded:: 0.17\n-           parameter *drop_intermediate*.\n-\n-    Returns\n-    -------\n-    fpr : ndarray of shape (>2,)\n-        Increasing false positive rates such that element i is the false\n-        positive rate of predictions with score >= `thresholds[i]`.\n-\n-    tpr : ndarray of shape (>2,)\n-        Increasing true positive rates such that element `i` is the true\n-        positive rate of predictions with score >= `thresholds[i]`.\n-\n-    thresholds : ndarray of shape = (n_thresholds,)\n-        Decreasing thresholds on the decision function used to compute\n-        fpr and tpr. `thresholds[0]` represents no instances being predicted\n-        and is arbitrarily set to `max(y_score) + 1`.\n-\n-    See Also\n-    --------\n-    RocCurveDisplay.from_estimator : Plot Receiver Operating Characteristic\n-        (ROC) curve given an estimator and some data.\n-    RocCurveDisplay.from_predictions : Plot Receiver Operating Characteristic\n-        (ROC) curve given the true and predicted values.\n-    det_curve: Compute error rates for different probability thresholds.\n-    roc_auc_score : Compute the area under the ROC curve.\n-\n-    Notes\n-    -----\n-    Since the thresholds are sorted from low to high values, they\n-    are reversed upon returning them to ensure they correspond to both ``fpr``\n-    and ``tpr``, which are sorted in reversed order during their calculation.\n-\n-    References\n-    ----------\n-    .. [1] `Wikipedia entry for the Receiver operating characteristic\n-            <https://en.wikipedia.org/wiki/Receiver_operating_characteristic>`_\n-\n-    .. [2] Fawcett T. An introduction to ROC analysis[J]. Pattern Recognition\n-           Letters, 2006, 27(8):861-874.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn import metrics\n-    >>> y = np.array([1, 1, 2, 2])\n-    >>> scores = np.array([0.1, 0.4, 0.35, 0.8])\n-    >>> fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=2)\n-    >>> fpr\n-    array([0. , 0. , 0.5, 0.5, 1. ])\n-    >>> tpr\n-    array([0. , 0.5, 0.5, 1. , 1. ])\n-    >>> thresholds\n-    array([1.8 , 0.8 , 0.4 , 0.35, 0.1 ])\n-    \"\"\"\n-    fps, tps, thresholds = _binary_clf_curve(\n-        y_true, y_score, pos_label=pos_label, sample_weight=sample_weight\n-    )\n-\n-    # Attempt to drop thresholds corresponding to points in between and\n-    # collinear with other points. These are always suboptimal and do not\n-    # appear on a plotted ROC curve (and thus do not affect the AUC).\n-    # Here np.diff(_, 2) is used as a \"second derivative\" to tell if there\n-    # is a corner at the point. Both fps and tps must be tested to handle\n-    # thresholds with multiple data points (which are combined in\n-    # _binary_clf_curve). This keeps all cases where the point should be kept,\n-    # but does not drop more complicated cases like fps = [1, 3, 7],\n-    # tps = [1, 2, 4]; there is no harm in keeping too many thresholds.\n-    if drop_intermediate and len(fps) > 2:\n-        optimal_idxs = np.where(\n-            np.r_[True, np.logical_or(np.diff(fps, 2), np.diff(tps, 2)), True]\n-        )[0]\n-        fps = fps[optimal_idxs]\n-        tps = tps[optimal_idxs]\n-        thresholds = thresholds[optimal_idxs]\n-\n-    # Add an extra threshold position\n-    # to make sure that the curve starts at (0, 0)\n-    tps = np.r_[0, tps]\n-    fps = np.r_[0, fps]\n-    thresholds = np.r_[thresholds[0] + 1, thresholds]\n-\n-    if fps[-1] <= 0:\n-        warnings.warn(\n-            \"No negative samples in y_true, false positive value should be meaningless\",\n-            UndefinedMetricWarning,\n-        )\n-        fpr = np.repeat(np.nan, fps.shape)\n-    else:\n-        fpr = fps / fps[-1]\n-\n-    if tps[-1] <= 0:\n-        warnings.warn(\n-            \"No positive samples in y_true, true positive value should be meaningless\",\n-            UndefinedMetricWarning,\n-        )\n-        tpr = np.repeat(np.nan, tps.shape)\n-    else:\n-        tpr = tps / tps[-1]\n-\n-    return fpr, tpr, thresholds\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\", \"sparse matrix\"],\n-        \"y_score\": [\"array-like\"],\n-        \"sample_weight\": [\"array-like\", None],\n-    }\n-)\n-def label_ranking_average_precision_score(y_true, y_score, *, sample_weight=None):\n-    \"\"\"Compute ranking-based average precision.\n-\n-    Label ranking average precision (LRAP) is the average over each ground\n-    truth label assigned to each sample, of the ratio of true vs. total\n-    labels with lower score.\n-\n-    This metric is used in multilabel ranking problem, where the goal\n-    is to give better rank to the labels associated to each sample.\n-\n-    The obtained score is always strictly greater than 0 and\n-    the best value is 1.\n-\n-    Read more in the :ref:`User Guide <label_ranking_average_precision>`.\n-\n-    Parameters\n-    ----------\n-    y_true : {array-like, sparse matrix} of shape (n_samples, n_labels)\n-        True binary labels in binary indicator format.\n-\n-    y_score : array-like of shape (n_samples, n_labels)\n-        Target scores, can either be probability estimates of the positive\n-        class, confidence values, or non-thresholded measure of decisions\n-        (as returned by \"decision_function\" on some classifiers).\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-        .. versionadded:: 0.20\n-\n-    Returns\n-    -------\n-    score : float\n-        Ranking-based average precision score.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn.metrics import label_ranking_average_precision_score\n-    >>> y_true = np.array([[1, 0, 0], [0, 0, 1]])\n-    >>> y_score = np.array([[0.75, 0.5, 1], [1, 0.2, 0.1]])\n-    >>> label_ranking_average_precision_score(y_true, y_score)\n-    0.416...\n-    \"\"\"\n-    check_consistent_length(y_true, y_score, sample_weight)\n-    y_true = check_array(y_true, ensure_2d=False, accept_sparse=\"csr\")\n-    y_score = check_array(y_score, ensure_2d=False)\n-\n-    if y_true.shape != y_score.shape:\n-        raise ValueError(\"y_true and y_score have different shape\")\n-\n-    # Handle badly formatted array and the degenerate case with one label\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    if y_type != \"multilabel-indicator\" and not (\n-        y_type == \"binary\" and y_true.ndim == 2\n-    ):\n-        raise ValueError(\"{0} format is not supported\".format(y_type))\n-\n-    if not issparse(y_true):\n-        y_true = csr_matrix(y_true)\n-\n-    y_score = -y_score\n-\n-    n_samples, n_labels = y_true.shape\n-\n-    out = 0.0\n-    for i, (start, stop) in enumerate(zip(y_true.indptr, y_true.indptr[1:])):\n-        relevant = y_true.indices[start:stop]\n-\n-        if relevant.size == 0 or relevant.size == n_labels:\n-            # If all labels are relevant or unrelevant, the score is also\n-            # equal to 1. The label ranking has no meaning.\n-            aux = 1.0\n-        else:\n-            scores_i = y_score[i]\n-            rank = rankdata(scores_i, \"max\")[relevant]\n-            L = rankdata(scores_i[relevant], \"max\")\n-            aux = (L / rank).mean()\n-\n-        if sample_weight is not None:\n-            aux = aux * sample_weight[i]\n-        out += aux\n-\n-    if sample_weight is None:\n-        out /= n_samples\n-    else:\n-        out /= np.sum(sample_weight)\n-\n-    return out\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"sample_weight\": [\"array-like\", None],\n-    }\n-)\n-def coverage_error(y_true, y_score, *, sample_weight=None):\n-    \"\"\"Coverage error measure.\n-\n-    Compute how far we need to go through the ranked scores to cover all\n-    true labels. The best value is equal to the average number\n-    of labels in ``y_true`` per sample.\n-\n-    Ties in ``y_scores`` are broken by giving maximal rank that would have\n-    been assigned to all tied values.\n-\n-    Note: Our implementation's score is 1 greater than the one given in\n-    Tsoumakas et al., 2010. This extends it to handle the degenerate case\n-    in which an instance has 0 true labels.\n-\n-    Read more in the :ref:`User Guide <coverage_error>`.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples, n_labels)\n-        True binary labels in binary indicator format.\n-\n-    y_score : array-like of shape (n_samples, n_labels)\n-        Target scores, can either be probability estimates of the positive\n-        class, confidence values, or non-thresholded measure of decisions\n-        (as returned by \"decision_function\" on some classifiers).\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    Returns\n-    -------\n-    coverage_error : float\n-        The coverage error.\n-\n-    References\n-    ----------\n-    .. [1] Tsoumakas, G., Katakis, I., & Vlahavas, I. (2010).\n-           Mining multi-label data. In Data mining and knowledge discovery\n-           handbook (pp. 667-685). Springer US.\n-    \"\"\"\n-    y_true = check_array(y_true, ensure_2d=True)\n-    y_score = check_array(y_score, ensure_2d=True)\n-    check_consistent_length(y_true, y_score, sample_weight)\n-\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    if y_type != \"multilabel-indicator\":\n-        raise ValueError(\"{0} format is not supported\".format(y_type))\n-\n-    if y_true.shape != y_score.shape:\n-        raise ValueError(\"y_true and y_score have different shape\")\n-\n-    y_score_mask = np.ma.masked_array(y_score, mask=np.logical_not(y_true))\n-    y_min_relevant = y_score_mask.min(axis=1).reshape((-1, 1))\n-    coverage = (y_score >= y_min_relevant).sum(axis=1)\n-    coverage = coverage.filled(0)\n-\n-    return np.average(coverage, weights=sample_weight)\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\", \"sparse matrix\"],\n-        \"y_score\": [\"array-like\"],\n-        \"sample_weight\": [\"array-like\", None],\n-    }\n-)\n-def label_ranking_loss(y_true, y_score, *, sample_weight=None):\n-    \"\"\"Compute Ranking loss measure.\n-\n-    Compute the average number of label pairs that are incorrectly ordered\n-    given y_score weighted by the size of the label set and the number of\n-    labels not in the label set.\n-\n-    This is similar to the error set size, but weighted by the number of\n-    relevant and irrelevant labels. The best performance is achieved with\n-    a ranking loss of zero.\n-\n-    Read more in the :ref:`User Guide <label_ranking_loss>`.\n-\n-    .. versionadded:: 0.17\n-       A function *label_ranking_loss*\n-\n-    Parameters\n-    ----------\n-    y_true : {array-like, sparse matrix} of shape (n_samples, n_labels)\n-        True binary labels in binary indicator format.\n-\n-    y_score : array-like of shape (n_samples, n_labels)\n-        Target scores, can either be probability estimates of the positive\n-        class, confidence values, or non-thresholded measure of decisions\n-        (as returned by \"decision_function\" on some classifiers).\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights.\n-\n-    Returns\n-    -------\n-    loss : float\n-        Average number of label pairs that are incorrectly ordered given\n-        y_score weighted by the size of the label set and the number of labels not\n-        in the label set.\n-\n-    References\n-    ----------\n-    .. [1] Tsoumakas, G., Katakis, I., & Vlahavas, I. (2010).\n-           Mining multi-label data. In Data mining and knowledge discovery\n-           handbook (pp. 667-685). Springer US.\n-    \"\"\"\n-    y_true = check_array(y_true, ensure_2d=False, accept_sparse=\"csr\")\n-    y_score = check_array(y_score, ensure_2d=False)\n-    check_consistent_length(y_true, y_score, sample_weight)\n-\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    if y_type not in (\"multilabel-indicator\",):\n-        raise ValueError(\"{0} format is not supported\".format(y_type))\n-\n-    if y_true.shape != y_score.shape:\n-        raise ValueError(\"y_true and y_score have different shape\")\n-\n-    n_samples, n_labels = y_true.shape\n-\n-    y_true = csr_matrix(y_true)\n-\n-    loss = np.zeros(n_samples)\n-    for i, (start, stop) in enumerate(zip(y_true.indptr, y_true.indptr[1:])):\n-        # Sort and bin the label scores\n-        unique_scores, unique_inverse = np.unique(y_score[i], return_inverse=True)\n-        true_at_reversed_rank = np.bincount(\n-            unique_inverse[y_true.indices[start:stop]], minlength=len(unique_scores)\n-        )\n-        all_at_reversed_rank = np.bincount(unique_inverse, minlength=len(unique_scores))\n-        false_at_reversed_rank = all_at_reversed_rank - true_at_reversed_rank\n-\n-        # if the scores are ordered, it's possible to count the number of\n-        # incorrectly ordered paires in linear time by cumulatively counting\n-        # how many false labels of a given score have a score higher than the\n-        # accumulated true labels with lower score.\n-        loss[i] = np.dot(true_at_reversed_rank.cumsum(), false_at_reversed_rank)\n-\n-    n_positives = count_nonzero(y_true, axis=1)\n-    with np.errstate(divide=\"ignore\", invalid=\"ignore\"):\n-        loss /= (n_labels - n_positives) * n_positives\n-\n-    # When there is no positive or no negative labels, those values should\n-    # be consider as correct, i.e. the ranking doesn't matter.\n-    loss[np.logical_or(n_positives == 0, n_positives == n_labels)] = 0.0\n-\n-    return np.average(loss, weights=sample_weight)\n-\n-\n-def _dcg_sample_scores(y_true, y_score, k=None, log_base=2, ignore_ties=False):\n-    \"\"\"Compute Discounted Cumulative Gain.\n-\n-    Sum the true scores ranked in the order induced by the predicted scores,\n-    after applying a logarithmic discount.\n-\n-    This ranking metric yields a high value if true labels are ranked high by\n-    ``y_score``.\n-\n-    Parameters\n-    ----------\n-    y_true : ndarray of shape (n_samples, n_labels)\n-        True targets of multilabel classification, or true scores of entities\n-        to be ranked.\n-\n-    y_score : ndarray of shape (n_samples, n_labels)\n-        Target scores, can either be probability estimates, confidence values,\n-        or non-thresholded measure of decisions (as returned by\n-        \"decision_function\" on some classifiers).\n-\n-    k : int, default=None\n-        Only consider the highest k scores in the ranking. If `None`, use all\n-        outputs.\n-\n-    log_base : float, default=2\n-        Base of the logarithm used for the discount. A low value means a\n-        sharper discount (top results are more important).\n-\n-    ignore_ties : bool, default=False\n-        Assume that there are no ties in y_score (which is likely to be the\n-        case if y_score is continuous) for efficiency gains.\n-\n-    Returns\n-    -------\n-    discounted_cumulative_gain : ndarray of shape (n_samples,)\n-        The DCG score for each sample.\n-\n-    See Also\n-    --------\n-    ndcg_score : The Discounted Cumulative Gain divided by the Ideal Discounted\n-        Cumulative Gain (the DCG obtained for a perfect ranking), in order to\n-        have a score between 0 and 1.\n-    \"\"\"\n-    discount = 1 / (np.log(np.arange(y_true.shape[1]) + 2) / np.log(log_base))\n-    if k is not None:\n-        discount[k:] = 0\n-    if ignore_ties:\n-        ranking = np.argsort(y_score)[:, ::-1]\n-        ranked = y_true[np.arange(ranking.shape[0])[:, np.newaxis], ranking]\n-        cumulative_gains = discount.dot(ranked.T)\n-    else:\n-        discount_cumsum = np.cumsum(discount)\n-        cumulative_gains = [\n-            _tie_averaged_dcg(y_t, y_s, discount_cumsum)\n-            for y_t, y_s in zip(y_true, y_score)\n-        ]\n-        cumulative_gains = np.asarray(cumulative_gains)\n-    return cumulative_gains\n-\n-\n-def _tie_averaged_dcg(y_true, y_score, discount_cumsum):\n-    \"\"\"\n-    Compute DCG by averaging over possible permutations of ties.\n-\n-    The gain (`y_true`) of an index falling inside a tied group (in the order\n-    induced by `y_score`) is replaced by the average gain within this group.\n-    The discounted gain for a tied group is then the average `y_true` within\n-    this group times the sum of discounts of the corresponding ranks.\n-\n-    This amounts to averaging scores for all possible orderings of the tied\n-    groups.\n-\n-    (note in the case of dcg@k the discount is 0 after index k)\n-\n-    Parameters\n-    ----------\n-    y_true : ndarray\n-        The true relevance scores.\n-\n-    y_score : ndarray\n-        Predicted scores.\n-\n-    discount_cumsum : ndarray\n-        Precomputed cumulative sum of the discounts.\n-\n-    Returns\n-    -------\n-    discounted_cumulative_gain : float\n-        The discounted cumulative gain.\n-\n-    References\n-    ----------\n-    McSherry, F., & Najork, M. (2008, March). Computing information retrieval\n-    performance measures efficiently in the presence of tied scores. In\n-    European conference on information retrieval (pp. 414-421). Springer,\n-    Berlin, Heidelberg.\n-    \"\"\"\n-    _, inv, counts = np.unique(-y_score, return_inverse=True, return_counts=True)\n-    ranked = np.zeros(len(counts))\n-    np.add.at(ranked, inv, y_true)\n-    ranked /= counts\n-    groups = np.cumsum(counts) - 1\n-    discount_sums = np.empty(len(counts))\n-    discount_sums[0] = discount_cumsum[groups[0]]\n-    discount_sums[1:] = np.diff(discount_cumsum[groups])\n-    return (ranked * discount_sums).sum()\n-\n-\n-def _check_dcg_target_type(y_true):\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    supported_fmt = (\n-        \"multilabel-indicator\",\n-        \"continuous-multioutput\",\n-        \"multiclass-multioutput\",\n-    )\n-    if y_type not in supported_fmt:\n-        raise ValueError(\n-            \"Only {} formats are supported. Got {} instead\".format(\n-                supported_fmt, y_type\n-            )\n-        )\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"k\": [Interval(Integral, 1, None, closed=\"left\"), None],\n-        \"log_base\": [Interval(Real, 0.0, None, closed=\"neither\")],\n-        \"sample_weight\": [\"array-like\", None],\n-        \"ignore_ties\": [\"boolean\"],\n-    }\n-)\n-def dcg_score(\n-    y_true, y_score, *, k=None, log_base=2, sample_weight=None, ignore_ties=False\n-):\n-    \"\"\"Compute Discounted Cumulative Gain.\n-\n-    Sum the true scores ranked in the order induced by the predicted scores,\n-    after applying a logarithmic discount.\n-\n-    This ranking metric yields a high value if true labels are ranked high by\n-    ``y_score``.\n-\n-    Usually the Normalized Discounted Cumulative Gain (NDCG, computed by\n-    ndcg_score) is preferred.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples, n_labels)\n-        True targets of multilabel classification, or true scores of entities\n-        to be ranked.\n-\n-    y_score : array-like of shape (n_samples, n_labels)\n-        Target scores, can either be probability estimates, confidence values,\n-        or non-thresholded measure of decisions (as returned by\n-        \"decision_function\" on some classifiers).\n-\n-    k : int, default=None\n-        Only consider the highest k scores in the ranking. If None, use all\n-        outputs.\n-\n-    log_base : float, default=2\n-        Base of the logarithm used for the discount. A low value means a\n-        sharper discount (top results are more important).\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights. If `None`, all samples are given the same weight.\n-\n-    ignore_ties : bool, default=False\n-        Assume that there are no ties in y_score (which is likely to be the\n-        case if y_score is continuous) for efficiency gains.\n-\n-    Returns\n-    -------\n-    discounted_cumulative_gain : float\n-        The averaged sample DCG scores.\n-\n-    See Also\n-    --------\n-    ndcg_score : The Discounted Cumulative Gain divided by the Ideal Discounted\n-        Cumulative Gain (the DCG obtained for a perfect ranking), in order to\n-        have a score between 0 and 1.\n-\n-    References\n-    ----------\n-    `Wikipedia entry for Discounted Cumulative Gain\n-    <https://en.wikipedia.org/wiki/Discounted_cumulative_gain>`_.\n-\n-    Jarvelin, K., & Kekalainen, J. (2002).\n-    Cumulated gain-based evaluation of IR techniques. ACM Transactions on\n-    Information Systems (TOIS), 20(4), 422-446.\n-\n-    Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\n-    A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\n-    Annual Conference on Learning Theory (COLT 2013).\n-\n-    McSherry, F., & Najork, M. (2008, March). Computing information retrieval\n-    performance measures efficiently in the presence of tied scores. In\n-    European conference on information retrieval (pp. 414-421). Springer,\n-    Berlin, Heidelberg.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn.metrics import dcg_score\n-    >>> # we have groud-truth relevance of some answers to a query:\n-    >>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n-    >>> # we predict scores for the answers\n-    >>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n-    >>> dcg_score(true_relevance, scores)\n-    9.49...\n-    >>> # we can set k to truncate the sum; only top k answers contribute\n-    >>> dcg_score(true_relevance, scores, k=2)\n-    5.63...\n-    >>> # now we have some ties in our prediction\n-    >>> scores = np.asarray([[1, 0, 0, 0, 1]])\n-    >>> # by default ties are averaged, so here we get the average true\n-    >>> # relevance of our top predictions: (10 + 5) / 2 = 7.5\n-    >>> dcg_score(true_relevance, scores, k=1)\n-    7.5\n-    >>> # we can choose to ignore ties for faster results, but only\n-    >>> # if we know there aren't ties in our scores, otherwise we get\n-    >>> # wrong results:\n-    >>> dcg_score(true_relevance,\n-    ...           scores, k=1, ignore_ties=True)\n-    5.0\n-    \"\"\"\n-    y_true = check_array(y_true, ensure_2d=False)\n-    y_score = check_array(y_score, ensure_2d=False)\n-    check_consistent_length(y_true, y_score, sample_weight)\n-    _check_dcg_target_type(y_true)\n-    return np.average(\n-        _dcg_sample_scores(\n-            y_true, y_score, k=k, log_base=log_base, ignore_ties=ignore_ties\n-        ),\n-        weights=sample_weight,\n-    )\n-\n-\n-def _ndcg_sample_scores(y_true, y_score, k=None, ignore_ties=False):\n-    \"\"\"Compute Normalized Discounted Cumulative Gain.\n-\n-    Sum the true scores ranked in the order induced by the predicted scores,\n-    after applying a logarithmic discount. Then divide by the best possible\n-    score (Ideal DCG, obtained for a perfect ranking) to obtain a score between\n-    0 and 1.\n-\n-    This ranking metric yields a high value if true labels are ranked high by\n-    ``y_score``.\n-\n-    Parameters\n-    ----------\n-    y_true : ndarray of shape (n_samples, n_labels)\n-        True targets of multilabel classification, or true scores of entities\n-        to be ranked.\n-\n-    y_score : ndarray of shape (n_samples, n_labels)\n-        Target scores, can either be probability estimates, confidence values,\n-        or non-thresholded measure of decisions (as returned by\n-        \"decision_function\" on some classifiers).\n-\n-    k : int, default=None\n-        Only consider the highest k scores in the ranking. If None, use all\n-        outputs.\n-\n-    ignore_ties : bool, default=False\n-        Assume that there are no ties in y_score (which is likely to be the\n-        case if y_score is continuous) for efficiency gains.\n-\n-    Returns\n-    -------\n-    normalized_discounted_cumulative_gain : ndarray of shape (n_samples,)\n-        The NDCG score for each sample (float in [0., 1.]).\n-\n-    See Also\n-    --------\n-    dcg_score : Discounted Cumulative Gain (not normalized).\n-\n-    \"\"\"\n-    gain = _dcg_sample_scores(y_true, y_score, k, ignore_ties=ignore_ties)\n-    # Here we use the order induced by y_true so we can ignore ties since\n-    # the gain associated to tied indices is the same (permuting ties doesn't\n-    # change the value of the re-ordered y_true)\n-    normalizing_gain = _dcg_sample_scores(y_true, y_true, k, ignore_ties=True)\n-    all_irrelevant = normalizing_gain == 0\n-    gain[all_irrelevant] = 0\n-    gain[~all_irrelevant] /= normalizing_gain[~all_irrelevant]\n-    return gain\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"k\": [Interval(Integral, 1, None, closed=\"left\"), None],\n-        \"sample_weight\": [\"array-like\", None],\n-        \"ignore_ties\": [\"boolean\"],\n-    }\n-)\n-def ndcg_score(y_true, y_score, *, k=None, sample_weight=None, ignore_ties=False):\n-    \"\"\"Compute Normalized Discounted Cumulative Gain.\n-\n-    Sum the true scores ranked in the order induced by the predicted scores,\n-    after applying a logarithmic discount. Then divide by the best possible\n-    score (Ideal DCG, obtained for a perfect ranking) to obtain a score between\n-    0 and 1.\n-\n-    This ranking metric returns a high value if true labels are ranked high by\n-    ``y_score``.\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples, n_labels)\n-        True targets of multilabel classification, or true scores of entities\n-        to be ranked. Negative values in `y_true` may result in an output\n-        that is not between 0 and 1.\n-\n-        .. versionchanged:: 1.2\n-            These negative values are deprecated, and will raise an error in v1.4.\n-\n-    y_score : array-like of shape (n_samples, n_labels)\n-        Target scores, can either be probability estimates, confidence values,\n-        or non-thresholded measure of decisions (as returned by\n-        \"decision_function\" on some classifiers).\n-\n-    k : int, default=None\n-        Only consider the highest k scores in the ranking. If `None`, use all\n-        outputs.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights. If `None`, all samples are given the same weight.\n-\n-    ignore_ties : bool, default=False\n-        Assume that there are no ties in y_score (which is likely to be the\n-        case if y_score is continuous) for efficiency gains.\n-\n-    Returns\n-    -------\n-    normalized_discounted_cumulative_gain : float in [0., 1.]\n-        The averaged NDCG scores for all samples.\n-\n-    See Also\n-    --------\n-    dcg_score : Discounted Cumulative Gain (not normalized).\n-\n-    References\n-    ----------\n-    `Wikipedia entry for Discounted Cumulative Gain\n-    <https://en.wikipedia.org/wiki/Discounted_cumulative_gain>`_\n-\n-    Jarvelin, K., & Kekalainen, J. (2002).\n-    Cumulated gain-based evaluation of IR techniques. ACM Transactions on\n-    Information Systems (TOIS), 20(4), 422-446.\n-\n-    Wang, Y., Wang, L., Li, Y., He, D., Chen, W., & Liu, T. Y. (2013, May).\n-    A theoretical analysis of NDCG ranking measures. In Proceedings of the 26th\n-    Annual Conference on Learning Theory (COLT 2013)\n-\n-    McSherry, F., & Najork, M. (2008, March). Computing information retrieval\n-    performance measures efficiently in the presence of tied scores. In\n-    European conference on information retrieval (pp. 414-421). Springer,\n-    Berlin, Heidelberg.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn.metrics import ndcg_score\n-    >>> # we have groud-truth relevance of some answers to a query:\n-    >>> true_relevance = np.asarray([[10, 0, 0, 1, 5]])\n-    >>> # we predict some scores (relevance) for the answers\n-    >>> scores = np.asarray([[.1, .2, .3, 4, 70]])\n-    >>> ndcg_score(true_relevance, scores)\n-    0.69...\n-    >>> scores = np.asarray([[.05, 1.1, 1., .5, .0]])\n-    >>> ndcg_score(true_relevance, scores)\n-    0.49...\n-    >>> # we can set k to truncate the sum; only top k answers contribute.\n-    >>> ndcg_score(true_relevance, scores, k=4)\n-    0.35...\n-    >>> # the normalization takes k into account so a perfect answer\n-    >>> # would still get 1.0\n-    >>> ndcg_score(true_relevance, true_relevance, k=4)\n-    1.0...\n-    >>> # now we have some ties in our prediction\n-    >>> scores = np.asarray([[1, 0, 0, 0, 1]])\n-    >>> # by default ties are averaged, so here we get the average (normalized)\n-    >>> # true relevance of our top predictions: (10 / 10 + 5 / 10) / 2 = .75\n-    >>> ndcg_score(true_relevance, scores, k=1)\n-    0.75...\n-    >>> # we can choose to ignore ties for faster results, but only\n-    >>> # if we know there aren't ties in our scores, otherwise we get\n-    >>> # wrong results:\n-    >>> ndcg_score(true_relevance,\n-    ...           scores, k=1, ignore_ties=True)\n-    0.5...\n-    \"\"\"\n-    y_true = check_array(y_true, ensure_2d=False)\n-    y_score = check_array(y_score, ensure_2d=False)\n-    check_consistent_length(y_true, y_score, sample_weight)\n-\n-    if y_true.min() < 0:\n-        # TODO(1.4): Replace warning w/ ValueError\n-        warnings.warn(\n-            (\n-                \"ndcg_score should not be used on negative y_true values. ndcg_score\"\n-                \" will raise a ValueError on negative y_true values starting from\"\n-                \" version 1.4.\"\n-            ),\n-            FutureWarning,\n-        )\n-    if y_true.ndim > 1 and y_true.shape[1] <= 1:\n-        raise ValueError(\n-            \"Computing NDCG is only meaningful when there is more than 1 document. \"\n-            f\"Got {y_true.shape[1]} instead.\"\n-        )\n-    _check_dcg_target_type(y_true)\n-    gain = _ndcg_sample_scores(y_true, y_score, k=k, ignore_ties=ignore_ties)\n-    return np.average(gain, weights=sample_weight)\n-\n-\n-@validate_params(\n-    {\n-        \"y_true\": [\"array-like\"],\n-        \"y_score\": [\"array-like\"],\n-        \"k\": [Interval(Integral, 1, None, closed=\"left\")],\n-        \"normalize\": [\"boolean\"],\n-        \"sample_weight\": [\"array-like\", None],\n-        \"labels\": [\"array-like\", None],\n-    }\n-)\n-def top_k_accuracy_score(\n-    y_true, y_score, *, k=2, normalize=True, sample_weight=None, labels=None\n-):\n-    \"\"\"Top-k Accuracy classification score.\n-\n-    This metric computes the number of times where the correct label is among\n-    the top `k` labels predicted (ranked by predicted scores). Note that the\n-    multilabel case isn't covered here.\n-\n-    Read more in the :ref:`User Guide <top_k_accuracy_score>`\n-\n-    Parameters\n-    ----------\n-    y_true : array-like of shape (n_samples,)\n-        True labels.\n-\n-    y_score : array-like of shape (n_samples,) or (n_samples, n_classes)\n-        Target scores. These can be either probability estimates or\n-        non-thresholded decision values (as returned by\n-        :term:`decision_function` on some classifiers).\n-        The binary case expects scores with shape (n_samples,) while the\n-        multiclass case expects scores with shape (n_samples, n_classes).\n-        In the multiclass case, the order of the class scores must\n-        correspond to the order of ``labels``, if provided, or else to\n-        the numerical or lexicographical order of the labels in ``y_true``.\n-        If ``y_true`` does not contain all the labels, ``labels`` must be\n-        provided.\n-\n-    k : int, default=2\n-        Number of most likely outcomes considered to find the correct label.\n-\n-    normalize : bool, default=True\n-        If `True`, return the fraction of correctly classified samples.\n-        Otherwise, return the number of correctly classified samples.\n-\n-    sample_weight : array-like of shape (n_samples,), default=None\n-        Sample weights. If `None`, all samples are given the same weight.\n-\n-    labels : array-like of shape (n_classes,), default=None\n-        Multiclass only. List of labels that index the classes in ``y_score``.\n-        If ``None``, the numerical or lexicographical order of the labels in\n-        ``y_true`` is used. If ``y_true`` does not contain all the labels,\n-        ``labels`` must be provided.\n-\n-    Returns\n-    -------\n-    score : float\n-        The top-k accuracy score. The best performance is 1 with\n-        `normalize == True` and the number of samples with\n-        `normalize == False`.\n-\n-    See Also\n-    --------\n-    accuracy_score : Compute the accuracy score. By default, the function will\n-        return the fraction of correct predictions divided by the total number\n-        of predictions.\n-\n-    Notes\n-    -----\n-    In cases where two or more labels are assigned equal predicted scores,\n-    the labels with the highest indices will be chosen first. This might\n-    impact the result if the correct label falls after the threshold because\n-    of that.\n-\n-    Examples\n-    --------\n-    >>> import numpy as np\n-    >>> from sklearn.metrics import top_k_accuracy_score\n-    >>> y_true = np.array([0, 1, 2, 2])\n-    >>> y_score = np.array([[0.5, 0.2, 0.2],  # 0 is in top 2\n-    ...                     [0.3, 0.4, 0.2],  # 1 is in top 2\n-    ...                     [0.2, 0.4, 0.3],  # 2 is in top 2\n-    ...                     [0.7, 0.2, 0.1]]) # 2 isn't in top 2\n-    >>> top_k_accuracy_score(y_true, y_score, k=2)\n-    0.75\n-    >>> # Not normalizing gives the number of \"correctly\" classified samples\n-    >>> top_k_accuracy_score(y_true, y_score, k=2, normalize=False)\n-    3\n-    \"\"\"\n-    y_true = check_array(y_true, ensure_2d=False, dtype=None)\n-    y_true = column_or_1d(y_true)\n-    y_type = type_of_target(y_true, input_name=\"y_true\")\n-    if y_type == \"binary\" and labels is not None and len(labels) > 2:\n-        y_type = \"multiclass\"\n-    if y_type not in {\"binary\", \"multiclass\"}:\n-        raise ValueError(\n-            f\"y type must be 'binary' or 'multiclass', got '{y_type}' instead.\"\n-        )\n-    y_score = check_array(y_score, ensure_2d=False)\n-    if y_type == \"binary\":\n-        if y_score.ndim == 2 and y_score.shape[1] != 1:\n-            raise ValueError(\n-                \"`y_true` is binary while y_score is 2d with\"\n-                f\" {y_score.shape[1]} classes. If `y_true` does not contain all the\"\n-                \" labels, `labels` must be provided.\"\n-            )\n-        y_score = column_or_1d(y_score)\n-\n-    check_consistent_length(y_true, y_score, sample_weight)\n-    y_score_n_classes = y_score.shape[1] if y_score.ndim == 2 else 2\n-\n-    if labels is None:\n-        classes = _unique(y_true)\n-        n_classes = len(classes)\n-\n-        if n_classes != y_score_n_classes:\n-            raise ValueError(\n-                f\"Number of classes in 'y_true' ({n_classes}) not equal \"\n-                f\"to the number of classes in 'y_score' ({y_score_n_classes}).\"\n-                \"You can provide a list of all known classes by assigning it \"\n-                \"to the `labels` parameter.\"\n-            )\n-    else:\n-        labels = column_or_1d(labels)\n-        classes = _unique(labels)\n-        n_labels = len(labels)\n-        n_classes = len(classes)\n-\n-        if n_classes != n_labels:\n-            raise ValueError(\"Parameter 'labels' must be unique.\")\n-\n-        if not np.array_equal(classes, labels):\n-            raise ValueError(\"Parameter 'labels' must be ordered.\")\n-\n-        if n_classes != y_score_n_classes:\n-            raise ValueError(\n-                f\"Number of given labels ({n_classes}) not equal to the \"\n-                f\"number of classes in 'y_score' ({y_score_n_classes}).\"\n-            )\n-\n-        if len(np.setdiff1d(y_true, classes)):\n-            raise ValueError(\"'y_true' contains labels not in parameter 'labels'.\")\n-\n-    if k >= n_classes:\n-        warnings.warn(\n-            (\n-                f\"'k' ({k}) greater than or equal to 'n_classes' ({n_classes}) \"\n-                \"will result in a perfect score and is therefore meaningless.\"\n-            ),\n-            UndefinedMetricWarning,\n-        )\n-\n-    y_true_encoded = _encode(y_true, uniques=classes)\n-\n-    if y_type == \"binary\":\n-        if k == 1:\n-            threshold = 0.5 if y_score.min() >= 0 and y_score.max() <= 1 else 0\n-            y_pred = (y_score > threshold).astype(np.int64)\n-            hits = y_pred == y_true_encoded\n-        else:\n-            hits = np.ones_like(y_score, dtype=np.bool_)\n-    elif y_type == \"multiclass\":\n-        sorted_pred = np.argsort(y_score, axis=1, kind=\"mergesort\")[:, ::-1]\n-        hits = (y_true_encoded == sorted_pred[:, :k].T).any(axis=0)\n-\n-    if normalize:\n-        return np.average(hits, weights=sample_weight)\n-    elif sample_weight is None:\n-        return np.sum(hits)\n-    else:\n-        return np.dot(hits, sample_weight)\n+if thresholds.max() > 1:\n+    thresholds = np.clip(thresholds, 0, 1)\n\\ No newline at end of file\n"}
{"instance_id": "scikit-learn__scikit-learn-26323", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/compose/_column_transformer.py b/sklearn/compose/_column_transformer.py\nindex 4eddd12b1b..f38a7f32cb 100644\n--- a/sklearn/compose/_column_transformer.py\n+++ b/sklearn/compose/_column_transformer.py\n@@ -296,7 +296,9 @@ class ColumnTransformer(TransformerMixin, _BaseComposition):\n         transformers = (\n             trans\n             for _, trans, _ in chain(\n-                self.transformers, getattr(self, \"transformers_\", [])\n+                self.transformers,\n+                getattr(self, \"transformers_\", []),\n+                [(\"remainder\", self.remainder, None)],\n             )\n             if trans not in {\"passthrough\", \"drop\"}\n         )\n", "model": "claude-sonnet-5-5", "steps": 5, "finished": true, "patch_lines": 15, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 15, "steps": 5}], "ms": 13692}
{"instance_id": "scikit-learn__scikit-learn-9288", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/cluster/k_means_.py b/sklearn/cluster/k_means_.py\nindex b7fbdf7da3..e579414fc1 100644\n--- a/sklearn/cluster/k_means_.py\n+++ b/sklearn/cluster/k_means_.py\n@@ -360,16 +360,18 @@ def k_means(X, n_clusters, sample_weight=None, init='k-means++',\n     else:\n         raise ValueError(\"Algorithm must be 'auto', 'full' or 'elkan', got\"\n                          \" %s\" % str(algorithm))\n+    # Draw the seeds up front so results do not depend on n_jobs\n+    seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)\n     if effective_n_jobs(n_jobs) == 1:\n         # For a single thread, less memory is needed if we just store one set\n         # of the best results (as opposed to one set per run per thread).\n-        for it in range(n_init):\n+        for seed in seeds:\n             # run a k-means once\n             labels, inertia, centers, n_iter_ = kmeans_single(\n                 X, sample_weight, n_clusters, max_iter=max_iter, init=init,\n                 verbose=verbose, precompute_distances=precompute_distances,\n                 tol=tol, x_squared_norms=x_squared_norms,\n-                random_state=random_state)\n+                random_state=seed)\n             # determine if these results are the best so far\n             if best_inertia is None or inertia < best_inertia:\n                 best_labels = labels.copy()\n@@ -378,7 +380,6 @@ def k_means(X, n_clusters, sample_weight=None, init='k-means++',\n                 best_n_iter = n_iter_\n     else:\n         # parallelisation of k-means runs\n-        seeds = random_state.randint(np.iinfo(np.int32).max, size=n_init)\n         results = Parallel(n_jobs=n_jobs, verbose=0)(\n             delayed(kmeans_single)(X, sample_weight, n_clusters,\n                                    max_iter=max_iter, init=init,\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 33, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 33, "steps": 9}], "ms": 20953}
{"instance_id": "matplotlib__matplotlib-13989", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py\nindex 4b73d52293..bc5461ad9f 100644\n--- a/lib/matplotlib/axes/_axes.py\n+++ b/lib/matplotlib/axes/_axes.py\n@@ -6686,7 +6686,7 @@ optional.\n \n         density = bool(density) or bool(normed)\n         if density and not stacked:\n-            hist_kwargs = dict(density=density)\n+            hist_kwargs['density'] = density\n \n         # List to store all the top coordinates of the histograms\n         tops = []\n", "model": "claude-sonnet-5-5", "steps": 4, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 4}], "ms": 12206}
