Skip to main content
Module 4 · Lesson 3 of 617/56 in the course~20 min
Module lessons (3/6)

Cross-validation

Lesson preview5 hands-on exercises readyMachine Learning: from first principles to practice · Module 4 — Generalization and evaluation

K-fold evaluation, its spread, and when to shuffle or stratify.

What you'll learn in this lesson

  • Explain why one train/test split can mislead and how k-fold cross-validation helps.
  • Run cross-validation by hand and with cross_val_score.
  • Know when to shuffle or stratify the folds.

Overview

With a single split, your score depends partly on luck: which rows happened to land in the test set? A different split could give a noticeably different number. Cross-validation reduces that luck by repeating the experiment several times and averaging.

Every sample is used for validation exactly once. Change the number of folds below.

Sections covered in this lesson

  1. 1The hook: one split is one roll of the dice
  2. 2K-fold cross-validation
  3. 3Choosing a cross-validation splitter
  4. 4Progressive examples: CV workflows in scikit-learn
  5. 5Watch out: the order of the rows
  6. 6Practice
Pro Lesson · Module 4 — Generalization and evaluation

Unlock "Cross-validation" and the full Machine Learning: from first principles to practice curriculum

K-fold evaluation, its spread, and when to shuffle or stratify.

Unlock all 5 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Machine Learning: from first principles to practice plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.