MACHINE LEARNING • LESSON 1 • HOW ML LEARNS

Training vs Prediction

We now know what a Machine Learning model is. The next important step is understanding what happens before a model can make predictions and what happens when we actually use it.

Training and prediction are two different stages.

During training, the model learns from data. During prediction, the trained model is used to produce an output for new data.

The Big Difference

TRAINING

Learn From Data

The learning algorithm uses training examples to determine a useful model.

VS
PREDICTION

Use the Model

The trained model receives new input and produces an output.

STAGE 1

What Happens During Training?

Training is the learning stage.

We provide the algorithm with examples from which it can learn useful relationships.

INPUT Training Data

Examples containing information relevant to the problem.

PROCESS Learning Algorithm

Searches for a useful relationship in the training data.

RESULT Trained Model

The learned result that can later be used for predictions.

Example: Training a House Price Model

Suppose we have historical house data.

SIZE PRICE
800 sq ft $300,000
1,000 sq ft $400,000
1,200 sq ft $500,000
1,500 sq ft $650,000
1,800 sq ft $750,000

The learning algorithm examines these examples and learns a relationship between house information and price.

AFTER TRAINING A trained house-price model
STAGE 2

What Happens During Prediction?

Prediction happens after we already have a trained model.

We give the model new information and ask it to produce an output.

NEW INPUT 1,400 sq ft

A house the model has not seen during training.

TRAINED MODEL Apply What Was Learned

The model uses its learned relationship.

OUTPUT Predicted Price

An estimated result is produced.

The Most Important Difference

DURING TRAINING The model is learning.

The algorithm uses examples to determine the learned values that form the model.

DURING PREDICTION The model is being used.

The trained model takes new input and produces an output.

Prediction Does Not Mean Retraining

This is a common beginner confusion.

Suppose the model has already been trained. We then give it one new house.

The model uses what it already learned to produce a prediction.

TRAINED MODEL Ready
NEW HOUSE 1,400 sq ft
PREDICTION Estimated Price
The model does not start learning from scratch every time it receives a new input.

Think of Machine Learning as Two Main Phases

01
TRAINING

Learn

Use training data to learn a model.

02
PREDICTION

Use

Use the trained model on new data.

Example 1: Spam Detection

TRAINING Learn From Emails

Give the algorithm many emails labeled as spam or not spam.

MODEL Learned Spam Patterns

The trained model represents patterns useful for distinguishing the categories.

PREDICTION New Email

The model predicts whether the new email is spam.

Example 2: Customer Purchase Prediction

TRAINING DATA Previous Customers

Customer information and whether they purchased a product.

TRAINED MODEL Learned Relationship

A model that can estimate purchase behavior.

NEW CUSTOMER Prediction

Estimate whether the customer is likely to purchase.

Training and Prediction Can Have Different Costs

Training can require significant computation, especially when the dataset or model is large.

Once a model is trained, making an individual prediction can often be much faster.

TRAINING More computation

The system is learning from many examples and adjusting the model.

PREDICTION Use the learned model

New input is passed through the already trained model.

Does a Model Ever Need to Be Trained Again?

Yes.

If new data becomes available or the real-world relationship changes, we may need to retrain or update the model.

OLD DATA Existing Training
NEW DATA Additional Examples
RETRAIN Updated Model

But this is different from prediction itself. Prediction simply uses the current trained model.

Common Beginner Confusion

"Does the model learn when I make a prediction?"

Not normally. Prediction uses the trained model. Learning happens during training.

"Is the training data the model?"

No. Training data contains examples. The model is the learned result produced from those examples.

KEY IDEA

Training teaches the model. Prediction uses the model.

Training uses examples to create a learned model. Prediction takes new input and passes it through that trained model to produce an output.

The Complete Flow

01 Training Data

Past examples

02 Training

Learn patterns

03 Trained Model

Learned relationship

04 New Input

New data

05 Prediction

Output

NEXT SECTION

Build It With Python

We now understand the basic Machine Learning workflow. Next, we'll stop talking only about examples and build a simple model with Python.