Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d84785c

Browse files
thomasjpfanjnothman
authored andcommitted
[MRG] ENH: Add scaling to convergence warning for LBFGS (#15571)
1 parent ee09095 commit d84785c

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

sklearn/linear_model/tests/test_logistic.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,13 @@ def test_logistic_regression_path_convergence_fail():
390390
X = np.concatenate((rng.randn(100, 2) + [1, 1], rng.randn(100, 2)))
391391
y = [1] * 100 + [-1] * 100
392392
Cs = [1e3]
393-
assert_warns(ConvergenceWarning, _logistic_regression_path,
394-
X, y, Cs=Cs, tol=0., max_iter=1, random_state=0, verbose=1)
393+
394+
msg = (r"lbfgs failed to converge.+Increase the number of iterations or "
395+
r"scale the data")
396+
397+
with pytest.warns(ConvergenceWarning, match=msg):
398+
_logistic_regression_path(
399+
X, y, Cs=Cs, tol=0., max_iter=1, random_state=0, verbose=0)
395400

396401

397402
def test_liblinear_dual_random_state():

sklearn/utils/optimize.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ def _check_optimize_result(solver, result, max_iter=None):
234234
if solver == "lbfgs":
235235
if result.status != 0:
236236
warnings.warn("{} failed to converge (status={}): {}. "
237-
"Increase the number of iterations."
237+
"Increase the number of iterations or scale the "
238+
"data as shown in https://scikit-learn.org/stable/"
239+
"modules/preprocessing.html"
238240
.format(solver, result.status, result.message),
239241
ConvergenceWarning, stacklevel=2)
240242
if max_iter is not None:

0 commit comments

Comments
 (0)