From de97082688045619219737324cafe1acc42ef376 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sol=C3=A8ne=20PERRET?= Date: Fri, 12 Jan 2024 14:57:06 +0100 Subject: [PATCH 1/6] Modification of the documentation for the fit method in the Ridge class. --- sklearn/linear_model/_ridge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index e39af10053c34..0b69a154dd229 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -1142,7 +1142,7 @@ def fit(self, X, y, sample_weight=None): sample_weight : float or ndarray of shape (n_samples,), default=None Individual weights for each sample. If given a float, every sample - will have the same weight. + will have the same weight. The sample_weight vector should sum to one. Returns ------- From ab87f0af706251a5a657136bf81437d7a1ae128b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sol=C3=A8ne=20PERRET?= Date: Fri, 12 Jan 2024 15:25:25 +0100 Subject: [PATCH 2/6] Correction of linting. --- sklearn/linear_model/_ridge.py | 78 ++++++++++++++++++++++------------ 1 file changed, 52 insertions(+), 26 deletions(-) diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index 0b69a154dd229..703be2b94a3c0 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -56,7 +56,8 @@ def matvec(b): def rmatvec(b): return X.T.dot(b) - X_offset * b.dot(sample_weight_sqrt) - X1 = sparse.linalg.LinearOperator(shape=X.shape, matvec=matvec, rmatvec=rmatvec) + X1 = sparse.linalg.LinearOperator( + shape=X.shape, matvec=matvec, rmatvec=rmatvec) return X1 @@ -119,7 +120,8 @@ def _mv(x): C = sp_linalg.LinearOperator( (n_features, n_features), matvec=mv, dtype=X.dtype ) - coefs[i], info = _sparse_linalg_cg(C, y_column, maxiter=max_iter, rtol=tol) + coefs[i], info = _sparse_linalg_cg( + C, y_column, maxiter=max_iter, rtol=tol) if info < 0: raise ValueError("Failed with error code %d" % info) @@ -206,7 +208,8 @@ def _solve_cholesky(X, y, alpha): coefs = np.empty([n_targets, n_features], dtype=X.dtype) for coef, target, current_alpha in zip(coefs, Xy.T, alpha): A.flat[:: n_features + 1] += current_alpha - coef[:] = linalg.solve(A, target, assume_a="pos", overwrite_a=False).ravel() + coef[:] = linalg.solve( + A, target, assume_a="pos", overwrite_a=False).ravel() A.flat[:: n_features + 1] -= current_alpha return coefs @@ -221,7 +224,8 @@ def _solve_cholesky_kernel(K, y, alpha, sample_weight=None, copy=False): alpha = np.atleast_1d(alpha) one_alpha = (alpha == alpha[0]).all() - has_sw = isinstance(sample_weight, np.ndarray) or sample_weight not in [1.0, None] + has_sw = isinstance(sample_weight, np.ndarray) or sample_weight not in [ + 1.0, None] if has_sw: # Unlike other solvers, we need to support sample_weight directly @@ -374,7 +378,8 @@ def _get_valid_accept_sparse(is_X_sparse, solver): ], "solver": [ StrOptions( - {"auto", "svd", "cholesky", "lsqr", "sparse_cg", "sag", "saga", "lbfgs"} + {"auto", "svd", "cholesky", "lsqr", + "sparse_cg", "sag", "saga", "lbfgs"} ) ], "max_iter": [Interval(Integral, 0, None, closed="left"), None], @@ -629,7 +634,8 @@ def _ridge_regression( if check_input: _dtype = [np.float64, np.float32] _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), solver) - X = check_array(X, accept_sparse=_accept_sparse, dtype=_dtype, order="C") + X = check_array(X, accept_sparse=_accept_sparse, + dtype=_dtype, order="C") y = check_array(y, dtype=X.dtype, ensure_2d=False, order=None) check_consistent_length(X, y) @@ -778,7 +784,8 @@ def _ridge_regression( if solver == "svd": if sparse.issparse(X): - raise TypeError("SVD solver does not support sparse inputs currently") + raise TypeError( + "SVD solver does not support sparse inputs currently") coef = _solve_svd(X, y, alpha) if ravel: @@ -804,7 +811,8 @@ class _BaseRidge(LinearModel, metaclass=ABCMeta): "tol": [Interval(Real, 0, None, closed="left")], "solver": [ StrOptions( - {"auto", "svd", "cholesky", "lsqr", "sparse_cg", "sag", "saga", "lbfgs"} + {"auto", "svd", "cholesky", "lsqr", + "sparse_cg", "sag", "saga", "lbfgs"} ) ], "positive": ["boolean"], @@ -873,7 +881,8 @@ def fit(self, X, y, sample_weight=None): solver = self.solver if sample_weight is not None: - sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) + sample_weight = _check_sample_weight( + sample_weight, X, dtype=X.dtype) # when X is sparse we only remove offset from y X, y, X_offset, y_offset, X_scale = _preprocess_data( @@ -1142,14 +1151,16 @@ def fit(self, X, y, sample_weight=None): sample_weight : float or ndarray of shape (n_samples,), default=None Individual weights for each sample. If given a float, every sample - will have the same weight. The sample_weight vector should sum to one. + will have the same weight. The sample_weight vector should sum to + one. Returns ------- self : object Fitted estimator. """ - _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), self.solver) + _accept_sparse = _get_valid_accept_sparse( + sparse.issparse(X), self.solver) X, y = self._validate_data( X, y, @@ -1210,7 +1221,8 @@ def _prepare_data(self, X, y, sample_weight, solver): sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) if self.class_weight: - sample_weight = sample_weight * compute_sample_weight(self.class_weight, y) + sample_weight = sample_weight * \ + compute_sample_weight(self.class_weight, y) return X, y, sample_weight, Y def predict(self, X): @@ -1460,7 +1472,8 @@ def fit(self, X, y, sample_weight=None): self : object Instance of the estimator. """ - X, y, sample_weight, Y = self._prepare_data(X, y, sample_weight, self.solver) + X, y, sample_weight, Y = self._prepare_data( + X, y, sample_weight, self.solver) super().fit(X, Y, sample_weight=sample_weight) return self @@ -1705,10 +1718,12 @@ def _compute_gram(self, X, sqrt_sw): X_weighted = sample_weight_matrix.dot(X) X_mean, _ = mean_variance_axis(X_weighted, axis=0) X_mean *= n_samples / sqrt_sw.dot(sqrt_sw) - X_mX = sqrt_sw[:, None] * safe_sparse_dot(X_mean, X.T, dense_output=True) + X_mX = sqrt_sw[:, None] * \ + safe_sparse_dot(X_mean, X.T, dense_output=True) X_mX_m = np.outer(sqrt_sw, sqrt_sw) * np.dot(X_mean, X_mean) return ( - safe_sparse_dot(X, X.T, dense_output=True) + X_mX_m - X_mX - X_mX.T, + safe_sparse_dot(X, X.T, dense_output=True) + + X_mX_m - X_mX - X_mX.T, X_mean, ) @@ -1790,7 +1805,8 @@ def _sparse_multidot_diag(self, X, A, X_mean, sqrt_sw): (X[batch].shape[0], X.shape[1] + self.fit_intercept), dtype=X.dtype ) if self.fit_intercept: - X_batch[:, :-1] = X[batch].toarray() - X_mean * scale[batch][:, None] + X_batch[:, :-1] = X[batch].toarray() - X_mean * \ + scale[batch][:, None] X_batch[:, -1] = intercept_col[batch] else: X_batch = X[batch].toarray() @@ -1990,7 +2006,8 @@ def fit(self, X, y, sample_weight=None): assert not (self.is_clf and self.alpha_per_target) if sample_weight is not None: - sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) + sample_weight = _check_sample_weight( + sample_weight, X, dtype=X.dtype) self.alphas = np.asarray(self.alphas) @@ -2031,12 +2048,14 @@ def fit(self, X, y, sample_weight=None): n_alphas = 1 if np.ndim(self.alphas) == 0 else len(self.alphas) if self.store_cv_values: - self.cv_values_ = np.empty((n_samples * n_y, n_alphas), dtype=X.dtype) + self.cv_values_ = np.empty( + (n_samples * n_y, n_alphas), dtype=X.dtype) best_coef, best_score, best_alpha = None, None, None for i, alpha in enumerate(np.atleast_1d(self.alphas)): - G_inverse_diag, c = solve(float(alpha), y, sqrt_sw, X_mean, *decomposition) + G_inverse_diag, c = solve( + float(alpha), y, sqrt_sw, X_mean, *decomposition) if error: squared_errors = (c / G_inverse_diag) ** 2 if self.alpha_per_target: @@ -2051,7 +2070,8 @@ def fit(self, X, y, sample_weight=None): self.cv_values_[:, i] = predictions.ravel() if self.is_clf: - identity_estimator = _IdentityClassifier(classes=np.arange(n_y)) + identity_estimator = _IdentityClassifier( + classes=np.arange(n_y)) alpha_score = scorer( identity_estimator, predictions, y.argmax(axis=1) ) @@ -2060,7 +2080,8 @@ def fit(self, X, y, sample_weight=None): if self.alpha_per_target: alpha_score = np.array( [ - scorer(identity_estimator, predictions[:, j], y[:, j]) + scorer(identity_estimator, + predictions[:, j], y[:, j]) for j in range(n_y) ] ) @@ -2205,9 +2226,11 @@ def fit(self, X, y, sample_weight=None): self.cv_values_ = estimator.cv_values_ else: if self.store_cv_values: - raise ValueError("cv!=None and store_cv_values=True are incompatible") + raise ValueError( + "cv!=None and store_cv_values=True are incompatible") if self.alpha_per_target: - raise ValueError("cv!=None and alpha_per_target=True are incompatible") + raise ValueError( + "cv!=None and alpha_per_target=True are incompatible") parameters = {"alpha": alphas} solver = "sparse_cg" if sparse.issparse(X) else "auto" @@ -2398,7 +2421,8 @@ def fit(self, X, y, sample_weight=None): cross-validation takes the sample weights into account when computing the validation score. """ - _raise_for_unsupported_routing(self, "fit", sample_weight=sample_weight) + _raise_for_unsupported_routing( + self, "fit", sample_weight=sample_weight) super().fit(X, y, sample_weight=sample_weight) return self @@ -2570,11 +2594,13 @@ def fit(self, X, y, sample_weight=None): self : object Fitted estimator. """ - _raise_for_unsupported_routing(self, "fit", sample_weight=sample_weight) + _raise_for_unsupported_routing( + self, "fit", sample_weight=sample_weight) # `RidgeClassifier` does not accept "sag" or "saga" solver and thus support # csr, csc, and coo sparse matrices. By using solver="eigen" we force to accept # all sparse format. - X, y, sample_weight, Y = self._prepare_data(X, y, sample_weight, solver="eigen") + X, y, sample_weight, Y = self._prepare_data( + X, y, sample_weight, solver="eigen") # If cv is None, gcv mode will be used and we used the binarized Y # since y will not be binarized in _RidgeGCV estimator. From 102c2ce4d511d3df89871f482d5d9febf74b1cf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sol=C3=A8ne=20PERRET?= Date: Fri, 12 Jan 2024 15:31:12 +0100 Subject: [PATCH 3/6] Correction of linting. --- sklearn/linear_model/_ridge.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index 703be2b94a3c0..04c4f2178b5fc 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -1151,7 +1151,7 @@ def fit(self, X, y, sample_weight=None): sample_weight : float or ndarray of shape (n_samples,), default=None Individual weights for each sample. If given a float, every sample - will have the same weight. The sample_weight vector should sum to + will have the same weight. The sample_weight vector should sum to one. Returns From 881e82d4f777031bc1f66099d0e1374e808ca05b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sol=C3=A8ne=20PERRET?= Date: Fri, 12 Jan 2024 15:51:02 +0100 Subject: [PATCH 4/6] Modiification of linting --- sklearn/linear_model/_ridge.py | 81 ++++++++++++---------------------- 1 file changed, 27 insertions(+), 54 deletions(-) diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index 04c4f2178b5fc..744db6855a2d7 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -56,8 +56,7 @@ def matvec(b): def rmatvec(b): return X.T.dot(b) - X_offset * b.dot(sample_weight_sqrt) - X1 = sparse.linalg.LinearOperator( - shape=X.shape, matvec=matvec, rmatvec=rmatvec) + X1 = sparse.linalg.LinearOperator(shape=X.shape, matvec=matvec, rmatvec=rmatvec) return X1 @@ -120,8 +119,7 @@ def _mv(x): C = sp_linalg.LinearOperator( (n_features, n_features), matvec=mv, dtype=X.dtype ) - coefs[i], info = _sparse_linalg_cg( - C, y_column, maxiter=max_iter, rtol=tol) + coefs[i], info = _sparse_linalg_cg(C, y_column, maxiter=max_iter, rtol=tol) if info < 0: raise ValueError("Failed with error code %d" % info) @@ -208,8 +206,7 @@ def _solve_cholesky(X, y, alpha): coefs = np.empty([n_targets, n_features], dtype=X.dtype) for coef, target, current_alpha in zip(coefs, Xy.T, alpha): A.flat[:: n_features + 1] += current_alpha - coef[:] = linalg.solve( - A, target, assume_a="pos", overwrite_a=False).ravel() + coef[:] = linalg.solve(A, target, assume_a="pos", overwrite_a=False).ravel() A.flat[:: n_features + 1] -= current_alpha return coefs @@ -224,8 +221,7 @@ def _solve_cholesky_kernel(K, y, alpha, sample_weight=None, copy=False): alpha = np.atleast_1d(alpha) one_alpha = (alpha == alpha[0]).all() - has_sw = isinstance(sample_weight, np.ndarray) or sample_weight not in [ - 1.0, None] + has_sw = isinstance(sample_weight, np.ndarray) or sample_weight not in [1.0, None] if has_sw: # Unlike other solvers, we need to support sample_weight directly @@ -348,10 +344,8 @@ def func(w): result = optimize.minimize(func, x0, **config) if not result["success"]: warnings.warn( - ( - "The lbfgs solver did not converge. Try increasing max_iter " - f"or tol. Currently: max_iter={max_iter} and tol={tol}" - ), + "The lbfgs solver did not converge. Try increasing max_iter " + f"or tol. Currently: max_iter={max_iter} and tol={tol}", ConvergenceWarning, ) coefs[i] = result["x"] @@ -378,8 +372,7 @@ def _get_valid_accept_sparse(is_X_sparse, solver): ], "solver": [ StrOptions( - {"auto", "svd", "cholesky", "lsqr", - "sparse_cg", "sag", "saga", "lbfgs"} + {"auto", "svd", "cholesky", "lsqr", "sparse_cg", "sag", "saga", "lbfgs"} ) ], "max_iter": [Interval(Integral, 0, None, closed="left"), None], @@ -634,8 +627,7 @@ def _ridge_regression( if check_input: _dtype = [np.float64, np.float32] _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), solver) - X = check_array(X, accept_sparse=_accept_sparse, - dtype=_dtype, order="C") + X = check_array(X, accept_sparse=_accept_sparse, dtype=_dtype, order="C") y = check_array(y, dtype=X.dtype, ensure_2d=False, order=None) check_consistent_length(X, y) @@ -784,8 +776,7 @@ def _ridge_regression( if solver == "svd": if sparse.issparse(X): - raise TypeError( - "SVD solver does not support sparse inputs currently") + raise TypeError("SVD solver does not support sparse inputs currently") coef = _solve_svd(X, y, alpha) if ravel: @@ -811,8 +802,7 @@ class _BaseRidge(LinearModel, metaclass=ABCMeta): "tol": [Interval(Real, 0, None, closed="left")], "solver": [ StrOptions( - {"auto", "svd", "cholesky", "lsqr", - "sparse_cg", "sag", "saga", "lbfgs"} + {"auto", "svd", "cholesky", "lsqr", "sparse_cg", "sag", "saga", "lbfgs"} ) ], "positive": ["boolean"], @@ -881,8 +871,7 @@ def fit(self, X, y, sample_weight=None): solver = self.solver if sample_weight is not None: - sample_weight = _check_sample_weight( - sample_weight, X, dtype=X.dtype) + sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) # when X is sparse we only remove offset from y X, y, X_offset, y_offset, X_scale = _preprocess_data( @@ -1159,8 +1148,7 @@ def fit(self, X, y, sample_weight=None): self : object Fitted estimator. """ - _accept_sparse = _get_valid_accept_sparse( - sparse.issparse(X), self.solver) + _accept_sparse = _get_valid_accept_sparse(sparse.issparse(X), self.solver) X, y = self._validate_data( X, y, @@ -1221,8 +1209,7 @@ def _prepare_data(self, X, y, sample_weight, solver): sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) if self.class_weight: - sample_weight = sample_weight * \ - compute_sample_weight(self.class_weight, y) + sample_weight = sample_weight * compute_sample_weight(self.class_weight, y) return X, y, sample_weight, Y def predict(self, X): @@ -1472,8 +1459,7 @@ def fit(self, X, y, sample_weight=None): self : object Instance of the estimator. """ - X, y, sample_weight, Y = self._prepare_data( - X, y, sample_weight, self.solver) + X, y, sample_weight, Y = self._prepare_data(X, y, sample_weight, self.solver) super().fit(X, Y, sample_weight=sample_weight) return self @@ -1718,12 +1704,10 @@ def _compute_gram(self, X, sqrt_sw): X_weighted = sample_weight_matrix.dot(X) X_mean, _ = mean_variance_axis(X_weighted, axis=0) X_mean *= n_samples / sqrt_sw.dot(sqrt_sw) - X_mX = sqrt_sw[:, None] * \ - safe_sparse_dot(X_mean, X.T, dense_output=True) + X_mX = sqrt_sw[:, None] * safe_sparse_dot(X_mean, X.T, dense_output=True) X_mX_m = np.outer(sqrt_sw, sqrt_sw) * np.dot(X_mean, X_mean) return ( - safe_sparse_dot(X, X.T, dense_output=True) + - X_mX_m - X_mX - X_mX.T, + safe_sparse_dot(X, X.T, dense_output=True) + X_mX_m - X_mX - X_mX.T, X_mean, ) @@ -1805,8 +1789,7 @@ def _sparse_multidot_diag(self, X, A, X_mean, sqrt_sw): (X[batch].shape[0], X.shape[1] + self.fit_intercept), dtype=X.dtype ) if self.fit_intercept: - X_batch[:, :-1] = X[batch].toarray() - X_mean * \ - scale[batch][:, None] + X_batch[:, :-1] = X[batch].toarray() - X_mean * scale[batch][:, None] X_batch[:, -1] = intercept_col[batch] else: X_batch = X[batch].toarray() @@ -2006,8 +1989,7 @@ def fit(self, X, y, sample_weight=None): assert not (self.is_clf and self.alpha_per_target) if sample_weight is not None: - sample_weight = _check_sample_weight( - sample_weight, X, dtype=X.dtype) + sample_weight = _check_sample_weight(sample_weight, X, dtype=X.dtype) self.alphas = np.asarray(self.alphas) @@ -2048,14 +2030,12 @@ def fit(self, X, y, sample_weight=None): n_alphas = 1 if np.ndim(self.alphas) == 0 else len(self.alphas) if self.store_cv_values: - self.cv_values_ = np.empty( - (n_samples * n_y, n_alphas), dtype=X.dtype) + self.cv_values_ = np.empty((n_samples * n_y, n_alphas), dtype=X.dtype) best_coef, best_score, best_alpha = None, None, None for i, alpha in enumerate(np.atleast_1d(self.alphas)): - G_inverse_diag, c = solve( - float(alpha), y, sqrt_sw, X_mean, *decomposition) + G_inverse_diag, c = solve(float(alpha), y, sqrt_sw, X_mean, *decomposition) if error: squared_errors = (c / G_inverse_diag) ** 2 if self.alpha_per_target: @@ -2070,8 +2050,7 @@ def fit(self, X, y, sample_weight=None): self.cv_values_[:, i] = predictions.ravel() if self.is_clf: - identity_estimator = _IdentityClassifier( - classes=np.arange(n_y)) + identity_estimator = _IdentityClassifier(classes=np.arange(n_y)) alpha_score = scorer( identity_estimator, predictions, y.argmax(axis=1) ) @@ -2080,8 +2059,7 @@ def fit(self, X, y, sample_weight=None): if self.alpha_per_target: alpha_score = np.array( [ - scorer(identity_estimator, - predictions[:, j], y[:, j]) + scorer(identity_estimator, predictions[:, j], y[:, j]) for j in range(n_y) ] ) @@ -2226,11 +2204,9 @@ def fit(self, X, y, sample_weight=None): self.cv_values_ = estimator.cv_values_ else: if self.store_cv_values: - raise ValueError( - "cv!=None and store_cv_values=True are incompatible") + raise ValueError("cv!=None and store_cv_values=True are incompatible") if self.alpha_per_target: - raise ValueError( - "cv!=None and alpha_per_target=True are incompatible") + raise ValueError("cv!=None and alpha_per_target=True are incompatible") parameters = {"alpha": alphas} solver = "sparse_cg" if sparse.issparse(X) else "auto" @@ -2421,8 +2397,7 @@ def fit(self, X, y, sample_weight=None): cross-validation takes the sample weights into account when computing the validation score. """ - _raise_for_unsupported_routing( - self, "fit", sample_weight=sample_weight) + _raise_for_unsupported_routing(self, "fit", sample_weight=sample_weight) super().fit(X, y, sample_weight=sample_weight) return self @@ -2594,13 +2569,11 @@ def fit(self, X, y, sample_weight=None): self : object Fitted estimator. """ - _raise_for_unsupported_routing( - self, "fit", sample_weight=sample_weight) + _raise_for_unsupported_routing(self, "fit", sample_weight=sample_weight) # `RidgeClassifier` does not accept "sag" or "saga" solver and thus support # csr, csc, and coo sparse matrices. By using solver="eigen" we force to accept # all sparse format. - X, y, sample_weight, Y = self._prepare_data( - X, y, sample_weight, solver="eigen") + X, y, sample_weight, Y = self._prepare_data(X, y, sample_weight, solver="eigen") # If cv is None, gcv mode will be used and we used the binarized Y # since y will not be binarized in _RidgeGCV estimator. From 7f7ce52d60fee2b774792bb013b6e2fc38a776aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sol=C3=A8ne=20PERRET?= Date: Fri, 12 Jan 2024 16:02:17 +0100 Subject: [PATCH 5/6] Linting --- sklearn/linear_model/_ridge.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index 744db6855a2d7..e39af10053c34 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -344,8 +344,10 @@ def func(w): result = optimize.minimize(func, x0, **config) if not result["success"]: warnings.warn( - "The lbfgs solver did not converge. Try increasing max_iter " - f"or tol. Currently: max_iter={max_iter} and tol={tol}", + ( + "The lbfgs solver did not converge. Try increasing max_iter " + f"or tol. Currently: max_iter={max_iter} and tol={tol}" + ), ConvergenceWarning, ) coefs[i] = result["x"] @@ -1140,8 +1142,7 @@ def fit(self, X, y, sample_weight=None): sample_weight : float or ndarray of shape (n_samples,), default=None Individual weights for each sample. If given a float, every sample - will have the same weight. The sample_weight vector should sum to - one. + will have the same weight. Returns ------- From 69cd512f32bd372e884641d786f3f2988b6f7746 Mon Sep 17 00:00:00 2001 From: sperret6 <146923414+sperret6@users.noreply.github.com> Date: Sat, 13 Jan 2024 18:41:24 +0100 Subject: [PATCH 6/6] Update _ridge.py --- sklearn/linear_model/_ridge.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sklearn/linear_model/_ridge.py b/sklearn/linear_model/_ridge.py index e39af10053c34..2b77e45bf26f7 100644 --- a/sklearn/linear_model/_ridge.py +++ b/sklearn/linear_model/_ridge.py @@ -1969,7 +1969,8 @@ def fit(self, X, y, sample_weight=None): sample_weight : float or ndarray of shape (n_samples,), default=None Individual weights for each sample. If given a float, every sample - will have the same weight. + will have the same weight. The sample_weight vector should sum to + one. Returns -------