Skip to content

Keep pruning cross-validation folds stable across epochs - #318

Merged
not522 merged 1 commit into
optuna:mainfrom
betacatsling:fix/pruning-stable-folds
Sep 24, 2026
Merged

not522 merged 1 commit into
optuna:mainfrom
betacatsling:fix/pruning-stable-folds

Conversation

@betacatsling

Copy link
Copy Markdown
Contributor

Motivation

Pruning keeps a fitted estimator for each CV fold across epochs, but recreates the folds on every epoch. A shuffled splitter with a mutable RandomState then puts previously trained samples into the validation fold, contaminating its score.

Description of the changes

Materialize the splits once per trial and reuse them for its epochs. This preserves per-trial splitter behavior while keeping each estimator's held-out samples fixed.

The regression trains actual SGDClassifier instances and asserts that validation samples never appear in their accumulated training samples, across three epochs and two trials. It fails on the unchanged base. Local sklearn integration suite: 30 passed. Changed-file Black, isort, flake8 and mypy checks passed. Other integration suites were not run.

AI assistance was used for implementation and local verification.

Fixes #317.

@github-actions

Copy link
Copy Markdown

This pull request has not seen any recent activity.

@github-actions github-actions Bot added the stale Exempt from stale bot labeling. label Sep 21, 2026
@not522 not522 added bug Something isn't working and removed stale Exempt from stale bot labeling. labels Sep 24, 2026
@not522 not522 added this to the v5.1.0 milestone Sep 24, 2026

@not522 not522 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@not522
not522 merged commit 698d705 into optuna:main Sep 24, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pruning with shuffled CV leaks training samples into validation across epochs

2 participants