Train-Test Split

Also known as · train/test split

Partitioning the data into a training set the model learns from and a held-out test set used to measure honest performance on unseen examples.

When to use

The first step of any supervised pipeline: train_test_split(X, y, test_size=0.2, random_state=42), with stratify=y for imbalanced classes. Never test on training data, since a model that memorises can score 100 percent there. A single split can be lucky or unlucky, which is why Cross-Validation averages over K folds. Also in PS 01.

See DS Lec 3.

Appears in