BuildMidData / MLAuto-graded
Split a dataset reproducibly with balanced classes
Return the same split for the same seed, use every row exactly once, and keep each class's share in both halves.split(X, y, test_size, seed, stratify=True) divides labelled rows into a training set and a test set and returns four lists, with each row still next to its label. The version in splitter.py doesn't do this reliably, so scores measured on its output can't be trusted. Make the same seed give the same split, put every row in exactly one set, size the test set to test_size, and keep each class's share when stratify is on. Standard library only.35 min
python
You're done when
- Every row ends up in exactly one of the two sets, with none lost or repeated, even when some rows have identical values.
- Running with the same seed gives exactly the same split.
- With stratification on, each class keeps its share of the data, and its count in the test set is right to within one row.
- The test set has the requested size, give or take rounding.
What it measures
Stratified samplingWhether each class keeps its share in both sets, including small and imbalanced classes.
Row bookkeepingPlacing every row exactly once, even when several rows hold the same value.
ReproducibilityWhether the seed fully decides the split, so a reported result can be rerun and checked.
Your environment
Terminal + editorA full shell in the browser
Coding agentAlready signed in, no API key to set up
Isolated workspaceOnly yours, wiped when you finish
Start this lab
35 min
Start labYou'll need to sign in to Anthropos first. The lab opens in a private cloud workspace with your coding agent ready to use.AI Labs is part of Anthropos Workforce. Not on your plan yet? Book a demo