Skip to content

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

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ogrisel
Copy link
Member

@ogrisel ogrisel commented May 6, 2025

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.

Copy link

github-actions bot commented May 6, 2025

✔️ Linting Passed

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

Generated for commit: 897dfe5. Link to the linter CI: here

@ogrisel ogrisel requested a review from Copilot May 6, 2025 15:09
@ogrisel
Copy link
Member Author

ogrisel commented May 6, 2025

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

Copy link

@Copilot Copilot AI left a comment

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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.

1 participant