MACHINE LEARNING • LESSON 7

Prediction With Linear Regression

After a Linear Regression model learns a relationship from training data, we can give it new input and ask it to predict a numerical value.

THE SIMPLEST DEFINITION

New input → trained model → numerical prediction.

The model uses the relationship it learned during training to estimate the output for data it has not seen before.

01

Start With a Trained Model

Suppose we trained a model using students' study hours and exam scores.

Study Hours Exam Score
1 hour 45
2 hours 55
3 hours 65
4 hours 75
5 hours 85

After training, suppose the model learns this relationship:

Score = 35 + 10 × Study Hours
02

Give the Model New Input

Now imagine a new student who studied for 6 hours.

The model has not seen this student's data during training. We want it to predict the student's score.

NEW INPUT 6 hours
TRAINED MODEL Linear Regression
PREDICTION Exam Score
03

Calculate the Prediction

We put the new input into the equation learned by the model.

Score = 35 + 10 × Study Hours

The new student studied for 6 hours:

Score = 35 + 10 × 6 Score = 35 + 60 Predicted Score = 95
The model predicts an exam score of 95.
04

Prediction Is an Estimate

This is important: the prediction is not guaranteed to be the student's actual score.

The model might predict:

MODEL Predicted Score = 95
REAL WORLD Actual Score = 91

The model made an estimate based on the relationship it learned from the training data.

The difference between the actual value and predicted value is called the residual or prediction error.

05

Prediction for Another Example

Let's use a different problem: predicting house prices.

Suppose the trained model learned:

Price = 20 + 0.04 × Size

Now we have a new house with a size of 1,500 sq ft.

Price = 20 + 0.04 × 1500 Price = 20 + 60 Predicted Price = ₹80 lakh

The model uses the new house size and the relationship it learned during training to produce the prediction.

06

What Happens Inside the Model?

At a simple level, the prediction process looks like this:

New Input
Trained Linear Regression Model
Apply Learned Relationship
Predicted Numerical Value

The model does not simply memorize the answer. It uses the parameters it learned during training to calculate a prediction.

07

Multiple Linear Regression Prediction

The same idea works when there are multiple input features.

Suppose a house-price model uses:

FEATURE 1 Size

2,000 sq ft

FEATURE 2 Bedrooms

3 bedrooms

FEATURE 3 Age

5 years

Size
+
Bedrooms
+
Age
Predicted Price

Multiple Linear Regression combines all the input features using the learned coefficients to produce one numerical prediction.

08

Prediction vs Training

Do not confuse these two stages.

TRAINING Model learns

Uses training data to learn the relationship and coefficients.

PREDICTION Model uses what it learned

Uses new input to produce an estimated output.

Training creates the model. Prediction uses that trained model.

REMEMBER THIS

Prediction = New Input + Trained Model → Estimated Output.

The model first learns a relationship from training data. When new input is provided, the trained model applies that learned relationship to produce a numerical prediction.

QUICK CHECK

Can You Follow the Prediction?

Model: Score = 35 + 10 × Hours The model has already been trained.
New input: 5 hours This is the value we want to predict from.
Prediction: 85 35 + (10 × 5) = 85.
Answer

The trained model takes the new input of 5 hours and calculates a predicted score of 85.

NEXT TOPIC

Build Linear Regression With Python

Next, we will build a real Linear Regression model using Python and see how training and prediction work in code.