Skip to content

FIX emit ConvergenceWarning instead of ValueError in HuberRegressor#33641

Open
EdenRochmanSharabi wants to merge 3 commits intoscikit-learn:mainfrom
EdenRochmanSharabi:fix/huber-convergence-warning
Open

FIX emit ConvergenceWarning instead of ValueError in HuberRegressor#33641
EdenRochmanSharabi wants to merge 3 commits intoscikit-learn:mainfrom
EdenRochmanSharabi:fix/huber-convergence-warning

Conversation

@EdenRochmanSharabi
Copy link
Copy Markdown
Contributor

Summary

Fixes #27777

HuberRegressor previously raised a ValueError when the L-BFGS-B solver
reported convergence issues with status code 2 (e.g.
ABNORMAL_TERMINATION_IN_LNSRCH). This is inconsistent with other estimators
like LogisticRegression, which emit a ConvergenceWarning and still return
the parameters from the last iteration.

This PR removes the special-cased ValueError for status == 2 and lets
_check_optimize_result handle all non-zero statuses uniformly by emitting a
ConvergenceWarning. This way:

  • The model still returns fitted parameters from the last iteration, which is
    often useful despite incomplete convergence.
  • The behavior is consistent with LogisticRegression and other L-BFGS-B
    based estimators, as suggested by maintainers in the issue discussion.

Changes

  • sklearn/linear_model/_huber.py: Removed the if opt_res.status == 2: raise ValueError(...) block. The existing call to _check_optimize_result on the next line already handles this case.
  • sklearn/linear_model/tests/test_huber.py: Added a non-regression test that verifies a ConvergenceWarning is emitted (instead of ValueError) 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.minimize to simulate the failure, making the test deterministic
across all platforms.

Eden Rochman 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
@github-actions github-actions Bot added module:linear_model CI:Linter failure The linter CI is failing on this PR labels Mar 26, 2026
@github-actions github-actions Bot removed the CI:Linter failure The linter CI is failing on this PR label Mar 27, 2026
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.

HuberRegressor failed with ABNORMAL_TERMINATION_IN_LNSRCH on simple dataset

1 participant