Loading...
Implement stratified train-test split that preserves the class distribution in both sets.
Given data indices and their labels, split into train and test sets such that each set has approximately the same proportion of each class.
For each unique label, assign floor(count * train_ratio) samples to training and the rest to test (using the original order of indices within each class).
Return a tuple (train_indices, test_indices) where both lists are sorted.
labels = [0, 0, 0, 0, 1, 1, 1, 1, 1, 1] train_ratio = 0.5
([0, 1, 4, 5, 6], [2, 3, 7, 8, 9])