-
-
Notifications
You must be signed in to change notification settings - Fork 25.9k
No warning when LogisticRegression does not converge #10866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If you use verbose=1 in your snippet, you'll get plenty of ConvergenceWarning. from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegressionCV
data = load_breast_cancer()
y = data.target
X = data.data
clf = LogisticRegressionCV(verbose=1)
clf.fit(X, y)
print(clf.n_iter_) I am going to close this one, please reopen if you strongly disagree. |
I also think that 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 |
After more thoughts, the case of However, from sklearn.datasets import load_breast_cancer
from sklearn.linear_model import LogisticRegression
data = load_breast_cancer()
y = data.target
X = data.data
clf = LogisticRegression(solver='lbfgs')
clf.fit(X, y)
print(clf.n_iter_) silently fails to converge, and this is a bug IMO. This was also recently relevant in #10813 |
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. |
I see that nobody is working on it. Can I do it ? |
Sure, thank you @AlexandreSev |
Unless @oliverangelil was planning to submit a PR.. |
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. |
yes I think there are a few cases where we only warn if verbose. I'd rather
consistently warn even if verbose=0
|
…ion. For now, convergence warnings are silent when verbose is set to 0 for lbfgs and liblinear solver, whereas they are not for others. Fix scikit-learn#10866.
Modify slightly test_max_iter to check that a warning is sent. See scikit-learn#10866.
…ion. For lbfgs and liblinears solvers, the convergence warnings appeared only when verbose was greater than 0, whereas they appeared with verbose = 0 with other solvers. See scikit-learn#10866
Modify test_max_iter to also check for the warning, and remove a test which becomes redundant with this modification. See scikit-learn#10866.
…re_warn With the add of convergence warning in logistic regression, this test failed. See scikit-learn#10866
…ion. For lbfgs and liblinears solvers, the convergence warnings appeared only when verbose was greater than 0, whereas they appeared with verbose = 0 with other solvers. See scikit-learn#10866
Modify test_max_iter to also check for the warning, and remove a test which becomes redundant with this modification. See scikit-learn#10866.
…re_warn With the add of convergence warning in logistic regression, this test failed. See scikit-learn#10866
For lbfgs and liblinears solvers, the convergence warnings appeared only when verbose was greater than 0, whereas they appeared with verbose = 0 with other solvers. Create test to check the convergence warning in logistic regression and in linear svm. Update `test_search` to ignore this convergence warning. Fixes scikit-learn#10866
For lbfgs and liblinears solvers, the convergence warnings appeared only when verbose was greater than 0, whereas they appeared with verbose = 0 with other solvers. Create test to check the convergence warning in logistic regression and in linear svm. Update `test_search` to ignore this convergence warning. Fixes scikit-learn#10866
C:\ProgramData\Anaconda3\lib\site-packages\sklearn\linear_model_logistic.py:762: ConvergenceWarning: lbfgs failed to converge (status=1): Increase the number of iterations (max_iter) or scale the data as shown in: |
please solve this issue with right algorothms |
Uh oh!
There was an error while loading. Please reload this page.
Description
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...
Steps/Code to Reproduce
Expected Results
Some kind of error to be shown. E.g: "result did not converge, try increasing the maximum number of iterations (max_iter)"
Versions
The text was updated successfully, but these errors were encountered: