Fix do not recommend to increase max_iter in ConvergenceWarning when not appropriate#31316
Merged
jeremiedbb merged 6 commits intoMay 12, 2025
Merged
Conversation
ogrisel
commented
May 6, 2025
Member
Author
|
For information, I requested a copilot review on this PR to assess its usefulness. |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes an issue where the convergence warning for the lbfgs solver was misleading by suggesting that users increase the number of iterations even when it isn’t appropriate. The changes update the warning message in _check_optimize_result, update caller invocations in the GLM and newton solver modules, and adjust the corresponding tests to validate the new behavior.
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| sklearn/utils/tests/test_optimize.py | Added tests for the updated convergence warning behavior. |
| sklearn/utils/optimize.py | Modified warning message construction based on the max_iter parameter. |
| sklearn/linear_model/tests/test_logistic.py | Updated the expected warning message format in tests. |
| sklearn/linear_model/_glm/glm.py | Passed the max_iter parameter to _check_optimize_result. |
| sklearn/linear_model/_glm/_newton_solver.py | Adjusted the computed max_iter in fallback_lbfgs_solve and its use in _check_optimize_result. |
Files not reviewed (1)
- doc/whats_new/upcoming_changes/changed-models/31316.fix.rst: Language not supported
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
thomasjpfan
approved these changes
May 6, 2025
thomasjpfan
left a comment
Member
There was a problem hiding this comment.
Minor nit, otherwise LGTM
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
jeremiedbb
pushed a commit
to jeremiedbb/scikit-learn
that referenced
this pull request
May 30, 2025
…hen not appropriate (scikit-learn#31316) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
jeremiedbb
pushed a commit
that referenced
this pull request
Jun 5, 2025
…hen not appropriate (#31316) Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While investigating #31164 I found out that
_check_optimize_resultcan sometimes lead to misleading error messages.This fix should help avoid pointing people in a misleading direction when investigating such convergence problems.