Skip to content

Comments

FIX: make HuberRegressor accept boolean X#32

Open
casey-brooks wants to merge 1 commit intoscikit-learn__scikit-learn-13328from
noa/issue-32949
Open

FIX: make HuberRegressor accept boolean X#32
casey-brooks wants to merge 1 commit intoscikit-learn__scikit-learn-13328from
noa/issue-32949

Conversation

@casey-brooks
Copy link

Summary

  • coerce inputs to accepted FLOAT_DTYPES via check_X_y to avoid boolean negation errors in _huber_loss_and_gradient
  • add dense and sparse regression tests that compare boolean matrices with their float-cast counterparts
  • capture the legacy failure stack trace for reference

Pre-fix failure

Traceback (most recent call last):
  File "<stdin>", line 7, in <module>
  File "sklearn/linear_model/huber.py", line 284, in fit
    parameters, f, dict_ = optimize.fmin_l_bfgs_b(
  File "scipy/optimize/lbfgsb.py", line 197, in fmin_l_bfgs_b
    res = _minimize_lbfgsb(fun, x0, args=args, jac=jac, bounds=bounds,
  File "scipy/optimize/lbfgsb.py", line 306, in _minimize_lbfgsb
    sf = _prepare_scalar_function(fun, x0, jac=jac, args=args, epsilon=eps,
  File "scipy/optimize/optimize.py", line 261, in _prepare_scalar_function
    sf = ScalarFunction(fun, x0, args, grad, hess,
  File "scipy/optimize/_differentiable_functions.py", line 140, in __init__
    self._update_fun()
  File "scipy/optimize/_differentiable_functions.py", line 233, in _update_fun
    self._update_fun_impl()
  File "scipy/optimize/_differentiable_functions.py", line 137, in update_fun
    self.f = fun_wrapped(self.x)
  File "scipy/optimize/optimize.py", line 74, in __call__
    self._compute_if_needed(x, *args)
  File "scipy/optimize/optimize.py", line 68, in _compute_if_needed
    fg = self.fun(x, *args)
  File "sklearn/linear_model/huber.py", line 93, in _huber_loss_and_gradient
    X_non_outliers = -axis0_safe_slice(X, ~outliers_mask, n_non_outliers)
TypeError: The numpy boolean negative, the `-` operator, is not supported, use the `~` operator or the logical_not function instead.

Testing

  • pytest -q sklearn/linear_model/tests/test_huber.py --maxfail=1
  • git diff -U0 | flake8 --diff

Fixes scikit-learn#32949

@casey-brooks casey-brooks requested a review from a team December 26, 2025 02:13
@casey-brooks
Copy link
Author

Test & Lint Summary

  • pytest -q sklearn/linear_model/tests/test_huber.py --maxfail=1 (11 passed)
  • git diff -U0 | flake8 --diff (no findings)

Copy link

@noa-lucent noa-lucent left a comment

Choose a reason for hiding this comment

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

Fix ensures HuberRegressor converts boolean inputs to float via check_X_y and adds dense/sparse regression tests. Looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants