Repository navigation
Fix TargetEncoder sklearn export and reject unsupported statistics - #8765
rapids-bot[bot] merged 4 commits into
Conversation
- Test the value of `_encodings_per_feature` rather than its presence. Combination and median fits set it to an empty list, which made the check always true after `fit`, leaving both the single-feature branch and the `UnsupportedOnCPU` branch unreachable: single-feature combination and `stat="median"` exported a model with `encodings_ = []`, and multi-feature combination exported an empty model instead of raising. - Export `y_stat_val` as the sklearn model's `target_mean_`, and use it as the fallback for categories missing from `encode_all`. cuML falls back to `y_stat_val` for unseen categories while sklearn falls back to `target_mean_`, so exporting `self.mean` made the converted model disagree with cuML for `stat="median"` and `stat="var"` (and for `stat="mean"` whenever `y_stat_val` differs from `self.mean`). Tests cover the single-feature combination and median exports, the `UnsupportedOnCPU` path, independent mode, and unseen-category agreement between cuML and the exported model for mean, median and var.
- Use the direct truthiness check on _encodings_per_feature instead of getattr(): all fitted paths initialize the attribute, so the direct check is enough. - Impute NaN/undefined encodings with y_stat_val on export. With stat="var" and smooth=0 the variance of a singleton category is 0/0 (NaN); cuML imputes that with y_stat_val before use, so the exported model must use the same value. The single-feature path now passes y_stat_val as _category_encodings' fill_value, because the helper otherwise falls back to self.mean, which disagrees with cuML for stat="median"/"var"; _replace_nan() covers the remaining export path. - Add a regression test for the singleton-category case (stat="var", smooth=0). - Apply ruff-format to the files touched by this PR (79-column style).
86798ee to
9c8be6c
Compare
|
@csadorf thanks for the review. I've rebased onto current main and both points are addressed in On the conflict: it came from #8698 ("Treat missing string value seen during I resolved it by adopting upstream's One thing worth flagging: To fix it I added an optional Validation (RTX 4070 Ti, from-source cuML 26.12.00a117):
I also updated the PR description with a validation section. One note so it doesn't look like a regression: three Housekeeping: I don't have permission to apply RAPIDS labels here - could you please add |
Reject median and variance export instead of storing a non-mean fallback in target_mean_. Remove export-only fallback translation, preserve native cuML behavior, and cover supported mean-mode exports and unsupported statistics.
|
I’ve restricted Exporting I’ve pushed two commits: one merges |
|
/ok to test b436855 |
|
Updated the PR title and description to reflect the revised scope and implementation. |
|
/merge |
Summary
Fixes
TargetEncoder.as_sklearn()to export populated encodings for single-feature combination mode and validates conversion eligibility for mean-based, per-feature encoding.Raises
UnsupportedOnCPUfor median and variance statistics, preserving sklearn’s mean-based encoding contract.Preserves the target mean and missing-category handling during export. Adds regression coverage for conversion eligibility, exported encodings, and unseen-category fallback.
Closes #8745