Skip to content

fix: guard against n_splits > n_samples in rolling-origin CV#315

Open
drussellmrichie wants to merge 1 commit intolarsiusprime:masterfrom
drussellmrichie:fix/tuning-min-samples-cv
Open

fix: guard against n_splits > n_samples in rolling-origin CV#315
drussellmrichie wants to merge 1 commit intolarsiusprime:masterfrom
drussellmrichie:fix/tuning-min-samples-cv

Conversation

@drussellmrichie
Copy link
Copy Markdown

Problem

_lightgbm_rolling_origin_cv crashes when n_splits exceeds the number of samples in the dataset. This happens with small model groups (e.g. a locality with very few sales in a given segment).

Fix

Clamp n_splits to n_samples at the top of the function. If the clamped value is less than 2 (not enough for CV), emit a UserWarning and return a penalty MAPE of 1.0 rather than crashing.

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>
@github-actions
Copy link
Copy Markdown
Contributor

Thank you for your contribution.
Please sign our CLA at the following link:
Click here to sign the CLA.
A maintainer will verify your signature and confirm it here by commenting with the following sentence:


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.
You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant