MACHINE LEARNING • LESSON 4

Validation Data

Validation data is a separate portion of the dataset used during model development to compare choices and decide which approach works better.

THE CORE IDEA

Training data teaches the model. Validation data helps us decide how to build the model.

Validation data is not normally used as the primary data for fitting the model. Instead, it helps us evaluate different choices while developing it.

01

Why Do We Need Validation Data?

Suppose you train a house-price model.

After training, you discover that you have several choices:

  • Model A.
  • Model B.
  • Model C.

You need a fair way to compare these choices using data that was not used to fit the model.

That is where validation data becomes useful.

02

Training vs Validation

TRAINING DATA Used to learn

The model uses these examples to learn relationships between features and labels.

VALIDATION DATA Used to compare

We use these unseen examples to help decide which model or configuration is better.

03

A Simple Example

Imagine that we have 10,000 house samples.

We might divide them like this:

TRAINING 8,000 samples

Used to train the model.

VALIDATION 1,000 samples

Used during development.

TEST 1,000 samples

Kept for final evaluation.

The exact percentages are not universal rules. They depend on the problem and the amount of available data.

04

Compare Two Models

Suppose we train two different models using the same training data.

MODEL A Validation Error: 12%

Performs reasonably well on unseen validation examples.

MODEL B Validation Error: 8%

Performs better on the validation examples.

Based on this validation result, Model B looks like the better choice.

The important point is that we did not choose the model based only on its training performance.

05

Validation Helps With Model Choices

Machine Learning often involves making decisions during development.

For example:

  • Which model should we use?
  • Which settings should we choose?
  • Which approach performs better?
  • Should we change the model?

Validation data gives us evidence that can help answer these questions.

06

Don't Train on the Validation Data

The purpose of validation data is to provide an independent check during development.

If you train the model directly on the validation examples, you weaken the meaning of the validation result.

Keep the roles separate.

Training data is for learning. Validation data is for making development decisions.

07

Validation Is Not the Final Test

This distinction is extremely important.

If we repeatedly compare models using the validation data, we are making decisions based on that data.

Therefore, the validation data is no longer a completely untouched final evaluation.

Training

Learn model parameters.

Validation

Choose and improve the approach.

Test

Final evaluation.

The test set should remain separate until the final evaluation.

08

A Real-World Analogy

Think about preparing for a driving test.

TRAINING Practice

You learn how to drive using practice situations.

VALIDATION Mock Test

You use practice exams to identify weaknesses and improve.

TEST Real Exam

The final test measures how well you perform on an unseen evaluation.

09

Validation Data in Python

Later, we may explicitly create training and validation sets using tools such as scikit-learn.

from sklearn.model_selection import train_test_split

X_train, X_validation, y_train, y_validation = train_test_split(
    X,
    y,
    test_size=0.2,
    random_state=42
)

The exact implementation can change depending on the project. The important idea is that the validation examples are kept separate from the data used to fit the model.

10

Validation Helps Us Improve

Imagine we try three different approaches.

Model A 15% validation error
Model B 8% validation error
Model C 11% validation error

Based on the validation results, Model B currently looks like the strongest candidate.

We can then take that development process forward before performing the final test.

11

The Biggest Mistake to Avoid

A common mistake is repeatedly checking the test set and changing the model based on the result.

For example:

Bad workflow

Train → Test → Change model → Test again → Change model → Test again.

The test set is gradually becoming part of the model development process.

A better approach is to use validation data for those development decisions and save the test set for the final evaluation.

KEY IDEA

Validation Data Helps You Choose

Training data is used to learn. Validation data is used during development to compare models and make decisions. The test set should remain separate for the final evaluation.

QUICK CHECK

Which Dataset Should You Use?

You trained two house-price models and want to decide which one performs better before the final evaluation.

Should you use the training data, validation data, or test data to make this development decision?

Answer

Use the validation data.

The training data was used to learn, while the test data should be kept for the final evaluation.

NEXT TOPIC

Test Data

Validation helps us choose and improve a model. Next, we will look at the final independent check: the test dataset.