Fill missing categoricals as UNKNOWN instead of the string "nan" - #394
Open
nikhilsi wants to merge 1 commit into
Open
Fill missing categoricals as UNKNOWN instead of the string "nan"#394nikhilsi wants to merge 1 commit into
nikhilsi wants to merge 1 commit into
Conversation
astype("str") converts NaN to the literal string "nan" before
fillna runs, so models received a "nan" category instead of
"UNKNOWN". Fill on object dtype first, then cast. Adds
tests/test_cleaning.py covering the null-to-UNKNOWN path.
Contributor
|
Thank you for your contribution. I affirm that this contributor has signed the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
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.
What was wrong
In
openavmkit/cleaning.py,_fill_unknown_values(lines 748-749 at7952236) casts categorical fields to
strbefore filling:astype("str")converts NaN to the literal string "nan" first, so thefillnaon the next line never finds anything to fill. Models end up witha "nan" category instead of the intended "UNKNOWN".
The change
Reorder so the fill happens while the nulls are still real:
Going through
objectkeeps NaN intact for the fill and also sidesteps thecategorical-dtype restriction on filling with an unseen category.
What changes downstream
The category label for missing values changes from "nan" to "UNKNOWN", so
one-hot column names and tree categorical levels shift accordingly.
Refitting after upgrading will produce slightly different encodings than
cached models built against the "nan" label; model caches should be
invalidated once this lands.
Verification
A test is included. It runs a frame containing NaN in a declared
categorical field through the fill step and asserts the result contains
"UNKNOWN" and no "nan" values. At 7952236 the "nan" assertion fails; with
this change it passes.
Fixes #377.