Skip to content

Fix do not recommend to increase max_iter in ConvergenceWarning when not appropriate#31316

Merged
jeremiedbb merged 6 commits into
scikit-learn:mainfrom
ogrisel:fix-_check_optimize_result
May 12, 2025
Merged

Fix do not recommend to increase max_iter in ConvergenceWarning when not appropriate#31316
jeremiedbb merged 6 commits into
scikit-learn:mainfrom
ogrisel:fix-_check_optimize_result

Conversation

@ogrisel

@ogrisel ogrisel commented May 6, 2025

Copy link
Copy Markdown
Member

While investigating #31164 I found out that _check_optimize_result can sometimes lead to misleading error messages.

This fix should help avoid pointing people in a misleading direction when investigating such convergence problems.

@github-actions

github-actions Bot commented May 6, 2025

Copy link
Copy Markdown

✔️ Linting Passed

All linting checks passed. Your pull request is in excellent shape! ☀️

Generated for commit: 0b3f309. Link to the linter CI: here

Comment thread sklearn/linear_model/tests/test_logistic.py Outdated
@ogrisel ogrisel requested a review from Copilot May 6, 2025 15:09
@ogrisel

ogrisel commented May 6, 2025

Copy link
Copy Markdown
Member Author

For information, I requested a copilot review on this PR to assess its usefulness.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread sklearn/linear_model/_glm/_newton_solver.py
Comment thread sklearn/utils/optimize.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

@thomasjpfan thomasjpfan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, otherwise LGTM

Comment thread sklearn/utils/optimize.py Outdated
Co-authored-by: Thomas J. Fan <thomasjpfan@gmail.com>

@jeremiedbb jeremiedbb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks

@jeremiedbb jeremiedbb merged commit 8c508c4 into scikit-learn:main May 12, 2025
36 checks passed
@ogrisel ogrisel deleted the fix-_check_optimize_result branch May 12, 2025 12:46
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants