Thanks to visit codestin.com
Credit goes to github.com

Skip to content

MNT Remove dead negative-value-as-missing convention for categorical features in HGB - #34663

Open
cakedev0 wants to merge 2 commits into
scikit-learn:mainfrom
cakedev0:cleanup/negative-categorical-missing-convention
Open

MNT Remove dead negative-value-as-missing convention for categorical features in HGB#34663
cakedev0 wants to merge 2 commits into
scikit-learn:mainfrom
cakedev0:cleanup/negative-categorical-missing-convention

Conversation

@cakedev0

@cakedev0 cakedev0 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Reference Issues/PRs

Not tied to an open issue.

Follows up on:

There are other clean-ups to do because of this behavior change.

Note: I'm not trying to revert the behavioral change, and I don't to. I think it's a better behavior this way, even though it's different from LightGBM.

What does this implement/fix? Explain your changes.

This PR:

  • Removes the dead is_categorical and data[i] < 0 branch in _binning.pyx and the analogous data_val < 0 branch in _predictor.pyx.
  • Drops the now-unused is_categorical parameter from _map_to_bins/_map_col_to_bins (and updates its one call site).
  • Update tests

Any other comments?

  • Info: I'm separately gathering evidence on whether mapping unknown categories to missing value is a good default policy at all.
  • Question: should we back-port the doc update (DOC: clarify categorical missing docs (HGB & trees) #34553) to earlier versions? I think there are a couple of versions where the HGB doc says negative values are treated as missing values while it's actually not true.

AI usage disclosure

I used AI assistance for:

  • Code generation
  • Test/benchmark generation

…features in HGB

The internal `_BinMapper`/`TreePredictor` classes used to treat negative
values of numeric-encoded categorical features as missing, following a
LightGBM convention. Since 1.4, categorical preprocessing in the public
estimators always goes through an internal OrdinalEncoder that remaps
categories to dense non-negative codes, so this branch has been
unreachable dead code for a while. This removes it and updates the tests
that pinned it, replacing them with tests documenting the current,
intentional behavior (only categories unseen at fit time -- regardless
of sign -- are treated as missing).
assert_array_equal(bin_mapper.transform(X), expected_trans)


def test_categorical_feature_negative_missing():

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This can't happen so it's not worth testing. IMO, having this test is just confusing.

@cakedev0
cakedev0 marked this pull request as ready for review August 6, 2026 13:07
@cakedev0 cakedev0 added this to Labs Aug 10, 2026
@cakedev0 cakedev0 moved this to PR waiting for reviews in Labs Aug 10, 2026
@cakedev0
cakedev0 requested a review from adam2392 September 3, 2026 13:25

@adam2392 adam2392 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.

Does this need a documentation update on the behavior change? Lmk if this was already addressed in previous PR.

Otherwise LGTM.

@cakedev0

cakedev0 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

The doc update was addressed in #34553

@adam2392

adam2392 commented Sep 4, 2026

Copy link
Copy Markdown
Member

Oh missed that. Then LGTM. Thanks!

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.

2 participants