Fix/issue 397 stratified splitting - #402
Open
intagliated wants to merge 1 commit into
Open
Conversation
intagliated
force-pushed
the
fix/issue-397-stratified-splitting
branch
from
April 25, 2026 18:42
c305891 to
b4c921c
Compare
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.
PR: Label-Aware Site Stratification for Training Splits
Linked Issue
Closes #397
Summary
This PR introduces Label-Aware Site Stratification to ensure that rare species (e.g., the "zebra" case) are consistently represented across all data splits (Train, Validation, and Holdout).
Previously,
zambautilized a standard group-based split which prioritized site integrity but ignored label distribution. This resulted in rare classes being dropped from evaluation sets if their corresponding sites were randomly assigned to the training set. This fix implements a Greedy Iterative Stratification algorithm to balance these constraints.Key Changes
zamba/data/operations.py: Addedgenerate_stratified_group_split. This core function uses a greedy approach to distribute sites based on their label composition.zamba/models/model_manager.py: Updated the training entry point to automatically trigger this stratified approach when asitecolumn is present and no manualsplitis provided.zamba/models/config.py: UpdatedTrainConfigto ensure seamless integration with existing data-loading parameters.Implementation Details
The algorithm functions as a multi-objective optimization:
Note
This approach strictly respects the
sitegroup constraint. 100% of samples from a single site will always remain in the same split to prevent data leakage.Verification Results
tests/test_issue_397_stratification.pyusing a skewed dummy dataset.Comparative Performance