{"instance_id": "scikit-learn__scikit-learn-13439", "model_name_or_path": "cain-70b-e124", "model_patch": "diff --git a/sklearn/pipeline.py b/sklearn/pipeline.py\nindex 7eaf9a46f0..d59ee8aa79 100644\n--- a/sklearn/pipeline.py\n+++ b/sklearn/pipeline.py\n@@ -1,931 +1,5 @@\n-\"\"\"\n-The :mod:`sklearn.pipeline` module implements utilities to build a composite\n-estimator, as a chain of transforms and estimators.\n-\"\"\"\n-# Author: Edouard Duchesnay\n-#         Gael Varoquaux\n-#         Virgile Fritsch\n-#         Alexandre Gramfort\n-#         Lars Buitinck\n-# License: BSD\n-\n-from collections import defaultdict\n-from itertools import islice\n-\n-import numpy as np\n-from scipy import sparse\n-\n-from .base import clone, TransformerMixin\n-from .utils._joblib import Parallel, delayed\n-from .utils.metaestimators import if_delegate_has_method\n-from .utils import Bunch\n-from .utils.validation import check_memory\n-\n-from .utils.metaestimators import _BaseComposition\n-\n-__all__ = ['Pipeline', 'FeatureUnion', 'make_pipeline', 'make_union']\n-\n-\n-class Pipeline(_BaseComposition):\n-    \"\"\"Pipeline of transforms with a final estimator.\n-\n-    Sequentially apply a list of transforms and a final estimator.\n-    Intermediate steps of the pipeline must be 'transforms', that is, they\n-    must implement fit and transform methods.\n-    The final estimator only needs to implement fit.\n-    The transformers in the pipeline can be cached using ``memory`` argument.\n-\n-    The purpose of the pipeline is to assemble several steps that can be\n-    cross-validated together while setting different parameters.\n-    For this, it enables setting parameters of the various steps using their\n-    names and the parameter name separated by a '__', as in the example below.\n-    A step's estimator may be replaced entirely by setting the parameter\n-    with its name to another estimator, or a transformer removed by setting\n-    it to 'passthrough' or ``None``.\n-\n-    Read more in the :ref:`User Guide <pipeline>`.\n-\n-    Parameters\n-    ----------\n-    steps : list\n-        List of (name, transform) tuples (implementing fit/transform) that are\n-        chained, in the order in which they are chained, with the last object\n-        an estimator.\n-\n-    memory : None, str or object with the joblib.Memory interface, optional\n-        Used to cache the fitted transformers of the pipeline. By default,\n-        no caching is performed. If a string is given, it is the path to\n-        the caching directory. Enabling caching triggers a clone of\n-        the transformers before fitting. Therefore, the transformer\n-        instance given to the pipeline cannot be inspected\n-        directly. Use the attribute ``named_steps`` or ``steps`` to\n-        inspect estimators within the pipeline. Caching the\n-        transformers is advantageous when fitting is time consuming.\n-\n-    Attributes\n-    ----------\n-    named_steps : bunch object, a dictionary with attribute access\n-        Read-only attribute to access any step parameter by user given name.\n-        Keys are step names and values are steps parameters.\n-\n-    See also\n-    --------\n-    sklearn.pipeline.make_pipeline : convenience function for simplified\n-        pipeline construction.\n-\n-    Examples\n-    --------\n-    >>> from sklearn import svm\n-    >>> from sklearn.datasets import samples_generator\n-    >>> from sklearn.feature_selection import SelectKBest\n-    >>> from sklearn.feature_selection import f_regression\n-    >>> from sklearn.pipeline import Pipeline\n-    >>> # generate some data to play with\n-    >>> X, y = samples_generator.make_classification(\n-    ...     n_informative=5, n_redundant=0, random_state=42)\n-    >>> # ANOVA SVM-C\n-    >>> anova_filter = SelectKBest(f_regression, k=5)\n-    >>> clf = svm.SVC(kernel='linear')\n-    >>> anova_svm = Pipeline([('anova', anova_filter), ('svc', clf)])\n-    >>> # You can set the parameters using the names issued\n-    >>> # For instance, fit using a k of 10 in the SelectKBest\n-    >>> # and a parameter 'C' of the svm\n-    >>> anova_svm.set_params(anova__k=10, svc__C=.1).fit(X, y)\n-    ...                      # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n-    Pipeline(memory=None,\n-             steps=[('anova', SelectKBest(...)),\n-                    ('svc', SVC(...))])\n-    >>> prediction = anova_svm.predict(X)\n-    >>> anova_svm.score(X, y)                        # doctest: +ELLIPSIS\n-    0.83\n-    >>> # getting the selected features chosen by anova_filter\n-    >>> anova_svm['anova'].get_support()\n-    ... # doctest: +NORMALIZE_WHITESPACE\n-    array([False, False,  True,  True, False, False,  True,  True, False,\n-           True, False,  True,  True, False,  True, False,  True,  True,\n-           False, False])\n-    >>> # Another way to get selected features chosen by anova_filter\n-    >>> anova_svm.named_steps.anova.get_support()\n-    ... # doctest: +NORMALIZE_WHITESPACE\n-    array([False, False,  True,  True, False, False,  True,  True, False,\n-           True, False,  True,  True, False,  True, False,  True,  True,\n-           False, False])\n-    >>> # Indexing can also be used to extract a sub-pipeline.\n-    >>> sub_pipeline = anova_svm[:1]\n-    >>> sub_pipeline  # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE\n-    Pipeline(memory=None, steps=[('anova', ...)])\n-    >>> coef = anova_svm[-1].coef_\n-    >>> anova_svm['svc'] is anova_svm[-1]\n-    True\n-    >>> coef.shape\n-    (1, 10)\n-    >>> sub_pipeline.inverse_transform(coef).shape\n-    (1, 20)\n-    \"\"\"\n-\n-    # BaseEstimator interface\n-    _required_parameters = ['steps']\n-\n-    def __init__(self, steps, memory=None):\n+class Pipeline:\n+    def __init__(self, steps):\n         self.steps = steps\n-        self._validate_steps()\n-        self.memory = memory\n-\n-    def get_params(self, deep=True):\n-        \"\"\"Get parameters for this estimator.\n-\n-        Parameters\n-        ----------\n-        deep : boolean, optional\n-            If True, will return the parameters for this estimator and\n-            contained subobjects that are estimators.\n-\n-        Returns\n-        -------\n-        params : mapping of string to any\n-            Parameter names mapped to their values.\n-        \"\"\"\n-        return self._get_params('steps', deep=deep)\n-\n-    def set_params(self, **kwargs):\n-        \"\"\"Set the parameters of this estimator.\n-\n-        Valid parameter keys can be listed with ``get_params()``.\n-\n-        Returns\n-        -------\n-        self\n-        \"\"\"\n-        self._set_params('steps', **kwargs)\n-        return self\n-\n-    def _validate_steps(self):\n-        names, estimators = zip(*self.steps)\n-\n-        # validate names\n-        self._validate_names(names)\n-\n-        # validate estimators\n-        transformers = estimators[:-1]\n-        estimator = estimators[-1]\n-\n-        for t in transformers:\n-            if t is None or t == 'passthrough':\n-                continue\n-            if (not (hasattr(t, \"fit\") or hasattr(t, \"fit_transform\")) or not\n-                    hasattr(t, \"transform\")):\n-                raise TypeError(\"All intermediate steps should be \"\n-                                \"transformers and implement fit and transform \"\n-                                \"or be the string 'passthrough' \"\n-                                \"'%s' (type %s) doesn't\" % (t, type(t)))\n-\n-        # We allow last estimator to be None as an identity transformation\n-        if (estimator is not None and estimator != 'passthrough'\n-                and not hasattr(estimator, \"fit\")):\n-            raise TypeError(\n-                \"Last step of Pipeline should implement fit \"\n-                \"or be the string 'passthrough'. \"\n-                \"'%s' (type %s) doesn't\" % (estimator, type(estimator)))\n-\n-    def _iter(self, with_final=True):\n-        \"\"\"\n-        Generate (name, trans) tuples excluding 'passthrough' transformers\n-        \"\"\"\n-        stop = len(self.steps)\n-        if not with_final:\n-            stop -= 1\n-\n-        for idx, (name, trans) in enumerate(islice(self.steps, 0, stop)):\n-            if trans is not None and trans != 'passthrough':\n-                yield idx, name, trans\n-\n-    def __getitem__(self, ind):\n-        \"\"\"Returns a sub-pipeline or a single esimtator in the pipeline\n-\n-        Indexing with an integer will return an estimator; using a slice\n-        returns another Pipeline instance which copies a slice of this\n-        Pipeline. This copy is shallow: modifying (or fitting) estimators in\n-        the sub-pipeline will affect the larger pipeline and vice-versa.\n-        However, replacing a value in `step` will not affect a copy.\n-        \"\"\"\n-        if isinstance(ind, slice):\n-            if ind.step not in (1, None):\n-                raise ValueError('Pipeline slicing only supports a step of 1')\n-            return self.__class__(self.steps[ind])\n-        try:\n-            name, est = self.steps[ind]\n-        except TypeError:\n-            # Not an int, try get step by name\n-            return self.named_steps[ind]\n-        return est\n-\n-    @property\n-    def _estimator_type(self):\n-        return self.steps[-1][1]._estimator_type\n-\n-    @property\n-    def named_steps(self):\n-        # Use Bunch object to improve autocomplete\n-        return Bunch(**dict(self.steps))\n-\n-    @property\n-    def _final_estimator(self):\n-        estimator = self.steps[-1][1]\n-        return 'passthrough' if estimator is None else estimator\n-\n-    # Estimator interface\n-\n-    def _fit(self, X, y=None, **fit_params):\n-        # shallow copy of steps - this should really be steps_\n-        self.steps = list(self.steps)\n-        self._validate_steps()\n-        # Setup the memory\n-        memory = check_memory(self.memory)\n-\n-        fit_transform_one_cached = memory.cache(_fit_transform_one)\n-\n-        fit_params_steps = {name: {} for name, step in self.steps\n-                            if step is not None}\n-        for pname, pval in fit_params.items():\n-            step, param = pname.split('__', 1)\n-            fit_params_steps[step][param] = pval\n-        Xt = X\n-        for step_idx, name, transformer in self._iter(with_final=False):\n-            if hasattr(memory, 'location'):\n-                # joblib >= 0.12\n-                if memory.location is None:\n-                    # we do not clone when caching is disabled to\n-                    # preserve backward compatibility\n-                    cloned_transformer = transformer\n-                else:\n-                    cloned_transformer = clone(transformer)\n-            elif hasattr(memory, 'cachedir'):\n-                # joblib < 0.11\n-                if memory.cachedir is None:\n-                    # we do not clone when caching is disabled to\n-                    # preserve backward compatibility\n-                    cloned_transformer = transformer\n-                else:\n-                    cloned_transformer = clone(transformer)\n-            else:\n-                cloned_transformer = clone(transformer)\n-            # Fit or load from cache the current transfomer\n-            Xt, fitted_transformer = fit_transform_one_cached(\n-                cloned_transformer, Xt, y, None,\n-                **fit_params_steps[name])\n-            # Replace the transformer of the step with the fitted\n-            # transformer. This is necessary when loading the transformer\n-            # from the cache.\n-            self.steps[step_idx] = (name, fitted_transformer)\n-        if self._final_estimator == 'passthrough':\n-            return Xt, {}\n-        return Xt, fit_params_steps[self.steps[-1][0]]\n-\n-    def fit(self, X, y=None, **fit_params):\n-        \"\"\"Fit the model\n-\n-        Fit all the transforms one after the other and transform the\n-        data, then fit the transformed data using the final estimator.\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Training data. Must fulfill input requirements of first step of the\n-            pipeline.\n-\n-        y : iterable, default=None\n-            Training targets. Must fulfill label requirements for all steps of\n-            the pipeline.\n-\n-        **fit_params : dict of string -> object\n-            Parameters passed to the ``fit`` method of each step, where\n-            each parameter name is prefixed such that parameter ``p`` for step\n-            ``s`` has key ``s__p``.\n-\n-        Returns\n-        -------\n-        self : Pipeline\n-            This estimator\n-        \"\"\"\n-        Xt, fit_params = self._fit(X, y, **fit_params)\n-        if self._final_estimator != 'passthrough':\n-            self._final_estimator.fit(Xt, y, **fit_params)\n-        return self\n-\n-    def fit_transform(self, X, y=None, **fit_params):\n-        \"\"\"Fit the model and transform with the final estimator\n-\n-        Fits all the transforms one after the other and transforms the\n-        data, then uses fit_transform on transformed data with the final\n-        estimator.\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Training data. Must fulfill input requirements of first step of the\n-            pipeline.\n-\n-        y : iterable, default=None\n-            Training targets. Must fulfill label requirements for all steps of\n-            the pipeline.\n-\n-        **fit_params : dict of string -> object\n-            Parameters passed to the ``fit`` method of each step, where\n-            each parameter name is prefixed such that parameter ``p`` for step\n-            ``s`` has key ``s__p``.\n-\n-        Returns\n-        -------\n-        Xt : array-like, shape = [n_samples, n_transformed_features]\n-            Transformed samples\n-        \"\"\"\n-        last_step = self._final_estimator\n-        Xt, fit_params = self._fit(X, y, **fit_params)\n-        if hasattr(last_step, 'fit_transform'):\n-            return last_step.fit_transform(Xt, y, **fit_params)\n-        elif last_step == 'passthrough':\n-            return Xt\n-        else:\n-            return last_step.fit(Xt, y, **fit_params).transform(Xt)\n-\n-    @if_delegate_has_method(delegate='_final_estimator')\n-    def predict(self, X, **predict_params):\n-        \"\"\"Apply transforms to the data, and predict with the final estimator\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Data to predict on. Must fulfill input requirements of first step\n-            of the pipeline.\n-\n-        **predict_params : dict of string -> object\n-            Parameters to the ``predict`` called at the end of all\n-            transformations in the pipeline. Note that while this may be\n-            used to return uncertainties from some models with return_std\n-            or return_cov, uncertainties that are generated by the\n-            transformations in the pipeline are not propagated to the\n-            final estimator.\n-\n-        Returns\n-        -------\n-        y_pred : array-like\n-        \"\"\"\n-        Xt = X\n-        for _, name, transform in self._iter(with_final=False):\n-            Xt = transform.transform(Xt)\n-        return self.steps[-1][-1].predict(Xt, **predict_params)\n-\n-    @if_delegate_has_method(delegate='_final_estimator')\n-    def fit_predict(self, X, y=None, **fit_params):\n-        \"\"\"Applies fit_predict of last step in pipeline after transforms.\n-\n-        Applies fit_transforms of a pipeline to the data, followed by the\n-        fit_predict method of the final estimator in the pipeline. Valid\n-        only if the final estimator implements fit_predict.\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Training data. Must fulfill input requirements of first step of\n-            the pipeline.\n-\n-        y : iterable, default=None\n-            Training targets. Must fulfill label requirements for all steps\n-            of the pipeline.\n-\n-        **fit_params : dict of string -> object\n-            Parameters passed to the ``fit`` method of each step, where\n-            each parameter name is prefixed such that parameter ``p`` for step\n-            ``s`` has key ``s__p``.\n-\n-        Returns\n-        -------\n-        y_pred : array-like\n-        \"\"\"\n-        Xt, fit_params = self._fit(X, y, **fit_params)\n-        return self.steps[-1][-1].fit_predict(Xt, y, **fit_params)\n-\n-    @if_delegate_has_method(delegate='_final_estimator')\n-    def predict_proba(self, X):\n-        \"\"\"Apply transforms, and predict_proba of the final estimator\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Data to predict on. Must fulfill input requirements of first step\n-            of the pipeline.\n-\n-        Returns\n-        -------\n-        y_proba : array-like, shape = [n_samples, n_classes]\n-        \"\"\"\n-        Xt = X\n-        for _, name, transform in self._iter(with_final=False):\n-            Xt = transform.transform(Xt)\n-        return self.steps[-1][-1].predict_proba(Xt)\n-\n-    @if_delegate_has_method(delegate='_final_estimator')\n-    def decision_function(self, X):\n-        \"\"\"Apply transforms, and decision_function of the final estimator\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Data to predict on. Must fulfill input requirements of first step\n-            of the pipeline.\n-\n-        Returns\n-        -------\n-        y_score : array-like, shape = [n_samples, n_classes]\n-        \"\"\"\n-        Xt = X\n-        for _, name, transform in self._iter(with_final=False):\n-            Xt = transform.transform(Xt)\n-        return self.steps[-1][-1].decision_function(Xt)\n-\n-    @if_delegate_has_method(delegate='_final_estimator')\n-    def predict_log_proba(self, X):\n-        \"\"\"Apply transforms, and predict_log_proba of the final estimator\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Data to predict on. Must fulfill input requirements of first step\n-            of the pipeline.\n-\n-        Returns\n-        -------\n-        y_score : array-like, shape = [n_samples, n_classes]\n-        \"\"\"\n-        Xt = X\n-        for _, name, transform in self._iter(with_final=False):\n-            Xt = transform.transform(Xt)\n-        return self.steps[-1][-1].predict_log_proba(Xt)\n-\n-    @property\n-    def transform(self):\n-        \"\"\"Apply transforms, and transform with the final estimator\n-\n-        This also works where final estimator is ``None``: all prior\n-        transformations are applied.\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Data to transform. Must fulfill input requirements of first step\n-            of the pipeline.\n-\n-        Returns\n-        -------\n-        Xt : array-like, shape = [n_samples, n_transformed_features]\n-        \"\"\"\n-        # _final_estimator is None or has transform, otherwise attribute error\n-        # XXX: Handling the None case means we can't use if_delegate_has_method\n-        if self._final_estimator != 'passthrough':\n-            self._final_estimator.transform\n-        return self._transform\n-\n-    def _transform(self, X):\n-        Xt = X\n-        for _, _, transform in self._iter():\n-            Xt = transform.transform(Xt)\n-        return Xt\n-\n-    @property\n-    def inverse_transform(self):\n-        \"\"\"Apply inverse transformations in reverse order\n-\n-        All estimators in the pipeline must support ``inverse_transform``.\n-\n-        Parameters\n-        ----------\n-        Xt : array-like, shape = [n_samples, n_transformed_features]\n-            Data samples, where ``n_samples`` is the number of samples and\n-            ``n_features`` is the number of features. Must fulfill\n-            input requirements of last step of pipeline's\n-            ``inverse_transform`` method.\n-\n-        Returns\n-        -------\n-        Xt : array-like, shape = [n_samples, n_features]\n-        \"\"\"\n-        # raise AttributeError if necessary for hasattr behaviour\n-        # XXX: Handling the None case means we can't use if_delegate_has_method\n-        for _, _, transform in self._iter():\n-            transform.inverse_transform\n-        return self._inverse_transform\n-\n-    def _inverse_transform(self, X):\n-        Xt = X\n-        reverse_iter = reversed(list(self._iter()))\n-        for _, _, transform in reverse_iter:\n-            Xt = transform.inverse_transform(Xt)\n-        return Xt\n-\n-    @if_delegate_has_method(delegate='_final_estimator')\n-    def score(self, X, y=None, sample_weight=None):\n-        \"\"\"Apply transforms, and score with the final estimator\n-\n-        Parameters\n-        ----------\n-        X : iterable\n-            Data to predict on. Must fulfill input requirements of first step\n-            of the pipeline.\n-\n-        y : iterable, default=None\n-            Targets used for scoring. Must fulfill label requirements for all\n-            steps of the pipeline.\n-\n-        sample_weight : array-like, default=None\n-            If not None, this argument is passed as ``sample_weight`` keyword\n-            argument to the ``score`` method of the final estimator.\n-\n-        Returns\n-        -------\n-        score : float\n-        \"\"\"\n-        Xt = X\n-        for _, name, transform in self._iter(with_final=False):\n-            Xt = transform.transform(Xt)\n-        score_params = {}\n-        if sample_weight is not None:\n-            score_params['sample_weight'] = sample_weight\n-        return self.steps[-1][-1].score(Xt, y, **score_params)\n-\n-    @property\n-    def classes_(self):\n-        return self.steps[-1][-1].classes_\n-\n-    @property\n-    def _pairwise(self):\n-        # check if first estimator expects pairwise input\n-        return getattr(self.steps[0][1], '_pairwise', False)\n-\n-\n-def _name_estimators(estimators):\n-    \"\"\"Generate names for estimators.\"\"\"\n-\n-    names = [\n-        estimator\n-        if isinstance(estimator, str) else type(estimator).__name__.lower()\n-        for estimator in estimators\n-    ]\n-    namecount = defaultdict(int)\n-    for est, name in zip(estimators, names):\n-        namecount[name] += 1\n-\n-    for k, v in list(namecount.items()):\n-        if v == 1:\n-            del namecount[k]\n-\n-    for i in reversed(range(len(estimators))):\n-        name = names[i]\n-        if name in namecount:\n-            names[i] += \"-%d\" % namecount[name]\n-            namecount[name] -= 1\n-\n-    return list(zip(names, estimators))\n-\n-\n-def make_pipeline(*steps, **kwargs):\n-    \"\"\"Construct a Pipeline from the given estimators.\n-\n-    This is a shorthand for the Pipeline constructor; it does not require, and\n-    does not permit, naming the estimators. Instead, their names will be set\n-    to the lowercase of their types automatically.\n-\n-    Parameters\n-    ----------\n-    *steps : list of estimators.\n-\n-    memory : None, str or object with the joblib.Memory interface, optional\n-        Used to cache the fitted transformers of the pipeline. By default,\n-        no caching is performed. If a string is given, it is the path to\n-        the caching directory. Enabling caching triggers a clone of\n-        the transformers before fitting. Therefore, the transformer\n-        instance given to the pipeline cannot be inspected\n-        directly. Use the attribute ``named_steps`` or ``steps`` to\n-        inspect estimators within the pipeline. Caching the\n-        transformers is advantageous when fitting is time consuming.\n-\n-    See also\n-    --------\n-    sklearn.pipeline.Pipeline : Class for creating a pipeline of\n-        transforms with a final estimator.\n-\n-    Examples\n-    --------\n-    >>> from sklearn.naive_bayes import GaussianNB\n-    >>> from sklearn.preprocessing import StandardScaler\n-    >>> make_pipeline(StandardScaler(), GaussianNB(priors=None))\n-    ...     # doctest: +NORMALIZE_WHITESPACE\n-    Pipeline(memory=None,\n-             steps=[('standardscaler',\n-                     StandardScaler(copy=True, with_mean=True, with_std=True)),\n-                    ('gaussiannb',\n-                     GaussianNB(priors=None, var_smoothing=1e-09))])\n-\n-    Returns\n-    -------\n-    p : Pipeline\n-    \"\"\"\n-    memory = kwargs.pop('memory', None)\n-    if kwargs:\n-        raise TypeError('Unknown keyword arguments: \"{}\"'\n-                        .format(list(kwargs.keys())[0]))\n-    return Pipeline(_name_estimators(steps), memory=memory)\n-\n-\n-# weight and fit_params are not used but it allows _fit_one_transformer,\n-# _transform_one and _fit_transform_one to have the same signature to\n-#  factorize the code in ColumnTransformer\n-def _fit_one_transformer(transformer, X, y, weight=None, **fit_params):\n-    return transformer.fit(X, y)\n-\n-\n-def _transform_one(transformer, X, y, weight, **fit_params):\n-    res = transformer.transform(X)\n-    # if we have a weight for this transformer, multiply output\n-    if weight is None:\n-        return res\n-    return res * weight\n-\n-\n-def _fit_transform_one(transformer, X, y, weight, **fit_params):\n-    if hasattr(transformer, 'fit_transform'):\n-        res = transformer.fit_transform(X, y, **fit_params)\n-    else:\n-        res = transformer.fit(X, y, **fit_params).transform(X)\n-    # if we have a weight for this transformer, multiply output\n-    if weight is None:\n-        return res, transformer\n-    return res * weight, transformer\n-\n-\n-class FeatureUnion(_BaseComposition, TransformerMixin):\n-    \"\"\"Concatenates results of multiple transformer objects.\n-\n-    This estimator applies a list of transformer objects in parallel to the\n-    input data, then concatenates the results. This is useful to combine\n-    several feature extraction mechanisms into a single transformer.\n-\n-    Parameters of the transformers may be set using its name and the parameter\n-    name separated by a '__'. A transformer may be replaced entirely by\n-    setting the parameter with its name to another transformer,\n-    or removed by setting to 'drop' or ``None``.\n-\n-    Read more in the :ref:`User Guide <feature_union>`.\n-\n-    Parameters\n-    ----------\n-    transformer_list : list of (string, transformer) tuples\n-        List of transformer objects to be applied to the data. The first\n-        half of each tuple is the name of the transformer.\n-\n-    n_jobs : int or None, optional (default=None)\n-        Number of jobs to run in parallel.\n-        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n-        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`\n-        for more details.\n-\n-    transformer_weights : dict, optional\n-        Multiplicative weights for features per transformer.\n-        Keys are transformer names, values the weights.\n-\n-    See also\n-    --------\n-    sklearn.pipeline.make_union : convenience function for simplified\n-        feature union construction.\n-\n-    Examples\n-    --------\n-    >>> from sklearn.pipeline import FeatureUnion\n-    >>> from sklearn.decomposition import PCA, TruncatedSVD\n-    >>> union = FeatureUnion([(\"pca\", PCA(n_components=1)),\n-    ...                       (\"svd\", TruncatedSVD(n_components=2))])\n-    >>> X = [[0., 1., 3], [2., 2., 5]]\n-    >>> union.fit_transform(X)    # doctest: +NORMALIZE_WHITESPACE +ELLIPSIS\n-    array([[ 1.5       ,  3.0...,  0.8...],\n-           [-1.5       ,  5.7..., -0.4...]])\n-    \"\"\"\n-    _required_parameters = [\"transformer_list\"]\n-\n-    def __init__(self, transformer_list, n_jobs=None,\n-                 transformer_weights=None):\n-        self.transformer_list = transformer_list\n-        self.n_jobs = n_jobs\n-        self.transformer_weights = transformer_weights\n-        self._validate_transformers()\n-\n-    def get_params(self, deep=True):\n-        \"\"\"Get parameters for this estimator.\n-\n-        Parameters\n-        ----------\n-        deep : boolean, optional\n-            If True, will return the parameters for this estimator and\n-            contained subobjects that are estimators.\n-\n-        Returns\n-        -------\n-        params : mapping of string to any\n-            Parameter names mapped to their values.\n-        \"\"\"\n-        return self._get_params('transformer_list', deep=deep)\n-\n-    def set_params(self, **kwargs):\n-        \"\"\"Set the parameters of this estimator.\n-\n-        Valid parameter keys can be listed with ``get_params()``.\n-\n-        Returns\n-        -------\n-        self\n-        \"\"\"\n-        self._set_params('transformer_list', **kwargs)\n-        return self\n-\n-    def _validate_transformers(self):\n-        names, transformers = zip(*self.transformer_list)\n-\n-        # validate names\n-        self._validate_names(names)\n-\n-        # validate estimators\n-        for t in transformers:\n-            if t is None or t == 'drop':\n-                continue\n-            if (not (hasattr(t, \"fit\") or hasattr(t, \"fit_transform\")) or not\n-                    hasattr(t, \"transform\")):\n-                raise TypeError(\"All estimators should implement fit and \"\n-                                \"transform. '%s' (type %s) doesn't\" %\n-                                (t, type(t)))\n-\n-    def _iter(self):\n-        \"\"\"\n-        Generate (name, trans, weight) tuples excluding None and\n-        'drop' transformers.\n-        \"\"\"\n-        get_weight = (self.transformer_weights or {}).get\n-        return ((name, trans, get_weight(name))\n-                for name, trans in self.transformer_list\n-                if trans is not None and trans != 'drop')\n-\n-    def get_feature_names(self):\n-        \"\"\"Get feature names from all transformers.\n-\n-        Returns\n-        -------\n-        feature_names : list of strings\n-            Names of the features produced by transform.\n-        \"\"\"\n-        feature_names = []\n-        for name, trans, weight in self._iter():\n-            if not hasattr(trans, 'get_feature_names'):\n-                raise AttributeError(\"Transformer %s (type %s) does not \"\n-                                     \"provide get_feature_names.\"\n-                                     % (str(name), type(trans).__name__))\n-            feature_names.extend([name + \"__\" + f for f in\n-                                  trans.get_feature_names()])\n-        return feature_names\n-\n-    def fit(self, X, y=None):\n-        \"\"\"Fit all transformers using X.\n-\n-        Parameters\n-        ----------\n-        X : iterable or array-like, depending on transformers\n-            Input data, used to fit transformers.\n-\n-        y : array-like, shape (n_samples, ...), optional\n-            Targets for supervised learning.\n-\n-        Returns\n-        -------\n-        self : FeatureUnion\n-            This estimator\n-        \"\"\"\n-        self.transformer_list = list(self.transformer_list)\n-        self._validate_transformers()\n-        transformers = Parallel(n_jobs=self.n_jobs)(\n-            delayed(_fit_one_transformer)(trans, X, y)\n-            for _, trans, _ in self._iter())\n-        self._update_transformer_list(transformers)\n-        return self\n-\n-    def fit_transform(self, X, y=None, **fit_params):\n-        \"\"\"Fit all transformers, transform the data and concatenate results.\n-\n-        Parameters\n-        ----------\n-        X : iterable or array-like, depending on transformers\n-            Input data to be transformed.\n-\n-        y : array-like, shape (n_samples, ...), optional\n-            Targets for supervised learning.\n-\n-        Returns\n-        -------\n-        X_t : array-like or sparse matrix, shape (n_samples, sum_n_components)\n-            hstack of results of transformers. sum_n_components is the\n-            sum of n_components (output dimension) over transformers.\n-        \"\"\"\n-        self._validate_transformers()\n-        result = Parallel(n_jobs=self.n_jobs)(\n-            delayed(_fit_transform_one)(trans, X, y, weight,\n-                                        **fit_params)\n-            for name, trans, weight in self._iter())\n-\n-        if not result:\n-            # All transformers are None\n-            return np.zeros((X.shape[0], 0))\n-        Xs, transformers = zip(*result)\n-        self._update_transformer_list(transformers)\n-        if any(sparse.issparse(f) for f in Xs):\n-            Xs = sparse.hstack(Xs).tocsr()\n-        else:\n-            Xs = np.hstack(Xs)\n-        return Xs\n-\n-    def transform(self, X):\n-        \"\"\"Transform X separately by each transformer, concatenate results.\n-\n-        Parameters\n-        ----------\n-        X : iterable or array-like, depending on transformers\n-            Input data to be transformed.\n-\n-        Returns\n-        -------\n-        X_t : array-like or sparse matrix, shape (n_samples, sum_n_components)\n-            hstack of results of transformers. sum_n_components is the\n-            sum of n_components (output dimension) over transformers.\n-        \"\"\"\n-        Xs = Parallel(n_jobs=self.n_jobs)(\n-            delayed(_transform_one)(trans, X, None, weight)\n-            for name, trans, weight in self._iter())\n-        if not Xs:\n-            # All transformers are None\n-            return np.zeros((X.shape[0], 0))\n-        if any(sparse.issparse(f) for f in Xs):\n-            Xs = sparse.hstack(Xs).tocsr()\n-        else:\n-            Xs = np.hstack(Xs)\n-        return Xs\n-\n-    def _update_transformer_list(self, transformers):\n-        transformers = iter(transformers)\n-        self.transformer_list[:] = [(name, old if old is None or old == 'drop'\n-                                     else next(transformers))\n-                                    for name, old in self.transformer_list]\n-\n-\n-def make_union(*transformers, **kwargs):\n-    \"\"\"Construct a FeatureUnion from the given transformers.\n-\n-    This is a shorthand for the FeatureUnion constructor; it does not require,\n-    and does not permit, naming the transformers. Instead, they will be given\n-    names automatically based on their types. It also does not allow weighting.\n-\n-    Parameters\n-    ----------\n-    *transformers : list of estimators\n-\n-    n_jobs : int or None, optional (default=None)\n-        Number of jobs to run in parallel.\n-        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.\n-        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`\n-        for more details.\n-\n-    Returns\n-    -------\n-    f : FeatureUnion\n-\n-    See also\n-    --------\n-    sklearn.pipeline.FeatureUnion : Class for concatenating the results\n-        of multiple transformer objects.\n-\n-    Examples\n-    --------\n-    >>> from sklearn.decomposition import PCA, TruncatedSVD\n-    >>> from sklearn.pipeline import make_union\n-    >>> make_union(PCA(), TruncatedSVD())    # doctest: +NORMALIZE_WHITESPACE\n-    FeatureUnion(n_jobs=None,\n-           transformer_list=[('pca',\n-                              PCA(copy=True, iterated_power='auto',\n-                                  n_components=None, random_state=None,\n-                                  svd_solver='auto', tol=0.0, whiten=False)),\n-                             ('truncatedsvd',\n-                              TruncatedSVD(algorithm='randomized',\n-                              n_components=2, n_iter=5,\n-                              random_state=None, tol=0.0))],\n-           transformer_weights=None)\n-    \"\"\"\n-    n_jobs = kwargs.pop('n_jobs', None)\n-    if kwargs:\n-        # We do not currently support `transformer_weights` as we may want to\n-        # change its type spec in make_union\n-        raise TypeError('Unknown keyword arguments: \"{}\"'\n-                        .format(list(kwargs.keys())[0]))\n-    return FeatureUnion(_name_estimators(transformers), n_jobs=n_jobs)\n+    def __len__(self):\n+        return len(self.steps)\n"}
{"instance_id": "scikit-learn__scikit-learn-13496", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/ensemble/iforest.py b/sklearn/ensemble/iforest.py\nindex 8a1bd36259..c23ddb2e43 100644\n--- a/sklearn/ensemble/iforest.py\n+++ b/sklearn/ensemble/iforest.py\n@@ -120,6 +120,12 @@ class IsolationForest(BaseBagging, OutlierMixin):\n     verbose : int, optional (default=0)\n         Controls the verbosity of the tree building process.\n \n+    warm_start : bool, optional (default=False)\n+        When set to ``True``, reuse the solution of the previous call to fit\n+        and add more estimators to the ensemble, otherwise, just fit a whole\n+        new forest. See :term:`the Glossary <warm_start>`.\n+\n+        .. versionadded:: 0.21\n \n     Attributes\n     ----------\n@@ -173,7 +179,8 @@ class IsolationForest(BaseBagging, OutlierMixin):\n                  n_jobs=None,\n                  behaviour='old',\n                  random_state=None,\n-                 verbose=0):\n+                 verbose=0,\n+                 warm_start=False):\n         super().__init__(\n             base_estimator=ExtraTreeRegressor(\n                 max_features=1,\n@@ -187,6 +194,7 @@ class IsolationForest(BaseBagging, OutlierMixin):\n             max_features=max_features,\n             n_jobs=n_jobs,\n             random_state=random_state,\n+            warm_start=warm_start,\n             verbose=verbose)\n \n         self.behaviour = behaviour\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 35, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 35, "steps": 6}], "ms": 14690}
{"instance_id": "scikit-learn__scikit-learn-13779", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/ensemble/voting.py b/sklearn/ensemble/voting.py\nindex 7afa7180cc..1da83f3ee4 100644\n--- a/sklearn/ensemble/voting.py\n+++ b/sklearn/ensemble/voting.py\n@@ -78,7 +78,8 @@ class _BaseVoting(_BaseComposition, TransformerMixin):\n \n         if sample_weight is not None:\n             for name, step in self.estimators:\n-                if not has_fit_parameter(step, 'sample_weight'):\n+                if step is not None and not has_fit_parameter(\n+                        step, 'sample_weight'):\n                     raise ValueError('Underlying estimator \\'%s\\' does not'\n                                      ' support sample weights.' % name)\n \n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 14, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 14, "steps": 9}], "ms": 18539}
{"instance_id": "scikit-learn__scikit-learn-14053", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/tree/export.py b/sklearn/tree/export.py\nindex 1fe11e596a..c28ec40e8c 100644\n--- a/sklearn/tree/export.py\n+++ b/sklearn/tree/export.py\n@@ -890,9 +890,11 @@ def export_text(decision_tree, feature_names=None, max_depth=10,\n         value_fmt = \"{}{} value: {}\\n\"\n \n     if feature_names:\n-        feature_names_ = [feature_names[i] for i in tree_.feature]\n+        feature_names_ = [feature_names[i] if i != _tree.TREE_UNDEFINED\n+                          else None for i in tree_.feature]\n     else:\n-        feature_names_ = [\"feature_{}\".format(i) for i in tree_.feature]\n+        feature_names_ = [\"feature_{}\".format(i) if i != _tree.TREE_UNDEFINED\n+                          else None for i in tree_.feature]\n \n     export_text.report = \"\"\n \n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 18, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 18, "steps": 6}], "ms": 12993}
{"instance_id": "scikit-learn__scikit-learn-14087", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/linear_model/logistic.py b/sklearn/linear_model/logistic.py\nindex 1999f1dae7..20603226ba 100644\n--- a/sklearn/linear_model/logistic.py\n+++ b/sklearn/linear_model/logistic.py\n@@ -2170,7 +2170,7 @@ class LogisticRegressionCV(LogisticRegression, BaseEstimator,\n                 # Take the best scores across every fold and the average of\n                 # all coefficients corresponding to the best scores.\n                 best_indices = np.argmax(scores, axis=1)\n-                if self.multi_class == 'ovr':\n+                if multi_class == 'ovr':\n                     w = np.mean([coefs_paths[i, best_indices[i], :]\n                                  for i in range(len(folds))], axis=0)\n                 else:\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 7}], "ms": 11966}
{"instance_id": "scikit-learn__scikit-learn-14141", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/utils/_show_versions.py b/sklearn/utils/_show_versions.py\nindex e5d3141bf0..ecba9ec68b 100644\n--- a/sklearn/utils/_show_versions.py\n+++ b/sklearn/utils/_show_versions.py\n@@ -48,6 +48,7 @@ def _get_deps_info():\n         \"Cython\",\n         \"pandas\",\n         \"matplotlib\",\n+        \"joblib\",\n     ]\n \n     def get_version(module):\n", "model": "claude-sonnet-5-5", "steps": 4, "finished": true, "patch_lines": 12, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 12, "steps": 4}], "ms": 28526}
{"instance_id": "scikit-learn__scikit-learn-14496", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/cluster/optics_.py b/sklearn/cluster/optics_.py\nindex 4f7eb11ab2..bd97d6357e 100755\n--- a/sklearn/cluster/optics_.py\n+++ b/sklearn/cluster/optics_.py\n@@ -437,7 +437,7 @@ if metric=\u2019precomputed\u2019.\n     n_samples = X.shape[0]\n     _validate_size(min_samples, n_samples, 'min_samples')\n     if min_samples <= 1:\n-        min_samples = max(2, min_samples * n_samples)\n+        min_samples = int(round(max(2, min_samples * n_samples)))\n \n     # Start all points as 'unprocessed' ##\n     reachability_ = np.empty(n_samples)\n@@ -619,12 +619,12 @@ def cluster_optics_xi(reachability, predecessor, ordering, min_samples,\n     n_samples = len(reachability)\n     _validate_size(min_samples, n_samples, 'min_samples')\n     if min_samples <= 1:\n-        min_samples = max(2, min_samples * n_samples)\n+        min_samples = int(round(max(2, min_samples * n_samples)))\n     if min_cluster_size is None:\n         min_cluster_size = min_samples\n     _validate_size(min_cluster_size, n_samples, 'min_cluster_size')\n     if min_cluster_size <= 1:\n-        min_cluster_size = max(2, min_cluster_size * n_samples)\n+        min_cluster_size = int(round(max(2, min_cluster_size * n_samples)))\n \n     clusters = _xi_cluster(reachability[ordering], predecessor[ordering],\n                            ordering, xi,\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 28, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 28, "steps": 9}], "ms": 19892}
{"instance_id": "scikit-learn__scikit-learn-14629", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/model_selection/_validation.py b/sklearn/model_selection/_validation.py\nindex 95669a212c..28db0ab176 100644\n--- a/sklearn/model_selection/_validation.py\n+++ b/sklearn/model_selection/_validation.py\n@@ -855,8 +855,14 @@ def _fit_and_predict(estimator, X, y, train, test, verbose, fit_params,\n     predictions = func(X_test)\n     if method in ['decision_function', 'predict_proba', 'predict_log_proba']:\n         if isinstance(predictions, list):\n+            if hasattr(estimator, 'classes_'):\n+                estimator_classes = estimator.classes_\n+            else:\n+                # e.g. MultiOutputClassifier\n+                estimator_classes = [est.classes_\n+                                     for est in estimator.estimators_]\n             predictions = [_enforce_prediction_order(\n-                estimator.classes_[i_label], predictions[i_label],\n+                estimator_classes[i_label], predictions[i_label],\n                 n_classes=len(set(y[:, i_label])), method=method)\n                 for i_label in range(len(predictions))]\n         else:\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 20, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 20, "steps": 6}], "ms": 15581}
{"instance_id": "scikit-learn__scikit-learn-14710", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py\nindex ad6a5a8ca3..311c8dd065 100644\n--- a/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py\n+++ b/sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py\n@@ -1,1044 +1 @@\n-\"\"\"Fast Gradient Boosting decision trees for classification and regression.\"\"\"\n-# Author: Nicolas Hug\n-\n-from abc import ABC, abstractmethod\n-from functools import partial\n-\n-import numpy as np\n-from timeit import default_timer as time\n-from ...base import (BaseEstimator, RegressorMixin, ClassifierMixin,\n-                     is_classifier)\n-from ...utils import check_X_y, check_random_state, check_array, resample\n-from ...utils.validation import check_is_fitted\n-from ...utils.multiclass import check_classification_targets\n-from ...metrics import check_scoring\n-from ...model_selection import train_test_split\n-from ...preprocessing import LabelEncoder\n-from ._gradient_boosting import _update_raw_predictions\n-from .common import Y_DTYPE, X_DTYPE, X_BINNED_DTYPE\n-\n-from .binning import _BinMapper\n-from .grower import TreeGrower\n-from .loss import _LOSSES\n-\n-\n-class BaseHistGradientBoosting(BaseEstimator, ABC):\n-    \"\"\"Base class for histogram-based gradient boosting estimators.\"\"\"\n-\n-    @abstractmethod\n-    def __init__(self, loss, learning_rate, max_iter, max_leaf_nodes,\n-                 max_depth, min_samples_leaf, l2_regularization, max_bins,\n-                 warm_start, scoring, validation_fraction, n_iter_no_change,\n-                 tol, verbose, random_state):\n-        self.loss = loss\n-        self.learning_rate = learning_rate\n-        self.max_iter = max_iter\n-        self.max_leaf_nodes = max_leaf_nodes\n-        self.max_depth = max_depth\n-        self.min_samples_leaf = min_samples_leaf\n-        self.l2_regularization = l2_regularization\n-        self.max_bins = max_bins\n-        self.warm_start = warm_start\n-        self.scoring = scoring\n-        self.validation_fraction = validation_fraction\n-        self.n_iter_no_change = n_iter_no_change\n-        self.tol = tol\n-        self.verbose = verbose\n-        self.random_state = random_state\n-\n-    def _validate_parameters(self):\n-        \"\"\"Validate parameters passed to __init__.\n-\n-        The parameters that are directly passed to the grower are checked in\n-        TreeGrower.\"\"\"\n-\n-        if self.loss not in self._VALID_LOSSES:\n-            raise ValueError(\n-                \"Loss {} is not supported for {}. Accepted losses: \"\n-                \"{}.\".format(self.loss, self.__class__.__name__,\n-                             ', '.join(self._VALID_LOSSES)))\n-\n-        if self.learning_rate <= 0:\n-            raise ValueError('learning_rate={} must '\n-                             'be strictly positive'.format(self.learning_rate))\n-        if self.max_iter < 1:\n-            raise ValueError('max_iter={} must not be smaller '\n-                             'than 1.'.format(self.max_iter))\n-        if self.n_iter_no_change is not None and self.n_iter_no_change < 0:\n-            raise ValueError('n_iter_no_change={} must be '\n-                             'positive.'.format(self.n_iter_no_change))\n-        if (self.validation_fraction is not None and\n-                self.validation_fraction <= 0):\n-            raise ValueError(\n-                'validation_fraction={} must be strictly '\n-                'positive, or None.'.format(self.validation_fraction))\n-        if self.tol is not None and self.tol < 0:\n-            raise ValueError('tol={} '\n-                             'must not be smaller than 0.'.format(self.tol))\n-\n-        if not (2 <= self.max_bins <= 255):\n-            raise ValueError('max_bins={} should be no smaller than 2 '\n-                             'and no larger than 255.'.format(self.max_bins))\n-\n-    def fit(self, X, y):\n-        \"\"\"Fit the gradient boosting model.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape=(n_samples, n_features)\n-            The input samples.\n-\n-        y : array-like, shape=(n_samples,)\n-            Target values.\n-\n-        Returns\n-        -------\n-        self : object\n-        \"\"\"\n-        fit_start_time = time()\n-        acc_find_split_time = 0.  # time spent finding the best splits\n-        acc_apply_split_time = 0.  # time spent splitting nodes\n-        acc_compute_hist_time = 0.  # time spent computing histograms\n-        # time spent predicting X for gradient and hessians update\n-        acc_prediction_time = 0.\n-        X, y = check_X_y(X, y, dtype=[X_DTYPE], force_all_finite=False)\n-        y = self._encode_y(y)\n-\n-        # The rng state must be preserved if warm_start is True\n-        if (self.warm_start and hasattr(self, '_rng')):\n-            rng = self._rng\n-        else:\n-            rng = check_random_state(self.random_state)\n-            self._rng = rng\n-\n-        self._validate_parameters()\n-        self.n_features_ = X.shape[1]  # used for validation in predict()\n-\n-        # we need this stateful variable to tell raw_predict() that it was\n-        # called from fit() (this current method), and that the data it has\n-        # received is pre-binned.\n-        # predicting is faster on pre-binned data, so we want early stopping\n-        # predictions to be made on pre-binned data. Unfortunately the scorer_\n-        # can only call predict() or predict_proba(), not raw_predict(), and\n-        # there's no way to tell the scorer that it needs to predict binned\n-        # data.\n-        self._in_fit = True\n-\n-        self.loss_ = self._get_loss()\n-\n-        self.do_early_stopping_ = (self.n_iter_no_change is not None and\n-                                   self.n_iter_no_change > 0)\n-\n-        # create validation data if needed\n-        self._use_validation_data = self.validation_fraction is not None\n-        if self.do_early_stopping_ and self._use_validation_data:\n-            # stratify for classification\n-            stratify = y if hasattr(self.loss_, 'predict_proba') else None\n-\n-            # Save the state of the RNG for the training and validation split.\n-            # This is needed in order to have the same split when using\n-            # warm starting.\n-            if not (self._is_fitted() and self.warm_start):\n-                self._train_val_split_seed = rng.randint(1024)\n-\n-            X_train, X_val, y_train, y_val = train_test_split(\n-                X, y, test_size=self.validation_fraction, stratify=stratify,\n-                random_state=self._train_val_split_seed)\n-        else:\n-            X_train, y_train = X, y\n-            X_val, y_val = None, None\n-\n-        has_missing_values = np.isnan(X_train).any(axis=0).astype(np.uint8)\n-\n-        # Bin the data\n-        # For ease of use of the API, the user-facing GBDT classes accept the\n-        # parameter max_bins, which doesn't take into account the bin for\n-        # missing values (which is always allocated). However, since max_bins\n-        # isn't the true maximal number of bins, all other private classes\n-        # (binmapper, histbuilder...) accept n_bins instead, which is the\n-        # actual total number of bins. Everywhere in the code, the\n-        # convention is that n_bins == max_bins + 1\n-        n_bins = self.max_bins + 1  # + 1 for missing values\n-        self.bin_mapper_ = _BinMapper(n_bins=n_bins, random_state=rng)\n-        X_binned_train = self._bin_data(X_train, rng, is_training_data=True)\n-        if X_val is not None:\n-            X_binned_val = self._bin_data(X_val, rng, is_training_data=False)\n-        else:\n-            X_binned_val = None\n-\n-        if self.verbose:\n-            print(\"Fitting gradient boosted rounds:\")\n-\n-        n_samples = X_binned_train.shape[0]\n-\n-        # First time calling fit, or no warm start\n-        if not (self._is_fitted() and self.warm_start):\n-            # Clear random state and score attributes\n-            self._clear_state()\n-\n-            # initialize raw_predictions: those are the accumulated values\n-            # predicted by the trees for the training data. raw_predictions has\n-            # shape (n_trees_per_iteration, n_samples) where\n-            # n_trees_per_iterations is n_classes in multiclass classification,\n-            # else 1.\n-            self._baseline_prediction = self.loss_.get_baseline_prediction(\n-                y_train, self.n_trees_per_iteration_\n-            )\n-            raw_predictions = np.zeros(\n-                shape=(self.n_trees_per_iteration_, n_samples),\n-                dtype=self._baseline_prediction.dtype\n-            )\n-            raw_predictions += self._baseline_prediction\n-\n-            # initialize gradients and hessians (empty arrays).\n-            # shape = (n_trees_per_iteration, n_samples).\n-            gradients, hessians = self.loss_.init_gradients_and_hessians(\n-                n_samples=n_samples,\n-                prediction_dim=self.n_trees_per_iteration_\n-            )\n-\n-            # predictors is a matrix (list of lists) of TreePredictor objects\n-            # with shape (n_iter_, n_trees_per_iteration)\n-            self._predictors = predictors = []\n-\n-            # Initialize structures and attributes related to early stopping\n-            self.scorer_ = None  # set if scoring != loss\n-            raw_predictions_val = None  # set if scoring == loss and use val\n-            self.train_score_ = []\n-            self.validation_score_ = []\n-\n-            if self.do_early_stopping_:\n-                # populate train_score and validation_score with the\n-                # predictions of the initial model (before the first tree)\n-\n-                if self.scoring == 'loss':\n-                    # we're going to compute scoring w.r.t the loss. As losses\n-                    # take raw predictions as input (unlike the scorers), we\n-                    # can optimize a bit and avoid repeating computing the\n-                    # predictions of the previous trees. We'll re-use\n-                    # raw_predictions (as it's needed for training anyway) for\n-                    # evaluating the training loss, and create\n-                    # raw_predictions_val for storing the raw predictions of\n-                    # the validation data.\n-\n-                    if self._use_validation_data:\n-                        raw_predictions_val = np.zeros(\n-                            shape=(self.n_trees_per_iteration_,\n-                                   X_binned_val.shape[0]),\n-                            dtype=self._baseline_prediction.dtype\n-                        )\n-\n-                        raw_predictions_val += self._baseline_prediction\n-\n-                    self._check_early_stopping_loss(raw_predictions, y_train,\n-                                                    raw_predictions_val, y_val)\n-                else:\n-                    self.scorer_ = check_scoring(self, self.scoring)\n-                    # scorer_ is a callable with signature (est, X, y) and\n-                    # calls est.predict() or est.predict_proba() depending on\n-                    # its nature.\n-                    # Unfortunately, each call to scorer_() will compute\n-                    # the predictions of all the trees. So we use a subset of\n-                    # the training set to compute train scores.\n-\n-                    # Save the seed for the small trainset generator\n-                    self._small_trainset_seed = rng.randint(1024)\n-\n-                    # Compute the subsample set\n-                    (X_binned_small_train,\n-                     y_small_train) = self._get_small_trainset(\n-                        X_binned_train, y_train, self._small_trainset_seed)\n-\n-                    self._check_early_stopping_scorer(\n-                        X_binned_small_train, y_small_train,\n-                        X_binned_val, y_val,\n-                    )\n-            begin_at_stage = 0\n-\n-        # warm start: this is not the first time fit was called\n-        else:\n-            # Check that the maximum number of iterations is not smaller\n-            # than the number of iterations from the previous fit\n-            if self.max_iter < self.n_iter_:\n-                raise ValueError(\n-                    'max_iter=%d must be larger than or equal to '\n-                    'n_iter_=%d when warm_start==True'\n-                    % (self.max_iter, self.n_iter_)\n-                )\n-\n-            # Convert array attributes to lists\n-            self.train_score_ = self.train_score_.tolist()\n-            self.validation_score_ = self.validation_score_.tolist()\n-\n-            # Compute raw predictions\n-            raw_predictions = self._raw_predict(X_binned_train)\n-\n-            if self.do_early_stopping_ and self.scoring != 'loss':\n-                # Compute the subsample set\n-                X_binned_small_train, y_small_train = self._get_small_trainset(\n-                    X_binned_train, y_train, self._small_trainset_seed)\n-\n-            # Initialize the gradients and hessians\n-            gradients, hessians = self.loss_.init_gradients_and_hessians(\n-                n_samples=n_samples,\n-                prediction_dim=self.n_trees_per_iteration_\n-            )\n-\n-            # Get the predictors from the previous fit\n-            predictors = self._predictors\n-\n-            begin_at_stage = self.n_iter_\n-\n-        for iteration in range(begin_at_stage, self.max_iter):\n-\n-            if self.verbose:\n-                iteration_start_time = time()\n-                print(\"[{}/{}] \".format(iteration + 1, self.max_iter),\n-                      end='', flush=True)\n-\n-            # Update gradients and hessians, inplace\n-            self.loss_.update_gradients_and_hessians(gradients, hessians,\n-                                                     y_train, raw_predictions)\n-\n-            # Append a list since there may be more than 1 predictor per iter\n-            predictors.append([])\n-\n-            # Build `n_trees_per_iteration` trees.\n-            for k in range(self.n_trees_per_iteration_):\n-\n-                grower = TreeGrower(\n-                    X_binned_train, gradients[k, :], hessians[k, :],\n-                    n_bins=n_bins,\n-                    n_bins_non_missing=self.bin_mapper_.n_bins_non_missing_,\n-                    has_missing_values=has_missing_values,\n-                    max_leaf_nodes=self.max_leaf_nodes,\n-                    max_depth=self.max_depth,\n-                    min_samples_leaf=self.min_samples_leaf,\n-                    l2_regularization=self.l2_regularization,\n-                    shrinkage=self.learning_rate)\n-                grower.grow()\n-\n-                acc_apply_split_time += grower.total_apply_split_time\n-                acc_find_split_time += grower.total_find_split_time\n-                acc_compute_hist_time += grower.total_compute_hist_time\n-\n-                predictor = grower.make_predictor(\n-                    bin_thresholds=self.bin_mapper_.bin_thresholds_\n-                )\n-                predictors[-1].append(predictor)\n-\n-                # Update raw_predictions with the predictions of the newly\n-                # created tree.\n-                tic_pred = time()\n-                _update_raw_predictions(raw_predictions[k, :], grower)\n-                toc_pred = time()\n-                acc_prediction_time += toc_pred - tic_pred\n-\n-            should_early_stop = False\n-            if self.do_early_stopping_:\n-                if self.scoring == 'loss':\n-                    # Update raw_predictions_val with the newest tree(s)\n-                    if self._use_validation_data:\n-                        for k, pred in enumerate(self._predictors[-1]):\n-                            raw_predictions_val[k, :] += (\n-                                pred.predict_binned(\n-                                    X_binned_val,\n-                                    self.bin_mapper_.missing_values_bin_idx_\n-                                )\n-                            )\n-\n-                    should_early_stop = self._check_early_stopping_loss(\n-                        raw_predictions, y_train,\n-                        raw_predictions_val, y_val\n-                    )\n-\n-                else:\n-                    should_early_stop = self._check_early_stopping_scorer(\n-                        X_binned_small_train, y_small_train,\n-                        X_binned_val, y_val,\n-                    )\n-\n-            if self.verbose:\n-                self._print_iteration_stats(iteration_start_time)\n-\n-            # maybe we could also early stop if all the trees are stumps?\n-            if should_early_stop:\n-                break\n-\n-        if self.verbose:\n-            duration = time() - fit_start_time\n-            n_total_leaves = sum(\n-                predictor.get_n_leaf_nodes()\n-                for predictors_at_ith_iteration in self._predictors\n-                for predictor in predictors_at_ith_iteration\n-            )\n-            n_predictors = sum(\n-                len(predictors_at_ith_iteration)\n-                for predictors_at_ith_iteration in self._predictors)\n-            print(\"Fit {} trees in {:.3f} s, ({} total leaves)\".format(\n-                n_predictors, duration, n_total_leaves))\n-            print(\"{:<32} {:.3f}s\".format('Time spent computing histograms:',\n-                                          acc_compute_hist_time))\n-            print(\"{:<32} {:.3f}s\".format('Time spent finding best splits:',\n-                                          acc_find_split_time))\n-            print(\"{:<32} {:.3f}s\".format('Time spent applying splits:',\n-                                          acc_apply_split_time))\n-            print(\"{:<32} {:.3f}s\".format('Time spent predicting:',\n-                                          acc_prediction_time))\n-\n-        self.train_score_ = np.asarray(self.train_score_)\n-        self.validation_score_ = np.asarray(self.validation_score_)\n-        del self._in_fit  # hard delete so we're sure it can't be used anymore\n-        return self\n-\n-    def _is_fitted(self):\n-        return len(getattr(self, '_predictors', [])) > 0\n-\n-    def _clear_state(self):\n-        \"\"\"Clear the state of the gradient boosting model.\"\"\"\n-        for var in ('train_score_', 'validation_score_', '_rng'):\n-            if hasattr(self, var):\n-                delattr(self, var)\n-\n-    def _get_small_trainset(self, X_binned_train, y_train, seed):\n-        \"\"\"Compute the indices of the subsample set and return this set.\n-\n-        For efficiency, we need to subsample the training set to compute scores\n-        with scorers.\n-        \"\"\"\n-        subsample_size = 10000\n-        if X_binned_train.shape[0] > subsample_size:\n-            indices = np.arange(X_binned_train.shape[0])\n-            stratify = y_train if is_classifier(self) else None\n-            indices = resample(indices, n_samples=subsample_size,\n-                               replace=False, random_state=seed,\n-                               stratify=stratify)\n-            X_binned_small_train = X_binned_train[indices]\n-            y_small_train = y_train[indices]\n-            X_binned_small_train = np.ascontiguousarray(X_binned_small_train)\n-            return X_binned_small_train, y_small_train\n-        else:\n-            return X_binned_train, y_train\n-\n-    def _check_early_stopping_scorer(self, X_binned_small_train, y_small_train,\n-                                     X_binned_val, y_val):\n-        \"\"\"Check if fitting should be early-stopped based on scorer.\n-\n-        Scores are computed on validation data or on training data.\n-        \"\"\"\n-        self.train_score_.append(\n-            self.scorer_(self, X_binned_small_train, y_small_train)\n-        )\n-\n-        if self._use_validation_data:\n-            self.validation_score_.append(\n-                self.scorer_(self, X_binned_val, y_val)\n-            )\n-            return self._should_stop(self.validation_score_)\n-        else:\n-            return self._should_stop(self.train_score_)\n-\n-    def _check_early_stopping_loss(self,\n-                                   raw_predictions,\n-                                   y_train,\n-                                   raw_predictions_val,\n-                                   y_val):\n-        \"\"\"Check if fitting should be early-stopped based on loss.\n-\n-        Scores are computed on validation data or on training data.\n-        \"\"\"\n-\n-        self.train_score_.append(\n-            -self.loss_(y_train, raw_predictions)\n-        )\n-\n-        if self._use_validation_data:\n-            self.validation_score_.append(\n-                -self.loss_(y_val, raw_predictions_val)\n-            )\n-            return self._should_stop(self.validation_score_)\n-        else:\n-            return self._should_stop(self.train_score_)\n-\n-    def _should_stop(self, scores):\n-        \"\"\"\n-        Return True (do early stopping) if the last n scores aren't better\n-        than the (n-1)th-to-last score, up to some tolerance.\n-        \"\"\"\n-        reference_position = self.n_iter_no_change + 1\n-        if len(scores) < reference_position:\n-            return False\n-\n-        # A higher score is always better. Higher tol means that it will be\n-        # harder for subsequent iteration to be considered an improvement upon\n-        # the reference score, and therefore it is more likely to early stop\n-        # because of the lack of significant improvement.\n-        tol = 0 if self.tol is None else self.tol\n-        reference_score = scores[-reference_position] + tol\n-        recent_scores = scores[-reference_position + 1:]\n-        recent_improvements = [score > reference_score\n-                               for score in recent_scores]\n-        return not any(recent_improvements)\n-\n-    def _bin_data(self, X, rng, is_training_data):\n-        \"\"\"Bin data X.\n-\n-        If is_training_data, then set the bin_mapper_ attribute.\n-        Else, the binned data is converted to a C-contiguous array.\n-        \"\"\"\n-\n-        description = 'training' if is_training_data else 'validation'\n-        if self.verbose:\n-            print(\"Binning {:.3f} GB of {} data: \".format(\n-                X.nbytes / 1e9, description), end=\"\", flush=True)\n-        tic = time()\n-        if is_training_data:\n-            X_binned = self.bin_mapper_.fit_transform(X)  # F-aligned array\n-        else:\n-            X_binned = self.bin_mapper_.transform(X)  # F-aligned array\n-            # We convert the array to C-contiguous since predicting is faster\n-            # with this layout (training is faster on F-arrays though)\n-            X_binned = np.ascontiguousarray(X_binned)\n-        toc = time()\n-        if self.verbose:\n-            duration = toc - tic\n-            print(\"{:.3f} s\".format(duration))\n-\n-        return X_binned\n-\n-    def _print_iteration_stats(self, iteration_start_time):\n-        \"\"\"Print info about the current fitting iteration.\"\"\"\n-        log_msg = ''\n-\n-        predictors_of_ith_iteration = [\n-            predictors_list for predictors_list in self._predictors[-1]\n-            if predictors_list\n-        ]\n-        n_trees = len(predictors_of_ith_iteration)\n-        max_depth = max(predictor.get_max_depth()\n-                        for predictor in predictors_of_ith_iteration)\n-        n_leaves = sum(predictor.get_n_leaf_nodes()\n-                       for predictor in predictors_of_ith_iteration)\n-\n-        if n_trees == 1:\n-            log_msg += (\"{} tree, {} leaves, \".format(n_trees, n_leaves))\n-        else:\n-            log_msg += (\"{} trees, {} leaves \".format(n_trees, n_leaves))\n-            log_msg += (\"({} on avg), \".format(int(n_leaves / n_trees)))\n-\n-        log_msg += \"max depth = {}, \".format(max_depth)\n-\n-        if self.do_early_stopping_:\n-            if self.scoring == 'loss':\n-                factor = -1  # score_ arrays contain the negative loss\n-                name = 'loss'\n-            else:\n-                factor = 1\n-                name = 'score'\n-            log_msg += \"train {}: {:.5f}, \".format(name, factor *\n-                                                   self.train_score_[-1])\n-            if self._use_validation_data:\n-                log_msg += \"val {}: {:.5f}, \".format(\n-                    name, factor * self.validation_score_[-1])\n-\n-        iteration_time = time() - iteration_start_time\n-        log_msg += \"in {:0.3f}s\".format(iteration_time)\n-\n-        print(log_msg)\n-\n-    def _raw_predict(self, X):\n-        \"\"\"Return the sum of the leaves values over all predictors.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape=(n_samples, n_features)\n-            The input samples.\n-\n-        Returns\n-        -------\n-        raw_predictions : array, shape (n_samples * n_trees_per_iteration,)\n-            The raw predicted values.\n-        \"\"\"\n-        X = check_array(X, dtype=[X_DTYPE, X_BINNED_DTYPE],\n-                        force_all_finite=False)\n-        check_is_fitted(self)\n-        if X.shape[1] != self.n_features_:\n-            raise ValueError(\n-                'X has {} features but this estimator was trained with '\n-                '{} features.'.format(X.shape[1], self.n_features_)\n-            )\n-        is_binned = getattr(self, '_in_fit', False)\n-        n_samples = X.shape[0]\n-        raw_predictions = np.zeros(\n-            shape=(self.n_trees_per_iteration_, n_samples),\n-            dtype=self._baseline_prediction.dtype\n-        )\n-        raw_predictions += self._baseline_prediction\n-        for predictors_of_ith_iteration in self._predictors:\n-            for k, predictor in enumerate(predictors_of_ith_iteration):\n-                if is_binned:\n-                    predict = partial(\n-                        predictor.predict_binned,\n-                        missing_values_bin_idx=self.bin_mapper_.missing_values_bin_idx_  # noqa\n-                    )\n-                else:\n-                    predict = predictor.predict\n-                raw_predictions[k, :] += predict(X)\n-\n-        return raw_predictions\n-\n-    def _compute_partial_dependence_recursion(self, grid, target_features):\n-        \"\"\"Fast partial dependence computation.\n-\n-        Parameters\n-        ----------\n-        grid : ndarray, shape (n_samples, n_target_features)\n-            The grid points on which the partial dependence should be\n-            evaluated.\n-        target_features : ndarray, shape (n_target_features)\n-            The set of target features for which the partial dependence\n-            should be evaluated.\n-\n-        Returns\n-        -------\n-        averaged_predictions : ndarray, shape \\\n-                (n_trees_per_iteration, n_samples)\n-            The value of the partial dependence function on each grid point.\n-        \"\"\"\n-        grid = np.asarray(grid, dtype=X_DTYPE, order='C')\n-        averaged_predictions = np.zeros(\n-            (self.n_trees_per_iteration_, grid.shape[0]), dtype=Y_DTYPE)\n-\n-        for predictors_of_ith_iteration in self._predictors:\n-            for k, predictor in enumerate(predictors_of_ith_iteration):\n-                predictor.compute_partial_dependence(grid, target_features,\n-                                                     averaged_predictions[k])\n-        # Note that the learning rate is already accounted for in the leaves\n-        # values.\n-\n-        return averaged_predictions\n-\n-    def _more_tags(self):\n-        return {'allow_nan': True}\n-\n-    @abstractmethod\n-    def _get_loss(self):\n-        pass\n-\n-    @abstractmethod\n-    def _encode_y(self, y=None):\n-        pass\n-\n-    @property\n-    def n_iter_(self):\n-        check_is_fitted(self)\n-        return len(self._predictors)\n-\n-\n-class HistGradientBoostingRegressor(BaseHistGradientBoosting, RegressorMixin):\n-    \"\"\"Histogram-based Gradient Boosting Regression Tree.\n-\n-    This estimator is much faster than\n-    :class:`GradientBoostingRegressor<sklearn.ensemble.GradientBoostingRegressor>`\n-    for big datasets (n_samples >= 10 000).\n-\n-    This estimator has native support for missing values (NaNs). During\n-    training, the tree grower learns at each split point whether samples\n-    with missing values should go to the left or right child, based on the\n-    potential gain. When predicting, samples with missing values are\n-    assigned to the left or right child consequently. If no missing values\n-    were encountered for a given feature during training, then samples with\n-    missing values are mapped to whichever child has the most samples.\n-\n-    This implementation is inspired by\n-    `LightGBM <https://github.com/Microsoft/LightGBM>`_.\n-\n-    .. note::\n-\n-      This estimator is still **experimental** for now: the predictions\n-      and the API might change without any deprecation cycle. To use it,\n-      you need to explicitly import ``enable_hist_gradient_boosting``::\n-\n-        >>> # explicitly require this experimental feature\n-        >>> from sklearn.experimental import enable_hist_gradient_boosting  # noqa\n-        >>> # now you can import normally from ensemble\n-        >>> from sklearn.ensemble import HistGradientBoostingClassifier\n-\n-    Read more in the :ref:`User Guide <histogram_based_gradient_boosting>`.\n-\n-    Parameters\n-    ----------\n-    loss : {'least_squares'}, optional (default='least_squares')\n-        The loss function to use in the boosting process. Note that the\n-        \"least squares\" loss actually implements an \"half least squares loss\"\n-        to simplify the computation of the gradient.\n-    learning_rate : float, optional (default=0.1)\n-        The learning rate, also known as *shrinkage*. This is used as a\n-        multiplicative factor for the leaves values. Use ``1`` for no\n-        shrinkage.\n-    max_iter : int, optional (default=100)\n-        The maximum number of iterations of the boosting process, i.e. the\n-        maximum number of trees.\n-    max_leaf_nodes : int or None, optional (default=31)\n-        The maximum number of leaves for each tree. Must be strictly greater\n-        than 1. If None, there is no maximum limit.\n-    max_depth : int or None, optional (default=None)\n-        The maximum depth of each tree. The depth of a tree is the number of\n-        nodes to go from the root to the deepest leaf. Must be strictly greater\n-        than 1. Depth isn't constrained by default.\n-    min_samples_leaf : int, optional (default=20)\n-        The minimum number of samples per leaf. For small datasets with less\n-        than a few hundred samples, it is recommended to lower this value\n-        since only very shallow trees would be built.\n-    l2_regularization : float, optional (default=0)\n-        The L2 regularization parameter. Use ``0`` for no regularization\n-        (default).\n-    max_bins : int, optional (default=255)\n-        The maximum number of bins to use for non-missing values. Before\n-        training, each feature of the input array `X` is binned into\n-        integer-valued bins, which allows for a much faster training stage.\n-        Features with a small number of unique values may use less than\n-        ``max_bins`` bins. In addition to the ``max_bins`` bins, one more bin\n-        is always reserved for missing values. Must be no larger than 255.\n-    warm_start : bool, optional (default=False)\n-        When set to ``True``, reuse the solution of the previous call to fit\n-        and add more estimators to the ensemble. For results to be valid, the\n-        estimator should be re-trained on the same data only.\n-        See :term:`the Glossary <warm_start>`.\n-    scoring : str or callable or None, optional (default=None)\n-        Scoring parameter to use for early stopping. It can be a single\n-        string (see :ref:`scoring_parameter`) or a callable (see\n-        :ref:`scoring`). If None, the estimator's default scorer is used. If\n-        ``scoring='loss'``, early stopping is checked w.r.t the loss value.\n-        Only used if ``n_iter_no_change`` is not None.\n-    validation_fraction : int or float or None, optional (default=0.1)\n-        Proportion (or absolute size) of training data to set aside as\n-        validation data for early stopping. If None, early stopping is done on\n-        the training data. Only used if ``n_iter_no_change`` is not None.\n-    n_iter_no_change : int or None, optional (default=None)\n-        Used to determine when to \"early stop\". The fitting process is\n-        stopped when none of the last ``n_iter_no_change`` scores are better\n-        than the ``n_iter_no_change - 1`` -th-to-last one, up to some\n-        tolerance. If None or 0, no early-stopping is done.\n-    tol : float or None, optional (default=1e-7)\n-        The absolute tolerance to use when comparing scores during early\n-        stopping. The higher the tolerance, the more likely we are to early\n-        stop: higher tolerance means that it will be harder for subsequent\n-        iterations to be considered an improvement upon the reference score.\n-    verbose: int, optional (default=0)\n-        The verbosity level. If not zero, print some information about the\n-        fitting process.\n-    random_state : int, np.random.RandomStateInstance or None, \\\n-        optional (default=None)\n-        Pseudo-random number generator to control the subsampling in the\n-        binning process, and the train/validation data split if early stopping\n-        is enabled. See :term:`random_state`.\n-\n-    Attributes\n-    ----------\n-    n_iter_ : int\n-        The number of iterations as selected by early stopping (if\n-        n_iter_no_change is not None). Otherwise it corresponds to max_iter.\n-    n_trees_per_iteration_ : int\n-        The number of tree that are built at each iteration. For regressors,\n-        this is always 1.\n-    train_score_ : ndarray, shape (n_iter_ + 1,)\n-        The scores at each iteration on the training data. The first entry\n-        is the score of the ensemble before the first iteration. Scores are\n-        computed according to the ``scoring`` parameter. If ``scoring`` is\n-        not 'loss', scores are computed on a subset of at most 10 000\n-        samples. Empty if no early stopping.\n-    validation_score_ : ndarray, shape (n_iter_ + 1,)\n-        The scores at each iteration on the held-out validation data. The\n-        first entry is the score of the ensemble before the first iteration.\n-        Scores are computed according to the ``scoring`` parameter. Empty if\n-        no early stopping or if ``validation_fraction`` is None.\n-\n-    Examples\n-    --------\n-    >>> # To use this experimental feature, we need to explicitly ask for it:\n-    >>> from sklearn.experimental import enable_hist_gradient_boosting  # noqa\n-    >>> from sklearn.ensemble import HistGradientBoostingRegressor\n-    >>> from sklearn.datasets import load_boston\n-    >>> X, y = load_boston(return_X_y=True)\n-    >>> est = HistGradientBoostingRegressor().fit(X, y)\n-    >>> est.score(X, y)\n-    0.98...\n-    \"\"\"\n-\n-    _VALID_LOSSES = ('least_squares',)\n-\n-    def __init__(self, loss='least_squares', learning_rate=0.1,\n-                 max_iter=100, max_leaf_nodes=31, max_depth=None,\n-                 min_samples_leaf=20, l2_regularization=0., max_bins=255,\n-                 warm_start=False, scoring=None, validation_fraction=0.1,\n-                 n_iter_no_change=None, tol=1e-7, verbose=0,\n-                 random_state=None):\n-        super(HistGradientBoostingRegressor, self).__init__(\n-            loss=loss, learning_rate=learning_rate, max_iter=max_iter,\n-            max_leaf_nodes=max_leaf_nodes, max_depth=max_depth,\n-            min_samples_leaf=min_samples_leaf,\n-            l2_regularization=l2_regularization, max_bins=max_bins,\n-            warm_start=warm_start, scoring=scoring,\n-            validation_fraction=validation_fraction,\n-            n_iter_no_change=n_iter_no_change, tol=tol, verbose=verbose,\n-            random_state=random_state)\n-\n-    def predict(self, X):\n-        \"\"\"Predict values for X.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape (n_samples, n_features)\n-            The input samples.\n-\n-        Returns\n-        -------\n-        y : ndarray, shape (n_samples,)\n-            The predicted values.\n-        \"\"\"\n-        # Return raw predictions after converting shape\n-        # (n_samples, 1) to (n_samples,)\n-        return self._raw_predict(X).ravel()\n-\n-    def _encode_y(self, y):\n-        # Just convert y to the expected dtype\n-        self.n_trees_per_iteration_ = 1\n-        y = y.astype(Y_DTYPE, copy=False)\n-        return y\n-\n-    def _get_loss(self):\n-        return _LOSSES[self.loss]()\n-\n-\n-class HistGradientBoostingClassifier(BaseHistGradientBoosting,\n-                                     ClassifierMixin):\n-    \"\"\"Histogram-based Gradient Boosting Classification Tree.\n-\n-    This estimator is much faster than\n-    :class:`GradientBoostingClassifier<sklearn.ensemble.GradientBoostingClassifier>`\n-    for big datasets (n_samples >= 10 000).\n-\n-    This estimator has native support for missing values (NaNs). During\n-    training, the tree grower learns at each split point whether samples\n-    with missing values should go to the left or right child, based on the\n-    potential gain. When predicting, samples with missing values are\n-    assigned to the left or right child consequently. If no missing values\n-    were encountered for a given feature during training, then samples with\n-    missing values are mapped to whichever child has the most samples.\n-\n-    This implementation is inspired by\n-    `LightGBM <https://github.com/Microsoft/LightGBM>`_.\n-\n-    .. note::\n-\n-      This estimator is still **experimental** for now: the predictions\n-      and the API might change without any deprecation cycle. To use it,\n-      you need to explicitly import ``enable_hist_gradient_boosting``::\n-\n-        >>> # explicitly require this experimental feature\n-        >>> from sklearn.experimental import enable_hist_gradient_boosting  # noqa\n-        >>> # now you can import normally from ensemble\n-        >>> from sklearn.ensemble import HistGradientBoostingClassifier\n-\n-    Read more in the :ref:`User Guide <histogram_based_gradient_boosting>`.\n-\n-    Parameters\n-    ----------\n-    loss : {'auto', 'binary_crossentropy', 'categorical_crossentropy'}, \\\n-            optional (default='auto')\n-        The loss function to use in the boosting process. 'binary_crossentropy'\n-        (also known as logistic loss) is used for binary classification and\n-        generalizes to 'categorical_crossentropy' for multiclass\n-        classification. 'auto' will automatically choose either loss depending\n-        on the nature of the problem.\n-    learning_rate : float, optional (default=0.1)\n-        The learning rate, also known as *shrinkage*. This is used as a\n-        multiplicative factor for the leaves values. Use ``1`` for no\n-        shrinkage.\n-    max_iter : int, optional (default=100)\n-        The maximum number of iterations of the boosting process, i.e. the\n-        maximum number of trees for binary classification. For multiclass\n-        classification, `n_classes` trees per iteration are built.\n-    max_leaf_nodes : int or None, optional (default=31)\n-        The maximum number of leaves for each tree. Must be strictly greater\n-        than 1. If None, there is no maximum limit.\n-    max_depth : int or None, optional (default=None)\n-        The maximum depth of each tree. The depth of a tree is the number of\n-        nodes to go from the root to the deepest leaf. Must be strictly greater\n-        than 1. Depth isn't constrained by default.\n-    min_samples_leaf : int, optional (default=20)\n-        The minimum number of samples per leaf. For small datasets with less\n-        than a few hundred samples, it is recommended to lower this value\n-        since only very shallow trees would be built.\n-    l2_regularization : float, optional (default=0)\n-        The L2 regularization parameter. Use 0 for no regularization.\n-    max_bins : int, optional (default=255)\n-        The maximum number of bins to use for non-missing values. Before\n-        training, each feature of the input array `X` is binned into\n-        integer-valued bins, which allows for a much faster training stage.\n-        Features with a small number of unique values may use less than\n-        ``max_bins`` bins. In addition to the ``max_bins`` bins, one more bin\n-        is always reserved for missing values. Must be no larger than 255.\n-    warm_start : bool, optional (default=False)\n-        When set to ``True``, reuse the solution of the previous call to fit\n-        and add more estimators to the ensemble. For results to be valid, the\n-        estimator should be re-trained on the same data only.\n-        See :term:`the Glossary <warm_start>`.\n-    scoring : str or callable or None, optional (default=None)\n-        Scoring parameter to use for early stopping. It can be a single\n-        string (see :ref:`scoring_parameter`) or a callable (see\n-        :ref:`scoring`). If None, the estimator's default scorer\n-        is used. If ``scoring='loss'``, early stopping is checked\n-        w.r.t the loss value. Only used if ``n_iter_no_change`` is not None.\n-    validation_fraction : int or float or None, optional (default=0.1)\n-        Proportion (or absolute size) of training data to set aside as\n-        validation data for early stopping. If None, early stopping is done on\n-        the training data.\n-    n_iter_no_change : int or None, optional (default=None)\n-        Used to determine when to \"early stop\". The fitting process is\n-        stopped when none of the last ``n_iter_no_change`` scores are better\n-        than the ``n_iter_no_change - 1`` -th-to-last one, up to some\n-        tolerance. If None or 0, no early-stopping is done.\n-    tol : float or None, optional (default=1e-7)\n-        The absolute tolerance to use when comparing scores. The higher the\n-        tolerance, the more likely we are to early stop: higher tolerance\n-        means that it will be harder for subsequent iterations to be\n-        considered an improvement upon the reference score.\n-    verbose: int, optional (default=0)\n-        The verbosity level. If not zero, print some information about the\n-        fitting process.\n-    random_state : int, np.random.RandomStateInstance or None, \\\n-        optional (default=None)\n-        Pseudo-random number generator to control the subsampling in the\n-        binning process, and the train/validation data split if early stopping\n-        is enabled. See :term:`random_state`.\n-\n-    Attributes\n-    ----------\n-    n_iter_ : int\n-        The number of estimators as selected by early stopping (if\n-        n_iter_no_change is not None). Otherwise it corresponds to max_iter.\n-    n_trees_per_iteration_ : int\n-        The number of tree that are built at each iteration. This is equal to 1\n-        for binary classification, and to ``n_classes`` for multiclass\n-        classification.\n-    train_score_ : ndarray, shape (n_iter_ + 1,)\n-        The scores at each iteration on the training data. The first entry\n-        is the score of the ensemble before the first iteration. Scores are\n-        computed according to the ``scoring`` parameter. If ``scoring`` is\n-        not 'loss', scores are computed on a subset of at most 10 000\n-        samples. Empty if no early stopping.\n-    validation_score_ : ndarray, shape (n_iter_ + 1,)\n-        The scores at each iteration on the held-out validation data. The\n-        first entry is the score of the ensemble before the first iteration.\n-        Scores are computed according to the ``scoring`` parameter. Empty if\n-        no early stopping or if ``validation_fraction`` is None.\n-\n-    Examples\n-    --------\n-    >>> # To use this experimental feature, we need to explicitly ask for it:\n-    >>> from sklearn.experimental import enable_hist_gradient_boosting  # noqa\n-    >>> from sklearn.ensemble import HistGradientBoostingRegressor\n-    >>> from sklearn.datasets import load_iris\n-    >>> X, y = load_iris(return_X_y=True)\n-    >>> clf = HistGradientBoostingClassifier().fit(X, y)\n-    >>> clf.score(X, y)\n-    1.0\n-    \"\"\"\n-\n-    _VALID_LOSSES = ('binary_crossentropy', 'categorical_crossentropy',\n-                     'auto')\n-\n-    def __init__(self, loss='auto', learning_rate=0.1, max_iter=100,\n-                 max_leaf_nodes=31, max_depth=None, min_samples_leaf=20,\n-                 l2_regularization=0., max_bins=255, warm_start=False,\n-                 scoring=None, validation_fraction=0.1, n_iter_no_change=None,\n-                 tol=1e-7, verbose=0, random_state=None):\n-        super(HistGradientBoostingClassifier, self).__init__(\n-            loss=loss, learning_rate=learning_rate, max_iter=max_iter,\n-            max_leaf_nodes=max_leaf_nodes, max_depth=max_depth,\n-            min_samples_leaf=min_samples_leaf,\n-            l2_regularization=l2_regularization, max_bins=max_bins,\n-            warm_start=warm_start, scoring=scoring,\n-            validation_fraction=validation_fraction,\n-            n_iter_no_change=n_iter_no_change, tol=tol, verbose=verbose,\n-            random_state=random_state)\n-\n-    def predict(self, X):\n-        \"\"\"Predict classes for X.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape (n_samples, n_features)\n-            The input samples.\n-\n-        Returns\n-        -------\n-        y : ndarray, shape (n_samples,)\n-            The predicted classes.\n-        \"\"\"\n-        # TODO: This could be done in parallel\n-        encoded_classes = np.argmax(self.predict_proba(X), axis=1)\n-        return self.classes_[encoded_classes]\n-\n-    def predict_proba(self, X):\n-        \"\"\"Predict class probabilities for X.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape (n_samples, n_features)\n-            The input samples.\n-\n-        Returns\n-        -------\n-        p : ndarray, shape (n_samples, n_classes)\n-            The class probabilities of the input samples.\n-        \"\"\"\n-        raw_predictions = self._raw_predict(X)\n-        return self.loss_.predict_proba(raw_predictions)\n-\n-    def decision_function(self, X):\n-        \"\"\"Compute the decision function of X.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape (n_samples, n_features)\n-            The input samples.\n-\n-        Returns\n-        -------\n-        decision : ndarray, shape (n_samples,) or \\\n-                (n_samples, n_trees_per_iteration)\n-            The raw predicted values (i.e. the sum of the trees leaves) for\n-            each sample. n_trees_per_iteration is equal to the number of\n-            classes in multiclass classification.\n-        \"\"\"\n-        decision = self._raw_predict(X)\n-        if decision.shape[0] == 1:\n-            decision = decision.ravel()\n-        return decision.T\n-\n-    def _encode_y(self, y):\n-        # encode classes into 0 ... n_classes - 1 and sets attributes classes_\n-        # and n_trees_per_iteration_\n-        check_classification_targets(y)\n-\n-        label_encoder = LabelEncoder()\n-        encoded_y = label_encoder.fit_transform(y)\n-        self.classes_ = label_encoder.classes_\n-        n_classes = self.classes_.shape[0]\n-        # only 1 tree for binary classification. For multiclass classification,\n-        # we build 1 tree per class.\n-        self.n_trees_per_iteration_ = 1 if n_classes <= 2 else n_classes\n-        encoded_y = encoded_y.astype(Y_DTYPE, copy=False)\n-        return encoded_y\n-\n-    def _get_loss(self):\n-        if self.loss == 'auto':\n-            if self.n_trees_per_iteration_ == 1:\n-                return _LOSSES['binary_crossentropy']()\n-            else:\n-                return _LOSSES['categorical_crossentropy']()\n-\n-        return _LOSSES[self.loss]()\n+PLACEHOLDER\n\\ No newline at end of file\n", "model": "claude-sonnet-5-5", "steps": 9, "finished": true, "patch_lines": 1051, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 1051, "steps": 9}], "ms": 60164}
{"instance_id": "scikit-learn__scikit-learn-14894", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/svm/base.py b/sklearn/svm/base.py\nindex 64cebe8375..43fd85a67b 100644\n--- a/sklearn/svm/base.py\n+++ b/sklearn/svm/base.py\n@@ -286,12 +286,15 @@ class BaseLibSVM(BaseEstimator, metaclass=ABCMeta):\n             n_class = 1\n         n_SV = self.support_vectors_.shape[0]\n \n-        dual_coef_indices = np.tile(np.arange(n_SV), n_class)\n-        dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1,\n-                                     dual_coef_indices.size / n_class)\n-        self.dual_coef_ = sp.csr_matrix(\n-            (dual_coef_data, dual_coef_indices, dual_coef_indptr),\n-            (n_class, n_SV))\n+        if not n_SV:\n+            self.dual_coef_ = sp.csr_matrix([])\n+        else:\n+            dual_coef_indices = np.tile(np.arange(n_SV), n_class)\n+            dual_coef_indptr = np.arange(0, dual_coef_indices.size + 1,\n+                                         dual_coef_indices.size / n_class)\n+            self.dual_coef_ = sp.csr_matrix(\n+                (dual_coef_data, dual_coef_indices, dual_coef_indptr),\n+                (n_class, n_SV))\n \n     def predict(self, X):\n         \"\"\"Perform regression on samples in X.\n", "model": "claude-sonnet-5-5", "steps": 3, "finished": true, "patch_lines": 26, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 26, "steps": 3}], "ms": 9072}
