{"instance_id": "scikit-learn__scikit-learn-10844", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/metrics/cluster/supervised.py b/sklearn/metrics/cluster/supervised.py\nindex a987778ae5..9bcca75a24 100644\n--- a/sklearn/metrics/cluster/supervised.py\n+++ b/sklearn/metrics/cluster/supervised.py\n@@ -856,7 +856,7 @@ def fowlkes_mallows_score(labels_true, labels_pred, sparse=False):\n     tk = np.dot(c.data, c.data) - n_samples\n     pk = np.sum(np.asarray(c.sum(axis=0)).ravel() ** 2) - n_samples\n     qk = np.sum(np.asarray(c.sum(axis=1)).ravel() ** 2) - n_samples\n-    return tk / np.sqrt(pk * qk) if tk != 0. else 0.\n+    return np.sqrt(tk / pk) * np.sqrt(tk / qk) if tk != 0. else 0.\n \n \n def entropy(labels):\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 13, "steps": 6}], "ms": 14618}
{"instance_id": "scikit-learn__scikit-learn-10908", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/feature_extraction/text.py b/sklearn/feature_extraction/text.py\nindex 9b1ebd6320..9ed4c30ecb 100644\n--- a/sklearn/feature_extraction/text.py\n+++ b/sklearn/feature_extraction/text.py\n@@ -300,6 +300,9 @@ class VectorizerMixin(object):\n \n     def _check_vocabulary(self):\n         \"\"\"Check if vocabulary is empty or missing (not fit-ed)\"\"\"\n+        if not hasattr(self, 'vocabulary_'):\n+            self._validate_vocabulary()\n+\n         msg = \"%(name)s - Vocabulary wasn't fitted.\"\n         check_is_fitted(self, 'vocabulary_', msg=msg),\n \n@@ -950,9 +953,6 @@ class CountVectorizer(BaseEstimator, VectorizerMixin):\n                 \"Iterable over raw text documents expected, \"\n                 \"string object received.\")\n \n-        if not hasattr(self, 'vocabulary_'):\n-            self._validate_vocabulary()\n-\n         self._check_vocabulary()\n \n         # use the same matrix-building strategy as fit_transform\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 24, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 24, "steps": 7}], "ms": 17052}
{"instance_id": "scikit-learn__scikit-learn-11578", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/linear_model/logistic.py b/sklearn/linear_model/logistic.py\nindex e4ea696ce7..c4d2e1881d 100644\n--- a/sklearn/linear_model/logistic.py\n+++ b/sklearn/linear_model/logistic.py\n@@ -922,7 +922,8 @@ def _log_reg_scoring_path(X, y, train, test, pos_class=None, Cs=10,\n         check_input=False, max_squared_sum=max_squared_sum,\n         sample_weight=sample_weight)\n \n-    log_reg = LogisticRegression(fit_intercept=fit_intercept)\n+    log_reg = LogisticRegression(fit_intercept=fit_intercept,\n+                                 multi_class=multi_class)\n \n     # The score method of Logistic Regression has a classes_ attribute.\n     if multi_class == 'ovr':\n", "model": "claude-sonnet-5-5", "steps": 7, "finished": true, "patch_lines": 14, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 14, "steps": 7}], "ms": 12450}
{"instance_id": "scikit-learn__scikit-learn-12585", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/base.py b/sklearn/base.py\nindex 56ffb18bf8..fb42081295 100644\n--- a/sklearn/base.py\n+++ b/sklearn/base.py\n@@ -48,7 +48,7 @@ def clone(estimator, safe=True):\n     # XXX: not handling dictionaries\n     if estimator_type in (list, tuple, set, frozenset):\n         return estimator_type([clone(e, safe=safe) for e in estimator])\n-    elif not hasattr(estimator, 'get_params'):\n+    elif not hasattr(estimator, 'get_params') or isinstance(estimator, type):\n         if not safe:\n             return copy.deepcopy(estimator)\n         else:\n@@ -180,7 +180,8 @@ class BaseEstimator(object):\n         out = dict()\n         for key in self._get_param_names():\n             value = getattr(self, key, None)\n-            if deep and hasattr(value, 'get_params'):\n+            if deep and hasattr(value, 'get_params') and not isinstance(\n+                    value, type):\n                 deep_items = value.get_params().items()\n                 out.update((key + '__' + k, val) for k, val in deep_items)\n             out[key] = value\n", "model": "claude-sonnet-5-5", "steps": 6, "finished": true, "patch_lines": 23, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 23, "steps": 6}], "ms": 15109}
{"instance_id": "scikit-learn__scikit-learn-12682", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/decomposition/dict_learning.py b/sklearn/decomposition/dict_learning.py\nindex a318c957fe..c1f562fd7b 100644\n--- a/sklearn/decomposition/dict_learning.py\n+++ b/sklearn/decomposition/dict_learning.py\n@@ -865,8 +865,10 @@ class SparseCodingMixin(TransformerMixin):\n                                   transform_algorithm='omp',\n                                   transform_n_nonzero_coefs=None,\n                                   transform_alpha=None, split_sign=False,\n-                                  n_jobs=None, positive_code=False):\n+                                  n_jobs=None, positive_code=False,\n+                                  transform_max_iter=1000):\n         self.n_components = n_components\n+        self.transform_max_iter = transform_max_iter\n         self.transform_algorithm = transform_algorithm\n         self.transform_n_nonzero_coefs = transform_n_nonzero_coefs\n         self.transform_alpha = transform_alpha\n@@ -900,7 +902,8 @@ class SparseCodingMixin(TransformerMixin):\n             X, self.components_, algorithm=self.transform_algorithm,\n             n_nonzero_coefs=self.transform_n_nonzero_coefs,\n             alpha=self.transform_alpha, n_jobs=self.n_jobs,\n-            positive=self.positive_code)\n+            positive=self.positive_code,\n+            max_iter=self.transform_max_iter)\n \n         if self.split_sign:\n             # feature vector is split into a positive and negative side\n@@ -974,6 +977,12 @@ class SparseCoder(BaseEstimator, SparseCodingMixin):\n \n         .. versionadded:: 0.20\n \n+    transform_max_iter : int, optional (default=1000)\n+        Maximum number of iterations to perform if `algorithm='lasso_cd'` or\n+        `lasso_lars`.\n+\n+        .. versionadded:: 0.22\n+\n     Attributes\n     ----------\n     components_ : array, [n_components, n_features]\n@@ -991,12 +1000,13 @@ class SparseCoder(BaseEstimator, SparseCodingMixin):\n \n     def __init__(self, dictionary, transform_algorithm='omp',\n                  transform_n_nonzero_coefs=None, transform_alpha=None,\n-                 split_sign=False, n_jobs=None, positive_code=False):\n+                 split_sign=False, n_jobs=None, positive_code=False,\n+                 transform_max_iter=1000):\n         self._set_sparse_coding_params(dictionary.shape[0],\n                                        transform_algorithm,\n                                        transform_n_nonzero_coefs,\n                                        transform_alpha, split_sign, n_jobs,\n-                                       positive_code)\n+                                       positive_code, transform_max_iter)\n         self.components_ = dictionary\n \n     def fit(self, X, y=None):\n@@ -1122,6 +1132,12 @@ class DictionaryLearning(BaseEstimator, SparseCodingMixin):\n \n         .. versionadded:: 0.20\n \n+    transform_max_iter : int, optional (default=1000)\n+        Maximum number of iterations to perform if `algorithm='lasso_cd'` or\n+        `lasso_lars`.\n+\n+        .. versionadded:: 0.22\n+\n     Attributes\n     ----------\n     components_ : array, [n_components, n_features]\n@@ -1152,12 +1168,13 @@ class DictionaryLearning(BaseEstimator, SparseCodingMixin):\n                  transform_n_nonzero_coefs=None, transform_alpha=None,\n                  n_jobs=None, code_init=None, dict_init=None, verbose=False,\n                  split_sign=False, random_state=None,\n-                 positive_code=False, positive_dict=False):\n+                 positive_code=False, positive_dict=False,\n+                 transform_max_iter=1000):\n \n         self._set_sparse_coding_params(n_components, transform_algorithm,\n                                        transform_n_nonzero_coefs,\n                                        transform_alpha, split_sign, n_jobs,\n-                                       positive_code)\n+                                       positive_code, transform_max_iter)\n         self.alpha = alpha\n         self.max_iter = max_iter\n         self.tol = tol\n@@ -1305,6 +1322,12 @@ class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin):\n \n         .. versionadded:: 0.20\n \n+    transform_max_iter : int, optional (default=1000)\n+        Maximum number of iterations to perform if `algorithm='lasso_cd'` or\n+        `lasso_lars`.\n+\n+        .. versionadded:: 0.22\n+\n     Attributes\n     ----------\n     components_ : array, [n_components, n_features]\n@@ -1341,12 +1364,13 @@ class MiniBatchDictionaryLearning(BaseEstimator, SparseCodingMixin):\n                  shuffle=True, dict_init=None, transform_algorithm='omp',\n                  transform_n_nonzero_coefs=None, transform_alpha=None,\n                  verbose=False, split_sign=False, random_state=None,\n-                 positive_code=False, positive_dict=False):\n+                 positive_code=False, positive_dict=False,\n+                 transform_max_iter=1000):\n \n         self._set_sparse_coding_params(n_components, transform_algorithm,\n                                        transform_n_nonzero_coefs,\n                                        transform_alpha, split_sign, n_jobs,\n-                                       positive_code)\n+                                       positive_code, transform_max_iter)\n         self.alpha = alpha\n         self.n_iter = n_iter\n         self.fit_algorithm = fit_algorithm\n", "model": "claude-sonnet-5-5", "steps": 13, "finished": true, "patch_lines": 113, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 113, "steps": 13}], "ms": 37563}
{"instance_id": "scikit-learn__scikit-learn-12973", "model_name_or_path": "cain-70b-e124", "model_patch": "diff --git a/sklearn/linear_model/least_angle.py b/sklearn/linear_model/least_angle.py\nindex 03b34a0dc0..76c2ac4069 100644\n--- a/sklearn/linear_model/least_angle.py\n+++ b/sklearn/linear_model/least_angle.py\n@@ -1,1546 +1 @@\n-\"\"\"\n-Least Angle Regression algorithm. See the documentation on the\n-Generalized Linear Model for a complete discussion.\n-\"\"\"\n-from __future__ import print_function\n-\n-# Author: Fabian Pedregosa <fabian.pedregosa@inria.fr>\n-#         Alexandre Gramfort <alexandre.gramfort@inria.fr>\n-#         Gael Varoquaux\n-#\n-# License: BSD 3 clause\n-\n-from math import log\n-import sys\n-import warnings\n-\n-import numpy as np\n-from scipy import linalg, interpolate\n-from scipy.linalg.lapack import get_lapack_funcs\n-\n-from .base import LinearModel\n-from ..base import RegressorMixin\n-from ..utils import arrayfuncs, as_float_array, check_X_y\n-from ..model_selection import check_cv\n-from ..exceptions import ConvergenceWarning\n-from ..utils._joblib import Parallel, delayed\n-\n-solve_triangular_args = {'check_finite': False}\n-\n-\n-def lars_path(X, y, Xy=None, Gram=None, max_iter=500,\n-              alpha_min=0, method='lar', copy_X=True,\n-              eps=np.finfo(np.float).eps,\n-              copy_Gram=True, verbose=0, return_path=True,\n-              return_n_iter=False, positive=False):\n-    \"\"\"Compute Least Angle Regression or Lasso path using LARS algorithm [1]\n-\n-    The optimization objective for the case method='lasso' is::\n-\n-    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n-\n-    in the case of method='lars', the objective function is only known in\n-    the form of an implicit equation (see discussion in [1])\n-\n-    Read more in the :ref:`User Guide <least_angle_regression>`.\n-\n-    Parameters\n-    -----------\n-    X : array, shape: (n_samples, n_features)\n-        Input data.\n-\n-    y : array, shape: (n_samples)\n-        Input targets.\n-\n-    Xy : array-like, shape (n_samples,) or (n_samples, n_targets), \\\n-            optional\n-        Xy = np.dot(X.T, y) that can be precomputed. It is useful\n-        only when the Gram matrix is precomputed.\n-\n-    Gram : None, 'auto', array, shape: (n_features, n_features), optional\n-        Precomputed Gram matrix (X' * X), if ``'auto'``, the Gram\n-        matrix is precomputed from the given X, if there are more samples\n-        than features.\n-\n-    max_iter : integer, optional (default=500)\n-        Maximum number of iterations to perform, set to infinity for no limit.\n-\n-    alpha_min : float, optional (default=0)\n-        Minimum correlation along the path. It corresponds to the\n-        regularization parameter alpha parameter in the Lasso.\n-\n-    method : {'lar', 'lasso'}, optional (default='lar')\n-        Specifies the returned model. Select ``'lar'`` for Least Angle\n-        Regression, ``'lasso'`` for the Lasso.\n-\n-    copy_X : bool, optional (default=True)\n-        If ``False``, ``X`` is overwritten.\n-\n-    eps : float, optional (default=``np.finfo(np.float).eps``)\n-        The machine-precision regularization in the computation of the\n-        Cholesky diagonal factors. Increase this for very ill-conditioned\n-        systems.\n-\n-    copy_Gram : bool, optional (default=True)\n-        If ``False``, ``Gram`` is overwritten.\n-\n-    verbose : int (default=0)\n-        Controls output verbosity.\n-\n-    return_path : bool, optional (default=True)\n-        If ``return_path==True`` returns the entire path, else returns only the\n-        last point of the path.\n-\n-    return_n_iter : bool, optional (default=False)\n-        Whether to return the number of iterations.\n-\n-    positive : boolean (default=False)\n-        Restrict coefficients to be >= 0.\n-        This option is only allowed with method 'lasso'. Note that the model\n-        coefficients will not converge to the ordinary-least-squares solution\n-        for small values of alpha. Only coefficients up to the smallest alpha\n-        value (``alphas_[alphas_ > 0.].min()`` when fit_path=True) reached by\n-        the stepwise Lars-Lasso algorithm are typically in congruence with the\n-        solution of the coordinate descent lasso_path function.\n-\n-    Returns\n-    --------\n-    alphas : array, shape: [n_alphas + 1]\n-        Maximum of covariances (in absolute value) at each iteration.\n-        ``n_alphas`` is either ``max_iter``, ``n_features`` or the\n-        number of nodes in the path with ``alpha >= alpha_min``, whichever\n-        is smaller.\n-\n-    active : array, shape [n_alphas]\n-        Indices of active variables at the end of the path.\n-\n-    coefs : array, shape (n_features, n_alphas + 1)\n-        Coefficients along the path\n-\n-    n_iter : int\n-        Number of iterations run. Returned only if return_n_iter is set\n-        to True.\n-\n-    See also\n-    --------\n-    lasso_path\n-    LassoLars\n-    Lars\n-    LassoLarsCV\n-    LarsCV\n-    sklearn.decomposition.sparse_encode\n-\n-    References\n-    ----------\n-    .. [1] \"Least Angle Regression\", Effron et al.\n-           https://statweb.stanford.edu/~tibs/ftp/lars.pdf\n-\n-    .. [2] `Wikipedia entry on the Least-angle regression\n-           <https://en.wikipedia.org/wiki/Least-angle_regression>`_\n-\n-    .. [3] `Wikipedia entry on the Lasso\n-           <https://en.wikipedia.org/wiki/Lasso_(statistics)>`_\n-\n-    \"\"\"\n-    if method == 'lar' and positive:\n-        warnings.warn('positive option is broken for Least'\n-                      ' Angle Regression (LAR). Use method=\"lasso\".'\n-                      ' This option will be removed in version 0.22.',\n-                      DeprecationWarning)\n-\n-    n_features = X.shape[1]\n-    n_samples = y.size\n-    max_features = min(max_iter, n_features)\n-\n-    if return_path:\n-        coefs = np.zeros((max_features + 1, n_features))\n-        alphas = np.zeros(max_features + 1)\n-    else:\n-        coef, prev_coef = np.zeros(n_features), np.zeros(n_features)\n-        alpha, prev_alpha = np.array([0.]), np.array([0.])  # better ideas?\n-\n-    n_iter, n_active = 0, 0\n-    active, indices = list(), np.arange(n_features)\n-    # holds the sign of covariance\n-    sign_active = np.empty(max_features, dtype=np.int8)\n-    drop = False\n-\n-    # will hold the cholesky factorization. Only lower part is\n-    # referenced.\n-    L = np.empty((max_features, max_features), dtype=X.dtype)\n-    swap, nrm2 = linalg.get_blas_funcs(('swap', 'nrm2'), (X,))\n-    solve_cholesky, = get_lapack_funcs(('potrs',), (X,))\n-\n-    if Gram is None or Gram is False:\n-        Gram = None\n-        if copy_X:\n-            # force copy. setting the array to be fortran-ordered\n-            # speeds up the calculation of the (partial) Gram matrix\n-            # and allows to easily swap columns\n-            X = X.copy('F')\n-\n-    elif isinstance(Gram, str) and Gram == 'auto' or Gram is True:\n-        if Gram is True or X.shape[0] > X.shape[1]:\n-            Gram = np.dot(X.T, X)\n-        else:\n-            Gram = None\n-    elif copy_Gram:\n-        Gram = Gram.copy()\n-\n-    if Xy is None:\n-        Cov = np.dot(X.T, y)\n-    else:\n-        Cov = Xy.copy()\n-\n-    if verbose:\n-        if verbose > 1:\n-            print(\"Step\\t\\tAdded\\t\\tDropped\\t\\tActive set size\\t\\tC\")\n-        else:\n-            sys.stdout.write('.')\n-            sys.stdout.flush()\n-\n-    tiny32 = np.finfo(np.float32).tiny  # to avoid division by 0 warning\n-    equality_tolerance = np.finfo(np.float32).eps\n-\n-    while True:\n-        if Cov.size:\n-            if positive:\n-                C_idx = np.argmax(Cov)\n-            else:\n-                C_idx = np.argmax(np.abs(Cov))\n-\n-            C_ = Cov[C_idx]\n-\n-            if positive:\n-                C = C_\n-            else:\n-                C = np.fabs(C_)\n-        else:\n-            C = 0.\n-\n-        if return_path:\n-            alpha = alphas[n_iter, np.newaxis]\n-            coef = coefs[n_iter]\n-            prev_alpha = alphas[n_iter - 1, np.newaxis]\n-            prev_coef = coefs[n_iter - 1]\n-\n-        alpha[0] = C / n_samples\n-        if alpha[0] <= alpha_min + equality_tolerance:  # early stopping\n-            if abs(alpha[0] - alpha_min) > equality_tolerance:\n-                # interpolation factor 0 <= ss < 1\n-                if n_iter > 0:\n-                    # In the first iteration, all alphas are zero, the formula\n-                    # below would make ss a NaN\n-                    ss = ((prev_alpha[0] - alpha_min) /\n-                          (prev_alpha[0] - alpha[0]))\n-                    coef[:] = prev_coef + ss * (coef - prev_coef)\n-                alpha[0] = alpha_min\n-            if return_path:\n-                coefs[n_iter] = coef\n-            break\n-\n-        if n_iter >= max_iter or n_active >= n_features:\n-            break\n-\n-        if not drop:\n-\n-            ##########################################################\n-            # Append x_j to the Cholesky factorization of (Xa * Xa') #\n-            #                                                        #\n-            #            ( L   0 )                                   #\n-            #     L  ->  (       )  , where L * w = Xa' x_j          #\n-            #            ( w   z )    and z = ||x_j||                #\n-            #                                                        #\n-            ##########################################################\n-\n-            if positive:\n-                sign_active[n_active] = np.ones_like(C_)\n-            else:\n-                sign_active[n_active] = np.sign(C_)\n-            m, n = n_active, C_idx + n_active\n-\n-            Cov[C_idx], Cov[0] = swap(Cov[C_idx], Cov[0])\n-            indices[n], indices[m] = indices[m], indices[n]\n-            Cov_not_shortened = Cov\n-            Cov = Cov[1:]  # remove Cov[0]\n-\n-            if Gram is None:\n-                X.T[n], X.T[m] = swap(X.T[n], X.T[m])\n-                c = nrm2(X.T[n_active]) ** 2\n-                L[n_active, :n_active] = \\\n-                    np.dot(X.T[n_active], X.T[:n_active].T)\n-            else:\n-                # swap does only work inplace if matrix is fortran\n-                # contiguous ...\n-                Gram[m], Gram[n] = swap(Gram[m], Gram[n])\n-                Gram[:, m], Gram[:, n] = swap(Gram[:, m], Gram[:, n])\n-                c = Gram[n_active, n_active]\n-                L[n_active, :n_active] = Gram[n_active, :n_active]\n-\n-            # Update the cholesky decomposition for the Gram matrix\n-            if n_active:\n-                linalg.solve_triangular(L[:n_active, :n_active],\n-                                        L[n_active, :n_active],\n-                                        trans=0, lower=1,\n-                                        overwrite_b=True,\n-                                        **solve_triangular_args)\n-\n-            v = np.dot(L[n_active, :n_active], L[n_active, :n_active])\n-            diag = max(np.sqrt(np.abs(c - v)), eps)\n-            L[n_active, n_active] = diag\n-\n-            if diag < 1e-7:\n-                # The system is becoming too ill-conditioned.\n-                # We have degenerate vectors in our active set.\n-                # We'll 'drop for good' the last regressor added.\n-\n-                # Note: this case is very rare. It is no longer triggered by\n-                # the test suite. The `equality_tolerance` margin added in 0.16\n-                # to get early stopping to work consistently on all versions of\n-                # Python including 32 bit Python under Windows seems to make it\n-                # very difficult to trigger the 'drop for good' strategy.\n-                warnings.warn('Regressors in active set degenerate. '\n-                              'Dropping a regressor, after %i iterations, '\n-                              'i.e. alpha=%.3e, '\n-                              'with an active set of %i regressors, and '\n-                              'the smallest cholesky pivot element being %.3e.'\n-                              ' Reduce max_iter or increase eps parameters.'\n-                              % (n_iter, alpha, n_active, diag),\n-                              ConvergenceWarning)\n-\n-                # XXX: need to figure a 'drop for good' way\n-                Cov = Cov_not_shortened\n-                Cov[0] = 0\n-                Cov[C_idx], Cov[0] = swap(Cov[C_idx], Cov[0])\n-                continue\n-\n-            active.append(indices[n_active])\n-            n_active += 1\n-\n-            if verbose > 1:\n-                print(\"%s\\t\\t%s\\t\\t%s\\t\\t%s\\t\\t%s\" % (n_iter, active[-1], '',\n-                                                      n_active, C))\n-\n-        if method == 'lasso' and n_iter > 0 and prev_alpha[0] < alpha[0]:\n-            # alpha is increasing. This is because the updates of Cov are\n-            # bringing in too much numerical error that is greater than\n-            # than the remaining correlation with the\n-            # regressors. Time to bail out\n-            warnings.warn('Early stopping the lars path, as the residues '\n-                          'are small and the current value of alpha is no '\n-                          'longer well controlled. %i iterations, alpha=%.3e, '\n-                          'previous alpha=%.3e, with an active set of %i '\n-                          'regressors.'\n-                          % (n_iter, alpha, prev_alpha, n_active),\n-                          ConvergenceWarning)\n-            break\n-\n-        # least squares solution\n-        least_squares, info = solve_cholesky(L[:n_active, :n_active],\n-                                             sign_active[:n_active],\n-                                             lower=True)\n-\n-        if least_squares.size == 1 and least_squares == 0:\n-            # This happens because sign_active[:n_active] = 0\n-            least_squares[...] = 1\n-            AA = 1.\n-        else:\n-            # is this really needed ?\n-            AA = 1. / np.sqrt(np.sum(least_squares * sign_active[:n_active]))\n-\n-            if not np.isfinite(AA):\n-                # L is too ill-conditioned\n-                i = 0\n-                L_ = L[:n_active, :n_active].copy()\n-                while not np.isfinite(AA):\n-                    L_.flat[::n_active + 1] += (2 ** i) * eps\n-                    least_squares, info = solve_cholesky(\n-                        L_, sign_active[:n_active], lower=True)\n-                    tmp = max(np.sum(least_squares * sign_active[:n_active]),\n-                              eps)\n-                    AA = 1. / np.sqrt(tmp)\n-                    i += 1\n-            least_squares *= AA\n-\n-        if Gram is None:\n-            # equiangular direction of variables in the active set\n-            eq_dir = np.dot(X.T[:n_active].T, least_squares)\n-            # correlation between each unactive variables and\n-            # eqiangular vector\n-            corr_eq_dir = np.dot(X.T[n_active:], eq_dir)\n-        else:\n-            # if huge number of features, this takes 50% of time, I\n-            # think could be avoided if we just update it using an\n-            # orthogonal (QR) decomposition of X\n-            corr_eq_dir = np.dot(Gram[:n_active, n_active:].T,\n-                                 least_squares)\n-\n-        g1 = arrayfuncs.min_pos((C - Cov) / (AA - corr_eq_dir + tiny32))\n-        if positive:\n-            gamma_ = min(g1, C / AA)\n-        else:\n-            g2 = arrayfuncs.min_pos((C + Cov) / (AA + corr_eq_dir + tiny32))\n-            gamma_ = min(g1, g2, C / AA)\n-\n-        # TODO: better names for these variables: z\n-        drop = False\n-        z = -coef[active] / (least_squares + tiny32)\n-        z_pos = arrayfuncs.min_pos(z)\n-        if z_pos < gamma_:\n-            # some coefficients have changed sign\n-            idx = np.where(z == z_pos)[0][::-1]\n-\n-            # update the sign, important for LAR\n-            sign_active[idx] = -sign_active[idx]\n-\n-            if method == 'lasso':\n-                gamma_ = z_pos\n-            drop = True\n-\n-        n_iter += 1\n-\n-        if return_path:\n-            if n_iter >= coefs.shape[0]:\n-                del coef, alpha, prev_alpha, prev_coef\n-                # resize the coefs and alphas array\n-                add_features = 2 * max(1, (max_features - n_active))\n-                coefs = np.resize(coefs, (n_iter + add_features, n_features))\n-                coefs[-add_features:] = 0\n-                alphas = np.resize(alphas, n_iter + add_features)\n-                alphas[-add_features:] = 0\n-            coef = coefs[n_iter]\n-            prev_coef = coefs[n_iter - 1]\n-        else:\n-            # mimic the effect of incrementing n_iter on the array references\n-            prev_coef = coef\n-            prev_alpha[0] = alpha[0]\n-            coef = np.zeros_like(coef)\n-\n-        coef[active] = prev_coef[active] + gamma_ * least_squares\n-\n-        # update correlations\n-        Cov -= gamma_ * corr_eq_dir\n-\n-        # See if any coefficient has changed sign\n-        if drop and method == 'lasso':\n-\n-            # handle the case when idx is not length of 1\n-            [arrayfuncs.cholesky_delete(L[:n_active, :n_active], ii) for ii in\n-                idx]\n-\n-            n_active -= 1\n-            # handle the case when idx is not length of 1\n-            drop_idx = [active.pop(ii) for ii in idx]\n-\n-            if Gram is None:\n-                # propagate dropped variable\n-                for ii in idx:\n-                    for i in range(ii, n_active):\n-                        X.T[i], X.T[i + 1] = swap(X.T[i], X.T[i + 1])\n-                        # yeah this is stupid\n-                        indices[i], indices[i + 1] = indices[i + 1], indices[i]\n-\n-                # TODO: this could be updated\n-                residual = y - np.dot(X[:, :n_active], coef[active])\n-                temp = np.dot(X.T[n_active], residual)\n-\n-                Cov = np.r_[temp, Cov]\n-            else:\n-                for ii in idx:\n-                    for i in range(ii, n_active):\n-                        indices[i], indices[i + 1] = indices[i + 1], indices[i]\n-                        Gram[i], Gram[i + 1] = swap(Gram[i], Gram[i + 1])\n-                        Gram[:, i], Gram[:, i + 1] = swap(Gram[:, i],\n-                                                          Gram[:, i + 1])\n-\n-                # Cov_n = Cov_j + x_j * X + increment(betas) TODO:\n-                # will this still work with multiple drops ?\n-\n-                # recompute covariance. Probably could be done better\n-                # wrong as Xy is not swapped with the rest of variables\n-\n-                # TODO: this could be updated\n-                residual = y - np.dot(X, coef)\n-                temp = np.dot(X.T[drop_idx], residual)\n-                Cov = np.r_[temp, Cov]\n-\n-            sign_active = np.delete(sign_active, idx)\n-            sign_active = np.append(sign_active, 0.)  # just to maintain size\n-            if verbose > 1:\n-                print(\"%s\\t\\t%s\\t\\t%s\\t\\t%s\\t\\t%s\" % (n_iter, '', drop_idx,\n-                                                      n_active, abs(temp)))\n-\n-    if return_path:\n-        # resize coefs in case of early stop\n-        alphas = alphas[:n_iter + 1]\n-        coefs = coefs[:n_iter + 1]\n-\n-        if return_n_iter:\n-            return alphas, active, coefs.T, n_iter\n-        else:\n-            return alphas, active, coefs.T\n-    else:\n-        if return_n_iter:\n-            return alpha, active, coef, n_iter\n-        else:\n-            return alpha, active, coef\n-\n-\n-###############################################################################\n-# Estimator classes\n-\n-class Lars(LinearModel, RegressorMixin):\n-    \"\"\"Least Angle Regression model a.k.a. LAR\n-\n-    Read more in the :ref:`User Guide <least_angle_regression>`.\n-\n-    Parameters\n-    ----------\n-    fit_intercept : boolean\n-        Whether to calculate the intercept for this model. If set\n-        to false, no intercept will be used in calculations\n-        (e.g. data is expected to be already centered).\n-\n-    verbose : boolean or integer, optional\n-        Sets the verbosity amount\n-\n-    normalize : boolean, optional, default True\n-        This parameter is ignored when ``fit_intercept`` is set to False.\n-        If True, the regressors X will be normalized before regression by\n-        subtracting the mean and dividing by the l2-norm.\n-        If you wish to standardize, please use\n-        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``\n-        on an estimator with ``normalize=False``.\n-\n-    precompute : True | False | 'auto' | array-like\n-        Whether to use a precomputed Gram matrix to speed up\n-        calculations. If set to ``'auto'`` let us decide. The Gram\n-        matrix can also be passed as argument.\n-\n-    n_nonzero_coefs : int, optional\n-        Target number of non-zero coefficients. Use ``np.inf`` for no limit.\n-\n-    eps : float, optional\n-        The machine-precision regularization in the computation of the\n-        Cholesky diagonal factors. Increase this for very ill-conditioned\n-        systems. Unlike the ``tol`` parameter in some iterative\n-        optimization-based algorithms, this parameter does not control\n-        the tolerance of the optimization.\n-\n-    copy_X : boolean, optional, default True\n-        If ``True``, X will be copied; else, it may be overwritten.\n-\n-    fit_path : boolean\n-        If True the full path is stored in the ``coef_path_`` attribute.\n-        If you compute the solution for a large problem or many targets,\n-        setting ``fit_path`` to ``False`` will lead to a speedup, especially\n-        with a small alpha.\n-\n-    positive : boolean (default=False)\n-        Restrict coefficients to be >= 0. Be aware that you might want to\n-        remove fit_intercept which is set True by default.\n-\n-        .. deprecated:: 0.20\n-\n-            The option is broken and deprecated. It will be removed in v0.22.\n-\n-    Attributes\n-    ----------\n-    alphas_ : array, shape (n_alphas + 1,) | list of n_targets such arrays\n-        Maximum of covariances (in absolute value) at each iteration. \\\n-        ``n_alphas`` is either ``n_nonzero_coefs`` or ``n_features``, \\\n-        whichever is smaller.\n-\n-    active_ : list, length = n_alphas | list of n_targets such lists\n-        Indices of active variables at the end of the path.\n-\n-    coef_path_ : array, shape (n_features, n_alphas + 1) \\\n-        | list of n_targets such arrays\n-        The varying values of the coefficients along the path. It is not\n-        present if the ``fit_path`` parameter is ``False``.\n-\n-    coef_ : array, shape (n_features,) or (n_targets, n_features)\n-        Parameter vector (w in the formulation formula).\n-\n-    intercept_ : float | array, shape (n_targets,)\n-        Independent term in decision function.\n-\n-    n_iter_ : array-like or int\n-        The number of iterations taken by lars_path to find the\n-        grid of alphas for each target.\n-\n-    Examples\n-    --------\n-    >>> from sklearn import linear_model\n-    >>> reg = linear_model.Lars(n_nonzero_coefs=1)\n-    >>> reg.fit([[-1, 1], [0, 0], [1, 1]], [-1.1111, 0, -1.1111])\n-    ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n-    Lars(copy_X=True, eps=..., fit_intercept=True, fit_path=True,\n-       n_nonzero_coefs=1, normalize=True, positive=False, precompute='auto',\n-       verbose=False)\n-    >>> print(reg.coef_) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n-    [ 0. -1.11...]\n-\n-    See also\n-    --------\n-    lars_path, LarsCV\n-    sklearn.decomposition.sparse_encode\n-\n-    \"\"\"\n-    method = 'lar'\n-\n-    def __init__(self, fit_intercept=True, verbose=False, normalize=True,\n-                 precompute='auto', n_nonzero_coefs=500,\n-                 eps=np.finfo(np.float).eps, copy_X=True, fit_path=True,\n-                 positive=False):\n-        self.fit_intercept = fit_intercept\n-        self.verbose = verbose\n-        self.normalize = normalize\n-        self.precompute = precompute\n-        self.n_nonzero_coefs = n_nonzero_coefs\n-        self.positive = positive\n-        self.eps = eps\n-        self.copy_X = copy_X\n-        self.fit_path = fit_path\n-\n-    @staticmethod\n-    def _get_gram(precompute, X, y):\n-        if (not hasattr(precompute, '__array__')) and (\n-                (precompute is True) or\n-                (precompute == 'auto' and X.shape[0] > X.shape[1]) or\n-                (precompute == 'auto' and y.shape[1] > 1)):\n-            precompute = np.dot(X.T, X)\n-\n-        return precompute\n-\n-    def _fit(self, X, y, max_iter, alpha, fit_path, Xy=None):\n-        \"\"\"Auxiliary method to fit the model using X, y as training data\"\"\"\n-        n_features = X.shape[1]\n-\n-        X, y, X_offset, y_offset, X_scale = self._preprocess_data(\n-            X, y, self.fit_intercept, self.normalize, self.copy_X)\n-\n-        if y.ndim == 1:\n-            y = y[:, np.newaxis]\n-\n-        n_targets = y.shape[1]\n-\n-        Gram = self._get_gram(self.precompute, X, y)\n-\n-        self.alphas_ = []\n-        self.n_iter_ = []\n-        self.coef_ = np.empty((n_targets, n_features))\n-\n-        if fit_path:\n-            self.active_ = []\n-            self.coef_path_ = []\n-            for k in range(n_targets):\n-                this_Xy = None if Xy is None else Xy[:, k]\n-                alphas, active, coef_path, n_iter_ = lars_path(\n-                    X, y[:, k], Gram=Gram, Xy=this_Xy, copy_X=self.copy_X,\n-                    copy_Gram=True, alpha_min=alpha, method=self.method,\n-                    verbose=max(0, self.verbose - 1), max_iter=max_iter,\n-                    eps=self.eps, return_path=True,\n-                    return_n_iter=True, positive=self.positive)\n-                self.alphas_.append(alphas)\n-                self.active_.append(active)\n-                self.n_iter_.append(n_iter_)\n-                self.coef_path_.append(coef_path)\n-                self.coef_[k] = coef_path[:, -1]\n-\n-            if n_targets == 1:\n-                self.alphas_, self.active_, self.coef_path_, self.coef_ = [\n-                    a[0] for a in (self.alphas_, self.active_, self.coef_path_,\n-                                   self.coef_)]\n-                self.n_iter_ = self.n_iter_[0]\n-        else:\n-            for k in range(n_targets):\n-                this_Xy = None if Xy is None else Xy[:, k]\n-                alphas, _, self.coef_[k], n_iter_ = lars_path(\n-                    X, y[:, k], Gram=Gram, Xy=this_Xy, copy_X=self.copy_X,\n-                    copy_Gram=True, alpha_min=alpha, method=self.method,\n-                    verbose=max(0, self.verbose - 1), max_iter=max_iter,\n-                    eps=self.eps, return_path=False, return_n_iter=True,\n-                    positive=self.positive)\n-                self.alphas_.append(alphas)\n-                self.n_iter_.append(n_iter_)\n-            if n_targets == 1:\n-                self.alphas_ = self.alphas_[0]\n-                self.n_iter_ = self.n_iter_[0]\n-\n-        self._set_intercept(X_offset, y_offset, X_scale)\n-        return self\n-\n-    def fit(self, X, y, Xy=None):\n-        \"\"\"Fit the model using X, y as training data.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape (n_samples, n_features)\n-            Training data.\n-\n-        y : array-like, shape (n_samples,) or (n_samples, n_targets)\n-            Target values.\n-\n-        Xy : array-like, shape (n_samples,) or (n_samples, n_targets), \\\n-                optional\n-            Xy = np.dot(X.T, y) that can be precomputed. It is useful\n-            only when the Gram matrix is precomputed.\n-\n-        Returns\n-        -------\n-        self : object\n-            returns an instance of self.\n-        \"\"\"\n-        X, y = check_X_y(X, y, y_numeric=True, multi_output=True)\n-\n-        alpha = getattr(self, 'alpha', 0.)\n-        if hasattr(self, 'n_nonzero_coefs'):\n-            alpha = 0.  # n_nonzero_coefs parametrization takes priority\n-            max_iter = self.n_nonzero_coefs\n-        else:\n-            max_iter = self.max_iter\n-\n-        self._fit(X, y, max_iter=max_iter, alpha=alpha, fit_path=self.fit_path,\n-                  Xy=Xy)\n-\n-        return self\n-\n-\n-class LassoLars(Lars):\n-    \"\"\"Lasso model fit with Least Angle Regression a.k.a. Lars\n-\n-    It is a Linear Model trained with an L1 prior as regularizer.\n-\n-    The optimization objective for Lasso is::\n-\n-    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n-\n-    Read more in the :ref:`User Guide <least_angle_regression>`.\n-\n-    Parameters\n-    ----------\n-    alpha : float\n-        Constant that multiplies the penalty term. Defaults to 1.0.\n-        ``alpha = 0`` is equivalent to an ordinary least square, solved\n-        by :class:`LinearRegression`. For numerical reasons, using\n-        ``alpha = 0`` with the LassoLars object is not advised and you\n-        should prefer the LinearRegression object.\n-\n-    fit_intercept : boolean\n-        whether to calculate the intercept for this model. If set\n-        to false, no intercept will be used in calculations\n-        (e.g. data is expected to be already centered).\n-\n-    verbose : boolean or integer, optional\n-        Sets the verbosity amount\n-\n-    normalize : boolean, optional, default True\n-        This parameter is ignored when ``fit_intercept`` is set to False.\n-        If True, the regressors X will be normalized before regression by\n-        subtracting the mean and dividing by the l2-norm.\n-        If you wish to standardize, please use\n-        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``\n-        on an estimator with ``normalize=False``.\n-\n-    precompute : True | False | 'auto' | array-like\n-        Whether to use a precomputed Gram matrix to speed up\n-        calculations. If set to ``'auto'`` let us decide. The Gram\n-        matrix can also be passed as argument.\n-\n-    max_iter : integer, optional\n-        Maximum number of iterations to perform.\n-\n-    eps : float, optional\n-        The machine-precision regularization in the computation of the\n-        Cholesky diagonal factors. Increase this for very ill-conditioned\n-        systems. Unlike the ``tol`` parameter in some iterative\n-        optimization-based algorithms, this parameter does not control\n-        the tolerance of the optimization.\n-\n-    copy_X : boolean, optional, default True\n-        If True, X will be copied; else, it may be overwritten.\n-\n-    fit_path : boolean\n-        If ``True`` the full path is stored in the ``coef_path_`` attribute.\n-        If you compute the solution for a large problem or many targets,\n-        setting ``fit_path`` to ``False`` will lead to a speedup, especially\n-        with a small alpha.\n-\n-    positive : boolean (default=False)\n-        Restrict coefficients to be >= 0. Be aware that you might want to\n-        remove fit_intercept which is set True by default.\n-        Under the positive restriction the model coefficients will not converge\n-        to the ordinary-least-squares solution for small values of alpha.\n-        Only coefficients up to the smallest alpha value (``alphas_[alphas_ >\n-        0.].min()`` when fit_path=True) reached by the stepwise Lars-Lasso\n-        algorithm are typically in congruence with the solution of the\n-        coordinate descent Lasso estimator.\n-\n-    Attributes\n-    ----------\n-    alphas_ : array, shape (n_alphas + 1,) | list of n_targets such arrays\n-        Maximum of covariances (in absolute value) at each iteration. \\\n-        ``n_alphas`` is either ``max_iter``, ``n_features``, or the number of \\\n-        nodes in the path with correlation greater than ``alpha``, whichever \\\n-        is smaller.\n-\n-    active_ : list, length = n_alphas | list of n_targets such lists\n-        Indices of active variables at the end of the path.\n-\n-    coef_path_ : array, shape (n_features, n_alphas + 1) or list\n-        If a list is passed it's expected to be one of n_targets such arrays.\n-        The varying values of the coefficients along the path. It is not\n-        present if the ``fit_path`` parameter is ``False``.\n-\n-    coef_ : array, shape (n_features,) or (n_targets, n_features)\n-        Parameter vector (w in the formulation formula).\n-\n-    intercept_ : float | array, shape (n_targets,)\n-        Independent term in decision function.\n-\n-    n_iter_ : array-like or int.\n-        The number of iterations taken by lars_path to find the\n-        grid of alphas for each target.\n-\n-    Examples\n-    --------\n-    >>> from sklearn import linear_model\n-    >>> reg = linear_model.LassoLars(alpha=0.01)\n-    >>> reg.fit([[-1, 1], [0, 0], [1, 1]], [-1, 0, -1])\n-    ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n-    LassoLars(alpha=0.01, copy_X=True, eps=..., fit_intercept=True,\n-         fit_path=True, max_iter=500, normalize=True, positive=False,\n-         precompute='auto', verbose=False)\n-    >>> print(reg.coef_) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n-    [ 0.         -0.963257...]\n-\n-    See also\n-    --------\n-    lars_path\n-    lasso_path\n-    Lasso\n-    LassoCV\n-    LassoLarsCV\n-    LassoLarsIC\n-    sklearn.decomposition.sparse_encode\n-\n-    \"\"\"\n-    method = 'lasso'\n-\n-    def __init__(self, alpha=1.0, fit_intercept=True, verbose=False,\n-                 normalize=True, precompute='auto', max_iter=500,\n-                 eps=np.finfo(np.float).eps, copy_X=True, fit_path=True,\n-                 positive=False):\n-        self.alpha = alpha\n-        self.fit_intercept = fit_intercept\n-        self.max_iter = max_iter\n-        self.verbose = verbose\n-        self.normalize = normalize\n-        self.positive = positive\n-        self.precompute = precompute\n-        self.copy_X = copy_X\n-        self.eps = eps\n-        self.fit_path = fit_path\n-\n-\n-###############################################################################\n-# Cross-validated estimator classes\n-\n-def _check_copy_and_writeable(array, copy=False):\n-    if copy or not array.flags.writeable:\n-        return array.copy()\n-    return array\n-\n-\n-def _lars_path_residues(X_train, y_train, X_test, y_test, Gram=None,\n-                        copy=True, method='lars', verbose=False,\n-                        fit_intercept=True, normalize=True, max_iter=500,\n-                        eps=np.finfo(np.float).eps, positive=False):\n-    \"\"\"Compute the residues on left-out data for a full LARS path\n-\n-    Parameters\n-    -----------\n-    X_train : array, shape (n_samples, n_features)\n-        The data to fit the LARS on\n-\n-    y_train : array, shape (n_samples)\n-        The target variable to fit LARS on\n-\n-    X_test : array, shape (n_samples, n_features)\n-        The data to compute the residues on\n-\n-    y_test : array, shape (n_samples)\n-        The target variable to compute the residues on\n-\n-    Gram : None, 'auto', array, shape: (n_features, n_features), optional\n-        Precomputed Gram matrix (X' * X), if ``'auto'``, the Gram\n-        matrix is precomputed from the given X, if there are more samples\n-        than features\n-\n-    copy : boolean, optional\n-        Whether X_train, X_test, y_train and y_test should be copied;\n-        if False, they may be overwritten.\n-\n-    method : 'lar' | 'lasso'\n-        Specifies the returned model. Select ``'lar'`` for Least Angle\n-        Regression, ``'lasso'`` for the Lasso.\n-\n-    verbose : integer, optional\n-        Sets the amount of verbosity\n-\n-    fit_intercept : boolean\n-        whether to calculate the intercept for this model. If set\n-        to false, no intercept will be used in calculations\n-        (e.g. data is expected to be already centered).\n-\n-    positive : boolean (default=False)\n-        Restrict coefficients to be >= 0. Be aware that you might want to\n-        remove fit_intercept which is set True by default.\n-        See reservations for using this option in combination with method\n-        'lasso' for expected small values of alpha in the doc of LassoLarsCV\n-        and LassoLarsIC.\n-\n-    normalize : boolean, optional, default True\n-        This parameter is ignored when ``fit_intercept`` is set to False.\n-        If True, the regressors X will be normalized before regression by\n-        subtracting the mean and dividing by the l2-norm.\n-        If you wish to standardize, please use\n-        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``\n-        on an estimator with ``normalize=False``.\n-\n-    max_iter : integer, optional\n-        Maximum number of iterations to perform.\n-\n-    eps : float, optional\n-        The machine-precision regularization in the computation of the\n-        Cholesky diagonal factors. Increase this for very ill-conditioned\n-        systems. Unlike the ``tol`` parameter in some iterative\n-        optimization-based algorithms, this parameter does not control\n-        the tolerance of the optimization.\n-\n-\n-    Returns\n-    --------\n-    alphas : array, shape (n_alphas,)\n-        Maximum of covariances (in absolute value) at each iteration.\n-        ``n_alphas`` is either ``max_iter`` or ``n_features``, whichever\n-        is smaller.\n-\n-    active : list\n-        Indices of active variables at the end of the path.\n-\n-    coefs : array, shape (n_features, n_alphas)\n-        Coefficients along the path\n-\n-    residues : array, shape (n_alphas, n_samples)\n-        Residues of the prediction on the test data\n-    \"\"\"\n-    X_train = _check_copy_and_writeable(X_train, copy)\n-    y_train = _check_copy_and_writeable(y_train, copy)\n-    X_test = _check_copy_and_writeable(X_test, copy)\n-    y_test = _check_copy_and_writeable(y_test, copy)\n-\n-    if fit_intercept:\n-        X_mean = X_train.mean(axis=0)\n-        X_train -= X_mean\n-        X_test -= X_mean\n-        y_mean = y_train.mean(axis=0)\n-        y_train = as_float_array(y_train, copy=False)\n-        y_train -= y_mean\n-        y_test = as_float_array(y_test, copy=False)\n-        y_test -= y_mean\n-\n-    if normalize:\n-        norms = np.sqrt(np.sum(X_train ** 2, axis=0))\n-        nonzeros = np.flatnonzero(norms)\n-        X_train[:, nonzeros] /= norms[nonzeros]\n-\n-    alphas, active, coefs = lars_path(\n-        X_train, y_train, Gram=Gram, copy_X=False, copy_Gram=False,\n-        method=method, verbose=max(0, verbose - 1), max_iter=max_iter, eps=eps,\n-        positive=positive)\n-    if normalize:\n-        coefs[nonzeros] /= norms[nonzeros][:, np.newaxis]\n-    residues = np.dot(X_test, coefs) - y_test[:, np.newaxis]\n-    return alphas, active, coefs, residues.T\n-\n-\n-class LarsCV(Lars):\n-    \"\"\"Cross-validated Least Angle Regression model.\n-\n-    See glossary entry for :term:`cross-validation estimator`.\n-\n-    Read more in the :ref:`User Guide <least_angle_regression>`.\n-\n-    Parameters\n-    ----------\n-    fit_intercept : boolean\n-        whether to calculate the intercept for this model. If set\n-        to false, no intercept will be used in calculations\n-        (e.g. data is expected to be already centered).\n-\n-    verbose : boolean or integer, optional\n-        Sets the verbosity amount\n-\n-    max_iter : integer, optional\n-        Maximum number of iterations to perform.\n-\n-    normalize : boolean, optional, default True\n-        This parameter is ignored when ``fit_intercept`` is set to False.\n-        If True, the regressors X will be normalized before regression by\n-        subtracting the mean and dividing by the l2-norm.\n-        If you wish to standardize, please use\n-        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``\n-        on an estimator with ``normalize=False``.\n-\n-    precompute : True | False | 'auto' | array-like\n-        Whether to use a precomputed Gram matrix to speed up\n-        calculations. If set to ``'auto'`` let us decide. The Gram matrix\n-        cannot be passed as argument since we will use only subsets of X.\n-\n-    cv : int, cross-validation generator or an iterable, optional\n-        Determines the cross-validation splitting strategy.\n-        Possible inputs for cv are:\n-\n-        - None, to use the default 3-fold cross-validation,\n-        - integer, to specify the number of folds.\n-        - :term:`CV splitter`,\n-        - An iterable yielding (train, test) splits as arrays of indices.\n-\n-        For integer/None inputs, :class:`KFold` is used.\n-\n-        Refer :ref:`User Guide <cross_validation>` for the various\n-        cross-validation strategies that can be used here.\n-\n-        .. versionchanged:: 0.20\n-            ``cv`` default value if None will change from 3-fold to 5-fold\n-            in v0.22.\n-\n-    max_n_alphas : integer, optional\n-        The maximum number of points on the path used to compute the\n-        residuals in the cross-validation\n-\n-    n_jobs : int or None, optional (default=None)\n-        Number of CPUs to use during the cross validation.\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-    eps : float, optional\n-        The machine-precision regularization in the computation of the\n-        Cholesky diagonal factors. Increase this for very ill-conditioned\n-        systems.\n-\n-    copy_X : boolean, optional, default True\n-        If ``True``, X will be copied; else, it may be overwritten.\n-\n-    positive : boolean (default=False)\n-        Restrict coefficients to be >= 0. Be aware that you might want to\n-        remove fit_intercept which is set True by default.\n-\n-        .. deprecated:: 0.20\n-            The option is broken and deprecated. It will be removed in v0.22.\n-\n-    Attributes\n-    ----------\n-    coef_ : array, shape (n_features,)\n-        parameter vector (w in the formulation formula)\n-\n-    intercept_ : float\n-        independent term in decision function\n-\n-    coef_path_ : array, shape (n_features, n_alphas)\n-        the varying values of the coefficients along the path\n-\n-    alpha_ : float\n-        the estimated regularization parameter alpha\n-\n-    alphas_ : array, shape (n_alphas,)\n-        the different values of alpha along the path\n-\n-    cv_alphas_ : array, shape (n_cv_alphas,)\n-        all the values of alpha along the path for the different folds\n-\n-    mse_path_ : array, shape (n_folds, n_cv_alphas)\n-        the mean square error on left-out for each fold along the path\n-        (alpha values given by ``cv_alphas``)\n-\n-    n_iter_ : array-like or int\n-        the number of iterations run by Lars with the optimal alpha.\n-\n-    Examples\n-    --------\n-    >>> from sklearn.linear_model import LarsCV\n-    >>> from sklearn.datasets import make_regression\n-    >>> X, y = make_regression(n_samples=200, noise=4.0, random_state=0)\n-    >>> reg = LarsCV(cv=5).fit(X, y)\n-    >>> reg.score(X, y) # doctest: +ELLIPSIS\n-    0.9996...\n-    >>> reg.alpha_\n-    0.0254...\n-    >>> reg.predict(X[:1,])\n-    array([154.0842...])\n-\n-    See also\n-    --------\n-    lars_path, LassoLars, LassoLarsCV\n-    \"\"\"\n-\n-    method = 'lar'\n-\n-    def __init__(self, fit_intercept=True, verbose=False, max_iter=500,\n-                 normalize=True, precompute='auto', cv='warn',\n-                 max_n_alphas=1000, n_jobs=None, eps=np.finfo(np.float).eps,\n-                 copy_X=True, positive=False):\n-        self.max_iter = max_iter\n-        self.cv = cv\n-        self.max_n_alphas = max_n_alphas\n-        self.n_jobs = n_jobs\n-        super().__init__(fit_intercept=fit_intercept,\n-                         verbose=verbose, normalize=normalize,\n-                         precompute=precompute,\n-                         n_nonzero_coefs=500,\n-                         eps=eps, copy_X=copy_X, fit_path=True,\n-                         positive=positive)\n-\n-    def fit(self, X, y):\n-        \"\"\"Fit the model using X, y as training data.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape (n_samples, n_features)\n-            Training data.\n-\n-        y : array-like, shape (n_samples,)\n-            Target values.\n-\n-        Returns\n-        -------\n-        self : object\n-            returns an instance of self.\n-        \"\"\"\n-        X, y = check_X_y(X, y, y_numeric=True)\n-        X = as_float_array(X, copy=self.copy_X)\n-        y = as_float_array(y, copy=self.copy_X)\n-\n-        # init cross-validation generator\n-        cv = check_cv(self.cv, classifier=False)\n-\n-        # As we use cross-validation, the Gram matrix is not precomputed here\n-        Gram = self.precompute\n-        if hasattr(Gram, '__array__'):\n-            warnings.warn(\"Parameter 'precompute' cannot be an array in \"\n-                          \"%s. Automatically switch to 'auto' instead.\"\n-                          % self.__class__.__name__)\n-            Gram = 'auto'\n-\n-        cv_paths = Parallel(n_jobs=self.n_jobs, verbose=self.verbose)(\n-            delayed(_lars_path_residues)(\n-                X[train], y[train], X[test], y[test], Gram=Gram, copy=False,\n-                method=self.method, verbose=max(0, self.verbose - 1),\n-                normalize=self.normalize, fit_intercept=self.fit_intercept,\n-                max_iter=self.max_iter, eps=self.eps, positive=self.positive)\n-            for train, test in cv.split(X, y))\n-        all_alphas = np.concatenate(list(zip(*cv_paths))[0])\n-        # Unique also sorts\n-        all_alphas = np.unique(all_alphas)\n-        # Take at most max_n_alphas values\n-        stride = int(max(1, int(len(all_alphas) / float(self.max_n_alphas))))\n-        all_alphas = all_alphas[::stride]\n-\n-        mse_path = np.empty((len(all_alphas), len(cv_paths)))\n-        for index, (alphas, active, coefs, residues) in enumerate(cv_paths):\n-            alphas = alphas[::-1]\n-            residues = residues[::-1]\n-            if alphas[0] != 0:\n-                alphas = np.r_[0, alphas]\n-                residues = np.r_[residues[0, np.newaxis], residues]\n-            if alphas[-1] != all_alphas[-1]:\n-                alphas = np.r_[alphas, all_alphas[-1]]\n-                residues = np.r_[residues, residues[-1, np.newaxis]]\n-            this_residues = interpolate.interp1d(alphas,\n-                                                 residues,\n-                                                 axis=0)(all_alphas)\n-            this_residues **= 2\n-            mse_path[:, index] = np.mean(this_residues, axis=-1)\n-\n-        mask = np.all(np.isfinite(mse_path), axis=-1)\n-        all_alphas = all_alphas[mask]\n-        mse_path = mse_path[mask]\n-        # Select the alpha that minimizes left-out error\n-        i_best_alpha = np.argmin(mse_path.mean(axis=-1))\n-        best_alpha = all_alphas[i_best_alpha]\n-\n-        # Store our parameters\n-        self.alpha_ = best_alpha\n-        self.cv_alphas_ = all_alphas\n-        self.mse_path_ = mse_path\n-\n-        # Now compute the full model\n-        # it will call a lasso internally when self if LassoLarsCV\n-        # as self.method == 'lasso'\n-        self._fit(X, y, max_iter=self.max_iter, alpha=best_alpha,\n-                  Xy=None, fit_path=True)\n-        return self\n-\n-\n-class LassoLarsCV(LarsCV):\n-    \"\"\"Cross-validated Lasso, using the LARS algorithm.\n-\n-    See glossary entry for :term:`cross-validation estimator`.\n-\n-    The optimization objective for Lasso is::\n-\n-    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n-\n-    Read more in the :ref:`User Guide <least_angle_regression>`.\n-\n-    Parameters\n-    ----------\n-    fit_intercept : boolean\n-        whether to calculate the intercept for this model. If set\n-        to false, no intercept will be used in calculations\n-        (e.g. data is expected to be already centered).\n-\n-    verbose : boolean or integer, optional\n-        Sets the verbosity amount\n-\n-    max_iter : integer, optional\n-        Maximum number of iterations to perform.\n-\n-    normalize : boolean, optional, default True\n-        This parameter is ignored when ``fit_intercept`` is set to False.\n-        If True, the regressors X will be normalized before regression by\n-        subtracting the mean and dividing by the l2-norm.\n-        If you wish to standardize, please use\n-        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``\n-        on an estimator with ``normalize=False``.\n-\n-    precompute : True | False | 'auto'\n-        Whether to use a precomputed Gram matrix to speed up\n-        calculations. If set to ``'auto'`` let us decide. The Gram matrix\n-        cannot be passed as argument since we will use only subsets of X.\n-\n-    cv : int, cross-validation generator or an iterable, optional\n-        Determines the cross-validation splitting strategy.\n-        Possible inputs for cv are:\n-\n-        - None, to use the default 3-fold cross-validation,\n-        - integer, to specify the number of folds.\n-        - :term:`CV splitter`,\n-        - An iterable yielding (train, test) splits as arrays of indices.\n-\n-        For integer/None inputs, :class:`KFold` is used.\n-\n-        Refer :ref:`User Guide <cross_validation>` for the various\n-        cross-validation strategies that can be used here.\n-\n-        .. versionchanged:: 0.20\n-            ``cv`` default value if None will change from 3-fold to 5-fold\n-            in v0.22.\n-\n-    max_n_alphas : integer, optional\n-        The maximum number of points on the path used to compute the\n-        residuals in the cross-validation\n-\n-    n_jobs : int or None, optional (default=None)\n-        Number of CPUs to use during the cross validation.\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-    eps : float, optional\n-        The machine-precision regularization in the computation of the\n-        Cholesky diagonal factors. Increase this for very ill-conditioned\n-        systems.\n-\n-    copy_X : boolean, optional, default True\n-        If True, X will be copied; else, it may be overwritten.\n-\n-    positive : boolean (default=False)\n-        Restrict coefficients to be >= 0. Be aware that you might want to\n-        remove fit_intercept which is set True by default.\n-        Under the positive restriction the model coefficients do not converge\n-        to the ordinary-least-squares solution for small values of alpha.\n-        Only coefficients up to the smallest alpha value (``alphas_[alphas_ >\n-        0.].min()`` when fit_path=True) reached by the stepwise Lars-Lasso\n-        algorithm are typically in congruence with the solution of the\n-        coordinate descent Lasso estimator.\n-        As a consequence using LassoLarsCV only makes sense for problems where\n-        a sparse solution is expected and/or reached.\n-\n-    Attributes\n-    ----------\n-    coef_ : array, shape (n_features,)\n-        parameter vector (w in the formulation formula)\n-\n-    intercept_ : float\n-        independent term in decision function.\n-\n-    coef_path_ : array, shape (n_features, n_alphas)\n-        the varying values of the coefficients along the path\n-\n-    alpha_ : float\n-        the estimated regularization parameter alpha\n-\n-    alphas_ : array, shape (n_alphas,)\n-        the different values of alpha along the path\n-\n-    cv_alphas_ : array, shape (n_cv_alphas,)\n-        all the values of alpha along the path for the different folds\n-\n-    mse_path_ : array, shape (n_folds, n_cv_alphas)\n-        the mean square error on left-out for each fold along the path\n-        (alpha values given by ``cv_alphas``)\n-\n-    n_iter_ : array-like or int\n-        the number of iterations run by Lars with the optimal alpha.\n-\n-    Examples\n-    --------\n-    >>> from sklearn.linear_model import LassoLarsCV\n-    >>> from sklearn.datasets import make_regression\n-    >>> X, y = make_regression(noise=4.0, random_state=0)\n-    >>> reg = LassoLarsCV(cv=5).fit(X, y)\n-    >>> reg.score(X, y) # doctest: +ELLIPSIS\n-    0.9992...\n-    >>> reg.alpha_\n-    0.0484...\n-    >>> reg.predict(X[:1,])\n-    array([-77.8723...])\n-\n-    Notes\n-    -----\n-\n-    The object solves the same problem as the LassoCV object. However,\n-    unlike the LassoCV, it find the relevant alphas values by itself.\n-    In general, because of this property, it will be more stable.\n-    However, it is more fragile to heavily multicollinear datasets.\n-\n-    It is more efficient than the LassoCV if only a small number of\n-    features are selected compared to the total number, for instance if\n-    there are very few samples compared to the number of features.\n-\n-    See also\n-    --------\n-    lars_path, LassoLars, LarsCV, LassoCV\n-    \"\"\"\n-\n-    method = 'lasso'\n-\n-    def __init__(self, fit_intercept=True, verbose=False, max_iter=500,\n-                 normalize=True, precompute='auto', cv='warn',\n-                 max_n_alphas=1000, n_jobs=None, eps=np.finfo(np.float).eps,\n-                 copy_X=True, positive=False):\n-        self.fit_intercept = fit_intercept\n-        self.verbose = verbose\n-        self.max_iter = max_iter\n-        self.normalize = normalize\n-        self.precompute = precompute\n-        self.cv = cv\n-        self.max_n_alphas = max_n_alphas\n-        self.n_jobs = n_jobs\n-        self.eps = eps\n-        self.copy_X = copy_X\n-        self.positive = positive\n-        # XXX : we don't use super().__init__\n-        # to avoid setting n_nonzero_coefs\n-\n-\n-class LassoLarsIC(LassoLars):\n-    \"\"\"Lasso model fit with Lars using BIC or AIC for model selection\n-\n-    The optimization objective for Lasso is::\n-\n-    (1 / (2 * n_samples)) * ||y - Xw||^2_2 + alpha * ||w||_1\n-\n-    AIC is the Akaike information criterion and BIC is the Bayes\n-    Information criterion. Such criteria are useful to select the value\n-    of the regularization parameter by making a trade-off between the\n-    goodness of fit and the complexity of the model. A good model should\n-    explain well the data while being simple.\n-\n-    Read more in the :ref:`User Guide <least_angle_regression>`.\n-\n-    Parameters\n-    ----------\n-    criterion : 'bic' | 'aic'\n-        The type of criterion to use.\n-\n-    fit_intercept : boolean\n-        whether to calculate the intercept for this model. If set\n-        to false, no intercept will be used in calculations\n-        (e.g. data is expected to be already centered).\n-\n-    verbose : boolean or integer, optional\n-        Sets the verbosity amount\n-\n-    normalize : boolean, optional, default True\n-        This parameter is ignored when ``fit_intercept`` is set to False.\n-        If True, the regressors X will be normalized before regression by\n-        subtracting the mean and dividing by the l2-norm.\n-        If you wish to standardize, please use\n-        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``\n-        on an estimator with ``normalize=False``.\n-\n-    precompute : True | False | 'auto' | array-like\n-        Whether to use a precomputed Gram matrix to speed up\n-        calculations. If set to ``'auto'`` let us decide. The Gram\n-        matrix can also be passed as argument.\n-\n-    max_iter : integer, optional\n-        Maximum number of iterations to perform. Can be used for\n-        early stopping.\n-\n-    eps : float, optional\n-        The machine-precision regularization in the computation of the\n-        Cholesky diagonal factors. Increase this for very ill-conditioned\n-        systems. Unlike the ``tol`` parameter in some iterative\n-        optimization-based algorithms, this parameter does not control\n-        the tolerance of the optimization.\n-\n-    copy_X : boolean, optional, default True\n-        If True, X will be copied; else, it may be overwritten.\n-\n-    positive : boolean (default=False)\n-        Restrict coefficients to be >= 0. Be aware that you might want to\n-        remove fit_intercept which is set True by default.\n-        Under the positive restriction the model coefficients do not converge\n-        to the ordinary-least-squares solution for small values of alpha.\n-        Only coefficients up to the smallest alpha value (``alphas_[alphas_ >\n-        0.].min()`` when fit_path=True) reached by the stepwise Lars-Lasso\n-        algorithm are typically in congruence with the solution of the\n-        coordinate descent Lasso estimator.\n-        As a consequence using LassoLarsIC only makes sense for problems where\n-        a sparse solution is expected and/or reached.\n-\n-\n-    Attributes\n-    ----------\n-    coef_ : array, shape (n_features,)\n-        parameter vector (w in the formulation formula)\n-\n-    intercept_ : float\n-        independent term in decision function.\n-\n-    alpha_ : float\n-        the alpha parameter chosen by the information criterion\n-\n-    n_iter_ : int\n-        number of iterations run by lars_path to find the grid of\n-        alphas.\n-\n-    criterion_ : array, shape (n_alphas,)\n-        The value of the information criteria ('aic', 'bic') across all\n-        alphas. The alpha which has the smallest information criterion is\n-        chosen. This value is larger by a factor of ``n_samples`` compared to\n-        Eqns. 2.15 and 2.16 in (Zou et al, 2007).\n-\n-\n-    Examples\n-    --------\n-    >>> from sklearn import linear_model\n-    >>> reg = linear_model.LassoLarsIC(criterion='bic')\n-    >>> reg.fit([[-1, 1], [0, 0], [1, 1]], [-1.1111, 0, -1.1111])\n-    ... # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n-    LassoLarsIC(copy_X=True, criterion='bic', eps=..., fit_intercept=True,\n-          max_iter=500, normalize=True, positive=False, precompute='auto',\n-          verbose=False)\n-    >>> print(reg.coef_) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE\n-    [ 0.  -1.11...]\n-\n-    Notes\n-    -----\n-    The estimation of the number of degrees of freedom is given by:\n-\n-    \"On the degrees of freedom of the lasso\"\n-    Hui Zou, Trevor Hastie, and Robert Tibshirani\n-    Ann. Statist. Volume 35, Number 5 (2007), 2173-2192.\n-\n-    https://en.wikipedia.org/wiki/Akaike_information_criterion\n-    https://en.wikipedia.org/wiki/Bayesian_information_criterion\n-\n-    See also\n-    --------\n-    lars_path, LassoLars, LassoLarsCV\n-    \"\"\"\n-    def __init__(self, criterion='aic', fit_intercept=True, verbose=False,\n-                 normalize=True, precompute='auto', max_iter=500,\n-                 eps=np.finfo(np.float).eps, copy_X=True, positive=False):\n-        self.criterion = criterion\n-        self.fit_intercept = fit_intercept\n-        self.positive = positive\n-        self.max_iter = max_iter\n-        self.verbose = verbose\n-        self.normalize = normalize\n-        self.copy_X = copy_X\n-        self.precompute = precompute\n-        self.eps = eps\n-        self.fit_path = True\n-\n-    def fit(self, X, y, copy_X=True):\n-        \"\"\"Fit the model using X, y as training data.\n-\n-        Parameters\n-        ----------\n-        X : array-like, shape (n_samples, n_features)\n-            training data.\n-\n-        y : array-like, shape (n_samples,)\n-            target values. Will be cast to X's dtype if necessary\n-\n-        copy_X : boolean, optional, default True\n-            If ``True``, X will be copied; else, it may be overwritten.\n-\n-        Returns\n-        -------\n-        self : object\n-            returns an instance of self.\n-        \"\"\"\n-        X, y = check_X_y(X, y, y_numeric=True)\n-\n-        X, y, Xmean, ymean, Xstd = LinearModel._preprocess_data(\n-            X, y, self.fit_intercept, self.normalize, self.copy_X)\n-        max_iter = self.max_iter\n-\n-        Gram = self.precompute\n-\n-        alphas_, active_, coef_path_, self.n_iter_ = lars_path(\n-            X, y, Gram=Gram, copy_X=copy_X, copy_Gram=True, alpha_min=0.0,\n-            method='lasso', verbose=self.verbose, max_iter=max_iter,\n-            eps=self.eps, return_n_iter=True, positive=self.positive)\n-\n-        n_samples = X.shape[0]\n-\n-        if self.criterion == 'aic':\n-            K = 2  # AIC\n-        elif self.criterion == 'bic':\n-            K = log(n_samples)  # BIC\n-        else:\n-            raise ValueError('criterion should be either bic or aic')\n-\n-        R = y[:, np.newaxis] - np.dot(X, coef_path_)  # residuals\n-        mean_squared_error = np.mean(R ** 2, axis=0)\n-        sigma2 = np.var(y)\n-\n-        df = np.zeros(coef_path_.shape[1], dtype=np.int)  # Degrees of freedom\n-        for k, coef in enumerate(coef_path_.T):\n-            mask = np.abs(coef) > np.finfo(coef.dtype).eps\n-            if not np.any(mask):\n-                continue\n-            # get the number of degrees of freedom equal to:\n-            # Xc = X[:, mask]\n-            # Trace(Xc * inv(Xc.T, Xc) * Xc.T) ie the number of non-zero coefs\n-            df[k] = np.sum(mask)\n-\n-        self.alphas_ = alphas_\n-        eps64 = np.finfo('float64').eps\n-        self.criterion_ = (n_samples * mean_squared_error / (sigma2 + eps64) +\n-                           K * df)  # Eqns. 2.15--16 in (Zou et al, 2007)\n-        n_best = np.argmin(self.criterion_)\n-\n-        self.alpha_ = alphas_[n_best]\n-        self.coef_ = coef_path_[:, n_best]\n-        self._set_intercept(Xmean, ymean, Xstd)\n-        return self\n+def fit(self, X, y, copy_X=None):\\n        if copy_X is not None:\\n            self.copy_X = copy_X\\n        # rest of the function remains the same\n\\ No newline at end of file\n"}
{"instance_id": "scikit-learn__scikit-learn-13124", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/model_selection/_split.py b/sklearn/model_selection/_split.py\nindex 24394f8691..63d17758e5 100644\n--- a/sklearn/model_selection/_split.py\n+++ b/sklearn/model_selection/_split.py\n@@ -576,8 +576,7 @@ class StratifiedKFold(_BaseKFold):\n             ``n_splits`` default value will change from 3 to 5 in v0.22.\n \n     shuffle : boolean, optional\n-        Whether to shuffle each stratification of the data before splitting\n-        into batches.\n+        Whether to shuffle each class's samples before splitting into batches.\n \n     random_state : int, RandomState instance or None, optional, default=None\n         If int, random_state is the seed used by the random number generator;\n@@ -620,7 +619,7 @@ class StratifiedKFold(_BaseKFold):\n         super().__init__(n_splits, shuffle, random_state)\n \n     def _make_test_folds(self, X, y=None):\n-        rng = self.random_state\n+        rng = check_random_state(self.random_state)\n         y = np.asarray(y)\n         type_of_target_y = type_of_target(y)\n         allowed_target_types = ('binary', 'multiclass')\n@@ -631,8 +630,13 @@ class StratifiedKFold(_BaseKFold):\n \n         y = column_or_1d(y)\n         n_samples = y.shape[0]\n-        unique_y, y_inversed = np.unique(y, return_inverse=True)\n-        y_counts = np.bincount(y_inversed)\n+        # encode classes by order of first appearance\n+        _, y_idx, y_inv = np.unique(y, return_index=True, return_inverse=True)\n+        _, class_perm = np.unique(y_idx, return_inverse=True)\n+        y_encoded = class_perm[y_inv]\n+\n+        n_classes = len(y_idx)\n+        y_counts = np.bincount(y_encoded)\n         min_groups = np.min(y_counts)\n         if np.all(self.n_splits > y_counts):\n             raise ValueError(\"n_splits=%d cannot be greater than the\"\n@@ -645,29 +649,20 @@ class StratifiedKFold(_BaseKFold):\n                            \" be less than n_splits=%d.\"\n                            % (min_groups, self.n_splits)), Warning)\n \n-        # pre-assign each sample to a test fold index using individual KFold\n-        # splitting strategies for each class so as to respect the balance of\n-        # classes\n-        # NOTE: Passing the data corresponding to ith class say X[y==class_i]\n-        # will break when the data is not 100% stratifiable for all classes.\n-        # So we pass np.zeroes(max(c, n_splits)) as data to the KFold\n-        per_cls_cvs = [\n-            KFold(self.n_splits, shuffle=self.shuffle,\n-                  random_state=rng).split(np.zeros(max(count, self.n_splits)))\n-            for count in y_counts]\n-\n-        test_folds = np.zeros(n_samples, dtype=np.int)\n-        for test_fold_indices, per_cls_splits in enumerate(zip(*per_cls_cvs)):\n-            for cls, (_, test_split) in zip(unique_y, per_cls_splits):\n-                cls_test_folds = test_folds[y == cls]\n-                # the test split can be too big because we used\n-                # KFold(...).split(X[:max(c, n_splits)]) when data is not 100%\n-                # stratifiable for all the classes\n-                # (we use a warning instead of raising an exception)\n-                # If this is the case, let's trim it:\n-                test_split = test_split[test_split < len(cls_test_folds)]\n-                cls_test_folds[test_split] = test_fold_indices\n-                test_folds[y == cls] = cls_test_folds\n+        # Round robin allocation of the sorted classes gives the number of\n+        # samples of each class in each test fold.\n+        y_order = np.sort(y_encoded)\n+        allocation = np.asarray(\n+            [np.bincount(y_order[i::self.n_splits], minlength=n_classes)\n+             for i in range(self.n_splits)])\n+\n+        # Assign samples of each class to folds in blocks, shuffled if asked.\n+        test_folds = np.empty(n_samples, dtype='i')\n+        for k in range(n_classes):\n+            folds_for_class = np.arange(self.n_splits).repeat(allocation[:, k])\n+            if self.shuffle:\n+                rng.shuffle(folds_for_class)\n+            test_folds[y_encoded == k] = folds_for_class\n \n         return test_folds\n \n", "model": "claude-sonnet-5-5", "steps": 16, "finished": true, "patch_lines": 83, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 83, "steps": 16}], "ms": 44394}
{"instance_id": "scikit-learn__scikit-learn-13135", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/preprocessing/_discretization.py b/sklearn/preprocessing/_discretization.py\nindex dd969c12b2..35d654399d 100644\n--- a/sklearn/preprocessing/_discretization.py\n+++ b/sklearn/preprocessing/_discretization.py\n@@ -172,6 +172,8 @@ class KBinsDiscretizer(BaseEstimator, TransformerMixin):\n                 # 1D k-means procedure\n                 km = KMeans(n_clusters=n_bins[jj], init=init, n_init=1)\n                 centers = km.fit(column[:, None]).cluster_centers_[:, 0]\n+                # Must sort, centers may be unsorted even with sorted init\n+                centers.sort()\n                 bin_edges[jj] = (centers[1:] + centers[:-1]) * 0.5\n                 bin_edges[jj] = np.r_[col_min, bin_edges[jj], col_max]\n \n", "model": "claude-sonnet-5-5", "steps": 3, "finished": true, "patch_lines": 13, "candidates": [{"compile_ok": 0, "loc_hits": 1, "files": 1, "diff_lines": 13, "steps": 3}], "ms": 8117}
{"instance_id": "scikit-learn__scikit-learn-13142", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/mixture/base.py b/sklearn/mixture/base.py\nindex bd34333c06..8920bef181 100644\n--- a/sklearn/mixture/base.py\n+++ b/sklearn/mixture/base.py\n@@ -257,11 +257,6 @@ class BaseMixture(DensityMixin, BaseEstimator, metaclass=ABCMeta):\n                 best_params = self._get_parameters()\n                 best_n_iter = n_iter\n \n-        # Always do a final e-step to guarantee that the labels returned by\n-        # fit_predict(X) are always consistent with fit(X).predict(X)\n-        # for any value of max_iter and tol (and any random_state).\n-        _, log_resp = self._e_step(X)\n-\n         if not self.converged_:\n             warnings.warn('Initialization %d did not converge. '\n                           'Try different init parameters, '\n@@ -273,6 +268,11 @@ class BaseMixture(DensityMixin, BaseEstimator, metaclass=ABCMeta):\n         self.n_iter_ = best_n_iter\n         self.lower_bound_ = max_lower_bound\n \n+        # Always do a final e-step to guarantee that the labels returned by\n+        # fit_predict(X) are always consistent with fit(X).predict(X)\n+        # for any value of max_iter and tol (and any random_state).\n+        _, log_resp = self._e_step(X)\n+\n         return log_resp.argmax(axis=1)\n \n     def _e_step(self, X):\n", "model": "claude-sonnet-5-5", "steps": 10, "finished": true, "patch_lines": 28, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 28, "steps": 10}], "ms": 38587}
{"instance_id": "scikit-learn__scikit-learn-13328", "model_name_or_path": "cain-anthropic-e124", "model_patch": "diff --git a/sklearn/linear_model/huber.py b/sklearn/linear_model/huber.py\nindex 65c6864007..2859136848 100644\n--- a/sklearn/linear_model/huber.py\n+++ b/sklearn/linear_model/huber.py\n@@ -251,7 +251,8 @@ class HuberRegressor(LinearModel, RegressorMixin, BaseEstimator):\n         self : object\n         \"\"\"\n         X, y = check_X_y(\n-            X, y, copy=False, accept_sparse=['csr'], y_numeric=True)\n+            X, y, copy=False, accept_sparse=['csr'], y_numeric=True,\n+            dtype=[np.float64, np.float32])\n         if sample_weight is not None:\n             sample_weight = np.array(sample_weight)\n             check_consistent_length(y, sample_weight)\n", "model": "claude-sonnet-5-5", "steps": 5, "finished": true, "patch_lines": 14, "candidates": [{"compile_ok": 0, "loc_hits": 0, "files": 1, "diff_lines": 14, "steps": 5}], "ms": 12036}
