You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
No warning when LogisticRegression does not converge #10866
I've run LogisticRegressionCV on the Wisconsin Breast Cancer data, and the output of clf.n_iter_ was 100 for all but 1 of the variables. The default of 100 iterations was probably not sufficient in this case. Should there not be some kind of warning? I have done some tests and ~3000 iterations was probably a better choice for max_iter...
changed the title [-]No warning when LogisticRegression does not converge.[/-][+]No warning when LogisticRegression is far from converging.[/+]on Mar 24, 2018
The culprit is this line that only affects the lbfgs solver. This is more critical if we can to make lbfgs the default solver #9997 in LogisticRegression
After more thoughts, the case of LogisticRegressionCV is more debatable, as there are always CV parameters that may fail to converge and handling it the same way as GridSearchCV would be probably more reasonable.
A quick git grep seems to confirm that ConvergenceWarning are generally issued when verbose=0, reopening.
The same thing happens for solver='liblinear' (the default solver at the time of writing) by the way (you need to decrease max_iter e.g. set it to 1). There should be a test that checks the ConvergenceWarning for all solvers.
changed the title [-]No warning when LogisticRegression is far from converging.[/-][+]No warning when LogisticRegression does not converge[/+]on Mar 26, 2018
I think I need to correct also this line. Do you agree ?
Moreover, I just saw that the name of this function is not perfectly correct, since it does not test the convergence warning.
Maybe we could write a test a bit like this one to test all the warnings. What do you think ?
You can reuse test_max_iter indeed to check for all solvers that there has been a warning and add an assert_warns_message in it. If you do that, test_logistic_regression_convergence_warnings is not really needed any more. There is no need to touch test_lr_liblinear_warning.
The best is to open a PR and see how that goes! Not that you have mentioned changing the tests but you will also need to change sklearn/linear_model/logistic.py to make sure a ConvergenceWarning is issued for all the solvers.
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model_logistic.py:762: ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
Activity
[-]No warning when LogisticRegression does not converge.[/-][+]No warning when LogisticRegression is far from converging.[/+]lesteve commentedon Mar 26, 2018
If you use verbose=1 in your snippet, you'll get plenty of ConvergenceWarning.
I am going to close this one, please reopen if you strongly disagree.
rth commentedon Mar 26, 2018
I also think that
LogisticRegression(andshould print aLogisticRegressionCV)ConvergenceWarningwhen it fails to converge with default parameters.It does not make sense to expect the users to set the verbosity in order to get the warning. Also other methods don't do this: e.g. MLPClassifier may raise ConvergenceWarnings so does MultiTaskElasticNet or LassoLars.
The culprit is this line that only affects the
lbfgssolver. This is more critical if we can to makelbfgsthe default solver #9997 inLogisticRegressionrth commentedon Mar 26, 2018
After more thoughts, the case of
LogisticRegressionCVis more debatable, as there are always CV parameters that may fail to converge and handling it the same way asGridSearchCVwould be probably more reasonable.However,
silently fails to converge, and this is a bug IMO. This was also recently relevant in #10813
lesteve commentedon Mar 26, 2018
A quick git grep seems to confirm that ConvergenceWarning are generally issued when verbose=0, reopening.
The same thing happens for solver='liblinear' (the default solver at the time of writing) by the way (you need to decrease max_iter e.g. set it to 1). There should be a test that checks the ConvergenceWarning for all solvers.
[-]No warning when LogisticRegression is far from converging.[/-][+]No warning when LogisticRegression does not converge[/+]AlexandreSev commentedon Mar 26, 2018
I see that nobody is working on it. Can I do it ?
rth commentedon Mar 26, 2018
Sure, thank you @AlexandreSev
rth commentedon Mar 26, 2018
Unless @oliverangelil was planning to submit a PR..
AlexandreSev commentedon Mar 26, 2018
I think I need to correct also this line. Do you agree ?
Moreover, I just saw that the name of this function is not perfectly correct, since it does not test the convergence warning.
Maybe we could write a test a bit like this one to test all the warnings. What do you think ?
lesteve commentedon Mar 26, 2018
You can reuse test_max_iter indeed to check for all solvers that there has been a warning and add an assert_warns_message in it. If you do that, test_logistic_regression_convergence_warnings is not really needed any more. There is no need to touch test_lr_liblinear_warning.
The best is to open a PR and see how that goes! Not that you have mentioned changing the tests but you will also need to change sklearn/linear_model/logistic.py to make sure a ConvergenceWarning is issued for all the solvers.
jnothman commentedon Mar 26, 2018
Make convergence warnings appear when verbose = 0 in Logistic Regress…
Test that a warning is sent when max_iter is reached for LR.
Make convergence warnings appear when verbose = 0 in Logistic Regress…
Test if a convergence warning is sent when needed in LR.
Increase max_iter to remove unwanted warning in test_return_train_sco…
Make convergence warnings appear when verbose = 0 in Logistic Regress…
Test if a convergence warning is sent when needed in LR.
Increase max_iter to remove unwanted warning in test_return_train_sco…
Ignore convergence warning in test_return_train_score_warn.
Make convergence warnings appear when verbose = 0 in linear models.
Make convergence warnings appear when verbose = 0 in linear models.
Bharat8219-git commentedon Sep 13, 2020
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model_logistic.py:762: ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.
Increase the number of iterations (max_iter) or scale the data as shown in:
https://scikit-learn.org/stable/modules/preprocessing.html
Please also refer to the documentation for alternative solver options:
https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
n_iter_i = _check_optimize_result(
Bharat8219-git commentedon Sep 13, 2020
please solve this issue with right algorothms