2.1.12 · D1Data Preprocessing & Feature Engineering

Foundations — Train - validation - test splitting

1,758 words8 min readBack to topic

Everything in the parent note is machinery built around that single idea. Below we unpack every symbol and word it uses, from absolute zero, in the order they build on each other. If the parent note wrote a symbol without explaining it, we explain it here.


0. What is "data" — the picture behind , , ,

Before any splitting, we need to agree on what we are splitting.

Picture a spreadsheet. Each row is one example (one customer, one photo, one house). Each column is one measured number about that example (age, price, pixel brightness).

Figure — Train - validation - test splitting

Why do we need these letters? Because the entire topic is about cutting rows of into groups. To talk about cutting, we first need a name for the thing being cut (), the inputs (), the answers (), and the total count ().


1. Model, parameters, hyperparameters — three words the parent leans on

The parent note says the training set fits parameters and the validation set tunes hyperparameters. These two words look alike but mean opposite things, so we pin them down.

Why the topic needs this split of words: the training set turns the front knobs, and the validation set helps you pick the back switches. Different jobs → different data. That is the whole reason a second hidden set exists.


2. Generalization and — the quantity we actually care about

The parent writes : performance on unseen data.

So the entire splitting ritual is an attempt to estimate a number we cannot see () using data we can see, by pretending some of our own data is "the future."

  • Generalization = doing well on new data, i.e. a high .
  • Memorizing / overfitting = doing well on practice, badly on new data. (See 3.2.1-Overfitting-underfitting.)
Figure — Train - validation - test splitting

3. A set and mutually exclusive — what "split" literally means

The parent says the three subsets are mutually exclusive. Two symbols make this exact.

Why the topic needs this: if the same row sat in both the training bucket and the test bucket, the "exam" would contain a question the model already practised. Mutual exclusivity is the guarantee that the exam is honest.

In symbols the parent implies:

  • (union) means "pour all buckets together" — you get back the whole pile.
  • (intersection) means "rows shared by two buckets."
  • (empty set) means "no rows at all."

So reads: train and validation share nothing.


4. Ratios and the notation

The parent writes splits like . This is a ratio — a recipe for slicing.

So for the counts: Here just means "the number of rows in the training bucket," and .


5. Proportion and the floor — the stratification symbols

The parent's stratification math uses and those funny brackets .

Why floor appears: you cannot put images in a bucket — rows are whole things. So says: "take this class's share of the training bucket, then round down to a whole count."

Figure — Train - validation - test splitting

Why the topic needs at all: stratification means "keep each class's proportion the same in every bucket." Without a name for that proportion, we couldn't state the rule. (Contrast with the danger in 6.3.2-Data-leakage when proportions or statistics cross bucket boundaries.)


6. Shuffle, index, and the fit / transform pair

The last three symbols the parent assumes are procedural.


How these foundations feed the topic

Dataset D = X and y, size N

Split into mutually exclusive sets

Model with parameters and hyperparameters

Need one bucket to tune, one to grade

Goal P unseen we cannot see

Class proportion p c and floor

Stratified split keeps proportions

Shuffle then index rows

Fit on train transform others

No leakage into test

Train Validation Test Split 2.1.12

Each box is one symbol group above. Follow the arrows and you have rebuilt the whole parent note from zero. Next steps that use this foundation: 2.1.13-Cross-validation (reuse hidden data cleverly) and 4.1.5-Early-stopping (use the validation bucket during training).


Equipment checklist

Cover the answer and say it out loud before revealing.

, , , — what each stands for
= number of rows; = input columns; = answer column; = the whole dataset ( and together).
Difference between a parameter and a hyperparameter
A parameter is a knob the machine turns itself from training data; a hyperparameter is a knob you set by hand before training.
What means and why we can't measure it directly
Performance on future/never-seen data; we can't measure it because that data hasn't arrived, so we fake it with hidden buckets.
What "mutually exclusive" guarantees
No row appears in two buckets, so the test acts as an honest exam.
Read in plain words
Train and test share no rows.
Meaning of the ratio
Of every 100 rows, 70 go to train, 15 to val, 15 to test; they add to 100.
Meaning of
The fraction of the whole dataset that belongs to class .
Compute and why we floor here
; because a bucket must hold a whole number of rows.
Why we shuffle before splitting
To destroy any hidden ordering that would make a slice all one class.
The fit / transform rule in one sentence
Fit (compute ) on train only, then transform val and test with those train numbers.