MACHINE LEARNING • LESSON 4

A Simple Dataset Split

Let's take one dataset and divide it into training, validation, and test data so we can see exactly how the three parts work together.

THE CORE IDEA

We start with one dataset and separate it into different groups with different responsibilities.

The samples remain examples from the same overall problem, but each group is used for a different stage of the Machine Learning workflow.

01

Start With One Dataset

Imagine we have a dataset containing 10,000 house records.

Each record contains information such as:

  • House size.
  • Number of bedrooms.
  • Number of bathrooms.
  • House age.
  • Location.
  • Selling price.
ORIGINAL DATASET 10,000 Samples

All available examples before splitting.

02

Decide the Split

For this example, we will use a simple 80 / 10 / 10 split.

80% Training
10% Validation
10% Test

With 10,000 samples, that gives us:

TRAINING 8,000

samples

VALIDATION 1,000

samples

TEST 1,000

samples

The numbers add up to the original dataset:

8,000 + 1,000 + 1,000 = 10,000
03

The Dataset Is Now Divided

After splitting, the three groups have different roles.

8,000 SAMPLES Training

Used to teach the model.

1,000 SAMPLES Validation

Used to compare and improve the approach.

1,000 SAMPLES Test

Reserved for final evaluation.

04

What Happens to the Training Data?

The 8,000 training samples are given to the Machine Learning algorithm.

TRAINING 8,000 Samples → Model

The model uses these examples to learn patterns between the input features and known outcomes.

For example, the model may learn relationships between house size and selling price.

05

What Happens to the Validation Data?

The 1,000 validation samples are kept separate from the training process.

VALIDATION 1,000 Samples → Development Decisions

We use these examples to compare models, settings, or approaches while developing the solution.

If one approach performs better on the validation data, we may choose that approach.

06

What Happens to the Test Data?

The 1,000 test samples are kept aside for the final evaluation.

TEST 1,000 Samples → Final Evaluation

After the development process is finished, the final model is evaluated using these examples.

07

Which Rows Go Where?

A simple way to think about the dataset is to number the samples.

TRAINING Rows 1 – 8,000

Used for learning.

VALIDATION Rows 8,001 – 9,000

Used during development.

TEST Rows 9,001 – 10,000

Used for final evaluation.

But don't blindly split real data this way.

In practice, simply taking the first 8,000 rows, then the next 1,000, and so on can create problems if the original data is ordered or grouped.

08

Why Random Splitting Is Often Used

If the dataset is suitable for random splitting, we can randomly assign samples to the different groups.

This helps avoid accidentally putting one type of example entirely into one part of the dataset.

Sample 1
Sample 2
Sample 3
Sample 4
Sample 5
Sample 6
Sample 7
Sample 8
Sample 9
Sample 10
Sample 11
Sample 12

The actual assignment is handled by the splitting strategy rather than manually choosing individual rows.

09

Example With Python

Python libraries can perform these splits for us.

from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(
    X,
    y,
    test_size=0.2,
    random_state=42
)

This creates an 80% training portion and a 20% test portion.

If we also need a validation set, we can split the remaining data again.

X_train, X_temp, y_train, y_temp = train_test_split(
    X,
    y,
    test_size=0.2,
    random_state=42
)

X_validation, X_test, y_validation, y_test = train_test_split(
    X_temp,
    y_temp,
    test_size=0.5,
    random_state=42
)

The result is approximately:

  • 80% training.
  • 10% validation.
  • 10% test.
10

What Does random_state Do?

You may have noticed this:

random_state=42

It makes the random split reproducible.

Without a fixed random state, running the same split again can produce different assignments of samples.

Example 1

Run the script today and Sample 25 goes into the training set.

Example 2

Run the script again without a fixed random state and Sample 25 may end up in another group.

A fixed random state makes experiments easier to reproduce.

11

Random Splitting Is Not Always Correct

This is an important limitation.

Randomly splitting every dataset is not automatically the right solution.

EXAMPLE 1 Time-Based Data

For forecasting future sales, using future records to train while testing on earlier records can leak information.

EXAMPLE 2 Related Samples

If multiple records belong to the same customer or patient, random splitting can place related records in different sets and make evaluation overly optimistic.

The split strategy must match the structure of the real-world problem.

12

The Complete Picture

ORIGINAL DATA 10,000 Samples
80% Training

Learn

10% Validation

Choose

10% Test

Evaluate

KEY IDEA

Splitting Data Is About Protecting the Evaluation

The goal is not to follow one magic percentage. The goal is to create useful separation between learning, development decisions, and final evaluation.

QUICK CHECK

You Have 20,000 Samples

You decide to use an 80 / 10 / 10 split.

How many samples should go into each group?

Answer

Training: 16,000 samples.

Validation: 2,000 samples.

Test: 2,000 samples.

NEXT TOPIC

Putting the Data Split Together

Let's bring everything together and walk through the complete training, validation, and testing workflow from beginning to end.