FIX emit ConvergenceWarning instead of ValueError in HuberRegressor#33641
Open
EdenRochmanSharabi wants to merge 3 commits intoscikit-learn:mainfrom
Open
FIX emit ConvergenceWarning instead of ValueError in HuberRegressor#33641EdenRochmanSharabi wants to merge 3 commits intoscikit-learn:mainfrom
EdenRochmanSharabi wants to merge 3 commits intoscikit-learn:mainfrom
Conversation
added 2 commits
March 26, 2026 21:13
When the L-BFGS-B solver reports convergence issues (e.g. ABNORMAL_TERMINATION_IN_LNSRCH), HuberRegressor previously raised a ValueError, unlike other estimators such as LogisticRegression which emit a ConvergenceWarning. Remove the special-cased ValueError for status==2 and let _check_optimize_result handle all non-zero statuses uniformly by emitting ConvergenceWarning. This allows the model to still return fitted parameters from the last iteration, which is often useful despite incomplete convergence. Fixes scikit-learn#27777
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.
Summary
Fixes #27777
HuberRegressorpreviously raised aValueErrorwhen the L-BFGS-B solverreported convergence issues with status code 2 (e.g.
ABNORMAL_TERMINATION_IN_LNSRCH). This is inconsistent with other estimatorslike
LogisticRegression, which emit aConvergenceWarningand still returnthe parameters from the last iteration.
This PR removes the special-cased
ValueErrorforstatus == 2and lets_check_optimize_resulthandle all non-zero statuses uniformly by emitting aConvergenceWarning. This way:often useful despite incomplete convergence.
LogisticRegressionand other L-BFGS-Bbased estimators, as suggested by maintainers in the issue discussion.
Changes
sklearn/linear_model/_huber.py: Removed theif opt_res.status == 2: raise ValueError(...)block. The existing call to_check_optimize_resulton the next line already handles this case.sklearn/linear_model/tests/test_huber.py: Added a non-regression test that verifies aConvergenceWarningis emitted (instead ofValueError) when the solver reports status 2.doc/whats_new/upcoming_changes/sklearn.linear_model/27777.fix.rst: Changelog entry.Notes
A previous PR (#27888) attempted this fix but was closed due to platform-dependent
floating-point behavior in the test. This PR avoids that issue by mocking
optimize.minimizeto simulate the failure, making the test deterministicacross all platforms.