Fix MissingDataError in multi_mra when features contain NaN#350
Open
drussellmrichie wants to merge 2 commits into
Open
Fix MissingDataError in multi_mra when features contain NaN#350drussellmrichie wants to merge 2 commits into
drussellmrichie wants to merge 2 commits into
Conversation
Real-world property data routinely has missing values (e.g. parking spaces, garage counts, central air) that survive as NaN through the one-hot encoding and astype(float) steps. statsmodels OLS raises MissingDataError on any NaN in the exog matrix. Guard by imputing NaN with training-set column medians before the global OLS fit, then propagate the same medians to X_test, X_sales, and X_univ so all splits are treated consistently. This is the same median-imputation pattern already applied in utilities/stats.py (calc_elastic_net_regularization, calc_p_values_recursive_drop, etc.) and accepted upstream in PRs larsiusprime#313, larsiusprime#316, larsiusprime#318. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
|
Thank you for your contribution. I affirm that this contributor has signed the CLA Russell Richie seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. |
The initial fix only called fillna(col_medians), but two further cases caused the error to persist: - inf values (e.g. FAR = area/land_area where land_area=0) are not caught by fillna; replace inf→NaN first. - Columns that are entirely NaN produce median()=NaN, making fillna a no-op; fall back to 0.0 for such columns. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Problem
run_multi_mra/_run_multi_mracrashes with:when any feature in
ind_varshasNaNvalues. This is common with real-world property data — fields likebldg_parking_spaces,bldg_has_garage,bldg_central_air, etc. are sparsely recorded by assessors and arrive asNaNafter theastype(float)conversion on line 1940.Root cause
_run_multi_mraone-hot encodes categoricals and callsastype(float), which preservesNaNfrom nullableFloat64columns asfloat64NaN. There is no imputation step beforesm.OLS(y_train, X_train).fit(), so statsmodels raises immediately.Fix
Impute
NaNwith training-set column medians immediately before the global OLS fit, and propagate the same medians toX_test,X_sales, andX_univso all splits are treated consistently:This is the same median-imputation pattern already applied in
utilities/stats.py(calc_elastic_net_regularization,calc_p_values_recursive_drop,calc_t_values_recursive_drop,calc_vif_recursive_drop) and accepted upstream in PRs #313, #316, #318.Test plan
multi_mraagainst a dataset with at least one feature containingNaNvalues — confirm it completes withoutMissingDataError🤖 Generated with Claude Code