Back to Practice
#0156

Check Stratified Split Counts

MediumML25 min20 XP

Problem

Given train labels and test labels, return a dictionary containing class counts for each split.

Why This Matters

A split can silently break evaluation if rare classes disappear from train or test.

Function Signature

def split_class_counts(y_train, y_test):

Examples

Example 1
Inputy_train = [0,0,1,1,1], y_test = [0,1]
Output{'train': {0: 2, 1: 3}, 'test': {0: 1, 1: 1}}

Both splits contain both classes, but proportions differ.

Constraints

  • Return the exact requested value.
  • Handle empty or small inputs when the prompt allows them.
  • Keep the code readable and deterministic.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputy_train = [0,0,1,1,1], y_test = [0,1]
Expected{'train': {0: 2, 1: 3}, 'test': {0: 1, 1: 1}}

Both splits contain both classes, but proportions differ.

Hidden Test Categories
empty or smallest inputduplicates or repeated valueslarger realistic input