scikit-learn: train_test_split & StratifiedKFold

Scores that mean something

35 min · interactive lesson with runnable code and 5 graded exercises.

What you'll be able to do

  • Split with stratify=y and a fixed random_state, in the right return order
  • Keep train, validation and test roles separate
  • Split time-ordered data by time, not randomly
  • Cross-validate a pipeline with StratifiedKFold, then fit once and test once

The full lesson is free with an account.

train_test_split

Train, validation, test

Time-ordered data

StratifiedKFold

cross_val_score

Pitfalls