fix: guard against all-NA scores in calc_correlations#316
Open
drussellmrichie wants to merge 2 commits intolarsiusprime:masterfrom
Open
fix: guard against all-NA scores in calc_correlations#316drussellmrichie wants to merge 2 commits intolarsiusprime:masterfrom
drussellmrichie wants to merge 2 commits intolarsiusprime:masterfrom
Conversation
When a model group has very few training samples (e.g. sparse commercial or post-valuation sub-models), KFold raises ValueError if n_splits exceeds the number of rows. Cap n_splits at len(X) and return a penalty MAPE of 1.0 when fewer than 2 samples are available, so Optuna can still complete gracefully. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
When a model group has very few sales (e.g. vacant land with 9 records),
pandas' idxmin() raises ValueError('Encountered all NA values') instead
of returning NaN as in older pandas versions. Break out of the variable
elimination loop early when all scores are NA so downstream code is
unaffected.
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. |
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
calc_correlationscrashes with aKeyErrororValueErroron.idxmin()when the computedscoreSeries is all-NA. This occurs when there are too few samples to compute meaningful correlations (e.g. very small model groups or sparse data).Fix
Add an early
breakwhenscore.isna().all()is detected, exiting the variable-dropping loop gracefully instead of crashing.Note: this branch also includes the fix from #315 (
fix/tuning-min-samples-cv), on which it stacks.