Fix the class counts after a SMOTE resample
Your task
An AI fixed class imbalance by running SMOTE (which makes synthetic minority rows from nearby real ones) on the whole dataset, then splitting. Synthetic rows were built from neighbors that later landed in the test set, and the test set itself came out balanced, unlike production. Validation recall read 0.95, and real recall was mediocre. The fix splits first and oversamples only the training side.
An assistant wrote resampled_split_counts(labels, in_test), which reports the class counts after the fix. It is in the editor. It has a bug. Find it and fix it.
Input and output:
labels: each row's label. 1 is the positive, minority class, and any other value is negative.in_test: whether each row is in the test set, at the same index.- Return a list of four counts after resampling: training negatives, training positives, test negatives, test positives.
Rules the tests check:
- Use only the first n rows, where n is the shorter length.
- Count each class on each side.
- The test counts are returned unchanged.
- On the training side, each class with at least one row is oversampled up to the larger of the two training counts. A class with no training rows stays at 0: SMOTE builds new rows from existing ones, so it cannot create a class from nothing.
Examples
resampled_split_counts(labels: list[int], in_test: list[bool]) -> list[int]Example 1
Input
resampled_split_counts([0, 0, 0, 0, 1, 0, 0, 1], [False, False, False, False, False, True, True, True])Output
[4, 4, 2, 1]Example 2
Input
resampled_split_counts([1, 0], [True, True])Output
[0, 0, 1, 1]