Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit ab5ba84

Browse filesBrowse files
authored
ENH change Ridge tol to 1e-4 (#24465)
* ENH set defaul tol of Ridge to 1e-4 instead of 1e-3 * MNT rename internal least square method in discrimant_analysis * DOC add versionchanged * DOC add whats_new entry * DOC add pr to whatsnew * DOC better versionchanged message
1 parent 14684bb commit ab5ba84
Copy full SHA for ab5ba84

File tree

Expand file treeCollapse file tree

4 files changed

+42
-17
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+42
-17
lines changed

‎doc/whats_new/v1.2.rst

Copy file name to clipboardExpand all lines: doc/whats_new/v1.2.rst
+10Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ random sampling procedures.
3131
to a tiny value. Moreover, `verbose` is now properly propagated to L-BFGS-B.
3232
:pr:`23619` by :user:`Christian Lorentzen <lorentzenchr>`.
3333

34+
- |API| The default value of `tol` was changed from `1e-3` to `1e-4` for
35+
:func:`linear_model.ridge_regression`, :class:`linear_model.Ridge` and
36+
:class:`linear_model.`RidgeClassifier`.
37+
:pr:`24465` by :user:`Christian Lorentzen <lorentzenchr>`.
38+
3439
- |Fix| Make sign of `components_` deterministic in :class:`decomposition.SparsePCA`.
3540
:pr:`23935` by :user:`Guillaume Lemaitre <glemaitre>`.
3641

@@ -333,6 +338,11 @@ Changelog
333338
in :class:`linear_model.LogisticRegression`, and will be removed in version 1.4.
334339
Use `None` instead. :pr:`23877` by :user:`Zhehao Liu <MaxwellLZH>`.
335340

341+
- |API| The default value of `tol` was changed from `1e-3` to `1e-4` for
342+
:func:`linear_model.ridge_regression`, :class:`linear_model.Ridge` and
343+
:class:`linear_model.`RidgeClassifier`.
344+
:pr:`24465` by :user:`Christian Lorentzen <lorentzenchr>`.
345+
336346
- |Fix| :class:`linear_model.SGDOneClassSVM` no longer performs parameter
337347
validation in the constructor. All validation is now handled in `fit()` and
338348
`partial_fit()`.

‎sklearn/discriminant_analysis.py

Copy file name to clipboardExpand all lines: sklearn/discriminant_analysis.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ def __init__(
350350
self.tol = tol # used only in svd solver
351351
self.covariance_estimator = covariance_estimator
352352

353-
def _solve_lsqr(self, X, y, shrinkage, covariance_estimator):
353+
def _solve_lstsq(self, X, y, shrinkage, covariance_estimator):
354354
"""Least squares solver.
355355
356356
The least squares solver computes a straightforward solution of the
@@ -621,7 +621,7 @@ def fit(self, X, y):
621621
)
622622
self._solve_svd(X, y)
623623
elif self.solver == "lsqr":
624-
self._solve_lsqr(
624+
self._solve_lstsq(
625625
X,
626626
y,
627627
shrinkage=self.shrinkage,

‎sklearn/linear_model/_ridge.py

Copy file name to clipboardExpand all lines: sklearn/linear_model/_ridge.py
+29-14Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def _solve_sparse_cg(
6666
y,
6767
alpha,
6868
max_iter=None,
69-
tol=1e-3,
69+
tol=1e-4,
7070
verbose=0,
7171
X_offset=None,
7272
X_scale=None,
@@ -153,7 +153,7 @@ def _solve_lsqr(
153153
alpha,
154154
fit_intercept=True,
155155
max_iter=None,
156-
tol=1e-3,
156+
tol=1e-4,
157157
X_offset=None,
158158
X_scale=None,
159159
sample_weight_sqrt=None,
@@ -303,7 +303,7 @@ def _solve_lbfgs(
303303
alpha,
304304
positive=True,
305305
max_iter=None,
306-
tol=1e-3,
306+
tol=1e-4,
307307
X_offset=None,
308308
X_scale=None,
309309
sample_weight_sqrt=None,
@@ -381,7 +381,7 @@ def ridge_regression(
381381
sample_weight=None,
382382
solver="auto",
383383
max_iter=None,
384-
tol=1e-3,
384+
tol=1e-4,
385385
verbose=0,
386386
positive=False,
387387
random_state=None,
@@ -471,8 +471,13 @@ def ridge_regression(
471471
by scipy.sparse.linalg. For 'sag' and saga solver, the default value is
472472
1000. For 'lbfgs' solver, the default value is 15000.
473473
474-
tol : float, default=1e-3
475-
Precision of the solution.
474+
tol : float, default=1e-4
475+
Precision of the solution. Note that `tol` has no effect for solvers 'svd' and
476+
'cholesky'.
477+
478+
.. versionchanged:: 1.2
479+
Default value changed from 1e-3 to 1e-4 for consistency with other linear
480+
models.
476481
477482
verbose : int, default=0
478483
Verbosity level. Setting verbose > 0 will display additional
@@ -556,7 +561,7 @@ def _ridge_regression(
556561
sample_weight=None,
557562
solver="auto",
558563
max_iter=None,
559-
tol=1e-3,
564+
tol=1e-4,
560565
verbose=0,
561566
positive=False,
562567
random_state=None,
@@ -803,7 +808,7 @@ def __init__(
803808
normalize="deprecated",
804809
copy_X=True,
805810
max_iter=None,
806-
tol=1e-3,
811+
tol=1e-4,
807812
solver="auto",
808813
positive=False,
809814
random_state=None,
@@ -977,8 +982,13 @@ class Ridge(MultiOutputMixin, RegressorMixin, _BaseRidge):
977982
by scipy.sparse.linalg. For 'sag' solver, the default value is 1000.
978983
For 'lbfgs' solver, the default value is 15000.
979984
980-
tol : float, default=1e-3
981-
Precision of the solution.
985+
tol : float, default=1e-4
986+
Precision of the solution. Note that `tol` has no effect for solvers 'svd' and
987+
'cholesky'.
988+
989+
.. versionchanged:: 1.2
990+
Default value changed from 1e-3 to 1e-4 for consistency with other linear
991+
models.
982992
983993
solver : {'auto', 'svd', 'cholesky', 'lsqr', 'sparse_cg', \
984994
'sag', 'saga', 'lbfgs'}, default='auto'
@@ -1096,7 +1106,7 @@ def __init__(
10961106
normalize="deprecated",
10971107
copy_X=True,
10981108
max_iter=None,
1099-
tol=1e-3,
1109+
tol=1e-4,
11001110
solver="auto",
11011111
positive=False,
11021112
random_state=None,
@@ -1276,8 +1286,13 @@ class RidgeClassifier(_RidgeClassifierMixin, _BaseRidge):
12761286
Maximum number of iterations for conjugate gradient solver.
12771287
The default value is determined by scipy.sparse.linalg.
12781288
1279-
tol : float, default=1e-3
1280-
Precision of the solution.
1289+
tol : float, default=1e-4
1290+
Precision of the solution. Note that `tol` has no effect for solvers 'svd' and
1291+
'cholesky'.
1292+
1293+
.. versionchanged:: 1.2
1294+
Default value changed from 1e-3 to 1e-4 for consistency with other linear
1295+
models.
12811296
12821297
class_weight : dict or 'balanced', default=None
12831298
Weights associated with classes in the form ``{class_label: weight}``.
@@ -1397,7 +1412,7 @@ def __init__(
13971412
normalize="deprecated",
13981413
copy_X=True,
13991414
max_iter=None,
1400-
tol=1e-3,
1415+
tol=1e-4,
14011416
class_weight=None,
14021417
solver="auto",
14031418
positive=False,

‎sklearn/linear_model/tests/test_ridge.py

Copy file name to clipboardExpand all lines: sklearn/linear_model/tests/test_ridge.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,7 @@ def test_ridge_fit_intercept_sparse_sag(with_sample_weight, global_random_seed):
16601660
assert_allclose(dense_ridge.intercept_, sparse_ridge.intercept_, rtol=1e-4)
16611661
assert_allclose(dense_ridge.coef_, sparse_ridge.coef_, rtol=1e-4)
16621662
with pytest.warns(UserWarning, match='"sag" solver requires.*'):
1663-
Ridge(solver="sag").fit(X_csr, y)
1663+
Ridge(solver="sag", fit_intercept=True, tol=1e-3, max_iter=None).fit(X_csr, y)
16641664

16651665

16661666
@pytest.mark.parametrize("return_intercept", [False, True])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.