Fix encoding OOV category.#12193
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a correctness bug in the ordinal (auto) re-coder for native categorical features where out-of-vocabulary (OOV) categories could be silently mapped to an in-range training category when lower_bound returned an insertion point rather than an exact match.
Changes:
- Add exact-match verification after
lower_boundin CPU and CUDASearchSortedimplementations (string + numeric) to properly detect OOV categories in-range. - Add CPU and GPU Python tests covering OOV categories whose sorted insertion point falls within the training set.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
src/encoder/ordinal.h |
Adds post-lower_bound equality check to avoid returning an insertion point as a match (CPU path). |
src/encoder/ordinal.cuh |
Mirrors the CPU fix on the CUDA path for both string and numeric category searches. |
python-package/xgboost/testing/ordinal.py |
Introduces run_cat_oov_in_range test helper validating error behavior for in-range OOV categories. |
tests/python/test_ordinal.py |
Wires the new OOV-in-range test into the CPU test suite. |
tests/python-gpu/test_gpu_ordinal.py |
Wires the new OOV-in-range test into the GPU test suite. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
RAMitchell
approved these changes
Apr 30, 2026
Member
RAMitchell
left a comment
There was a problem hiding this comment.
I am still not super happy about us doing recoding.
Member
Author
Yeah, at some point I gave up arguing against that. |
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.
Close #12189