Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 03 / Topic 4 of 6

Train, validation and test splits

  • Training set — the model learns from it.
  • Validation set — you choose between models/settings with it.
  • Test set — touched once, at the end, for the honest final number.

stratify=y keeps the class proportions equal across splits — with 29.9% churn overall, both splits stay at ~30% (the run above shows 0.299 / 0.300). Without it, a small split can end up with a noticeably different rate, and every metric shifts with it.

🔍 Going deeper: with little data, replace the fixed validation set with cross-validation (Part 6) — every row takes a turn validating. The test set still stays untouched until the end.

🧪 Quick quiz

  1. What does stratify=y do in train_test_split?
Show the answer

Keeps the class proportions the same in train and test — verified above: churn rate 0.299 in train, 0.300 in test.

Done here? The practice set for Part 3 — 4 exercises with solutions — is on the part page.

Search the guide