Repository navigation
Conversation
ensure_dataframe() filled every entirely-NaN column with 0 or "missing" in every context. During prediction a single row with a missing value forms an all-NaN column, so it bypassed the imputer fitted on the training data and the prediction depended on the other rows in the batch. The constant fill now applies only to training data (context="fit"); validation input and prediction input, including InferenceModel.validate_input(), keep their missing values for the fitted preprocessor. Fixes #495
This branch has not been deployed
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.
Fixes #495
Problem
A missing value in a single-row prediction request was replaced by
0(numeric) or"missing"(categorical) instead of being imputed by the preprocessor fitted on the training data. In the issue's example, a row with a missingagewas predicted as 15.8 on its own (exactly the prediction forage=0) but as 49.7 inside a two-row batch.Root cause
ensure_dataframe()fills entirely-NaN columns with a constant. That safeguard exists for training data: an all-NaN training column gives PreTab nothing to learn an imputation from. The fill also ran on prediction input (validate_input_features), onInferenceModel.validate_input()(which used the defaultcontext="fit") and on explicitX_val, where a single row with a missing value already forms an all-NaN column.Fix
ensure_dataframe()applies the all-NaN fill, and itsDataWarning, only whencontext == "fit".X_valis passed withcontext="validation"in both_FitMixin._build_modelandSklearnBaseLSS.build_model.InferenceModel.validate_input()passescontext="predict".Validation and prediction inputs keep their missing values, and the preprocessor's fitted imputer fills them. Training data is unchanged: a training column that is entirely NaN is still filled with the constant. The imputer is then fitted on that constant, so later missing values in that column at prediction time are imputed with the same constant.
Tests
tests/core/test_exceptions.py: withcontext="predict"or"validation", all-NaN numeric and object columns are left as NaN and noDataWarningis emitted.tests/integration/test_data_workflows.py: a single-row prediction with a missing numeric or categorical value equals the prediction for the same row inside a larger batch, andInferenceModel.validate_input()keeps the missing value.All 4 new cases fail on
mainand pass with this change.Docs
ensure_dataframedocstring now says the fill is training-only.Checks
just test: 3240 passed, 46 skipped, 28 xfailed; coverage 91.29%just docs: build succeeded (warnings treated as errors)just check: all hooks passed (ruff, prettier, pyright)