MACHINE LEARNING • LESSON 7

What Is Linear Regression?

Linear Regression is a machine learning algorithm used to predict a numerical value by learning a straight-line relationship between the input and the output.

THE SIMPLEST DEFINITION

Linear Regression learns the best straight line through the data.

Once the model learns that line, it can use the line to predict numerical values for new data.

01

Start With a Simple Example

Suppose we want to predict the price of a house based on its size.

House Size Price
1,000 sq ft ₹50 lakh
1,500 sq ft ₹70 lakh
2,000 sq ft ₹90 lakh
2,500 sq ft ₹110 lakh

We can see that larger houses generally have higher prices.

Linear Regression tries to learn this relationship.

02

What Does "Linear" Mean?

The word linear means that the model represents the relationship using a straight line.

For example, imagine plotting our house data on a graph:

::contentReference[oaicite:0]{index=0}

The points represent the houses we already know about. The straight line represents the relationship that the Linear Regression model has learned.

03

The Model Tries to Find the Best Line

The line does not necessarily pass through every data point.

Real-world data usually contains variation. Therefore, Linear Regression tries to find a line that represents the overall pattern as well as possible.

DATA Real observations
LINEAR REGRESSION Finds a suitable line
MODEL Learned relationship

The goal is not to memorize every individual observation. The goal is to learn the general relationship in the data.

04

The Linear Regression Equation

A simple Linear Regression model can be represented using this equation:

::contentReference[oaicite:1]{index=1}

In machine learning, we commonly write the prediction as:

ŷ = b₀ + b₁x
ŷ Predicted value
x Input feature
b₀ Intercept
b₁ Slope / coefficient

You do not need to memorize the mathematics yet. The important idea is that the model uses the input x and learned values to calculate a prediction.

05

A Simple Numerical Example

Suppose our model has learned this relationship:

Price = 10 + 0.04 × Size

Here, imagine that size is measured in square feet and price is represented in lakh units.

For a 1,500 sq ft house:

Price = 10 + 0.04 × 1500 Price = 70 Predicted Price = ₹70 lakh

The model takes the input house size and uses the learned line to calculate the predicted price.

06

Why Do We Need the Line?

Once the model has learned the relationship, we can give it a value it has not seen before.

NEW HOUSE 1,800 sq ft
LEARNED LINE Relationship
PREDICTION ₹82 lakh

The exact prediction depends on the line learned from the training data.

07

Linear Regression Does Not Mean Perfectly Straight Data

This is an important point for beginners.

Your data does not have to form a perfect straight line. The observations can be scattered around the line.

TOO SIMPLE TO EXPECT Every point exactly on the line
REALISTIC Points generally follow a linear pattern

Linear Regression tries to capture the overall linear relationship rather than requiring every observation to sit exactly on the line.

08

Another Simple Example

Suppose we want to predict a student's exam score based on the number of hours they studied.

Study Hours Exam Score
1 hour 45
2 hours 55
4 hours 70
6 hours 85

A Linear Regression model can learn the general relationship between study hours and exam score.

More study hours → generally higher predicted score

If a new student studies for 5 hours, the model can use the learned relationship to estimate their score.

09

Linear Regression in One Picture

Training Data
Find the Linear Relationship
Learn the Best-Fitting Line
Give New Input
Predict Numerical Value
REMEMBER THIS

Linear Regression = Learn a Straight-Line Relationship to Predict a Number.

The model looks at existing data, learns a line that represents the relationship between the input and numerical output, and then uses that line to make predictions for new data.

QUICK CHECK

Which One Is Linear Regression?

House size → House price Numerical prediction
Study hours → Exam score Numerical prediction
Email → Spam / Not Spam Category prediction
Answer

The first two are suitable examples of regression problems. Linear Regression can be used when we want to model a linear relationship and predict a numerical value. Spam detection is a classification problem.

NEXT TOPIC

Simple Linear Regression

Next, we will look at the simplest form of Linear Regression: using one input feature to predict one numerical output.