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.
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.
Start With a Simple Example
Suppose we want to predict the price of a house based on its size.
We can see that larger houses generally have higher prices.
Linear Regression tries to learn this relationship.
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.
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.
The goal is not to memorize every individual observation. The goal is to learn the general relationship in the data.
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:
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.
A Simple Numerical Example
Suppose our model has learned this relationship:
Here, imagine that size is measured in square feet and price is represented in lakh units.
For a 1,500 sq ft house:
The model takes the input house size and uses the learned line to calculate the predicted price.
Why Do We Need the Line?
Once the model has learned the relationship, we can give it a value it has not seen before.
The exact prediction depends on the line learned from the training data.
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.
Linear Regression tries to capture the overall linear relationship rather than requiring every observation to sit exactly on the line.
Another Simple Example
Suppose we want to predict a student's exam score based on the number of hours they studied.
A Linear Regression model can learn the general relationship between study hours and exam score.
If a new student studies for 5 hours, the model can use the learned relationship to estimate their score.
Linear Regression in One Picture
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.
Which One Is Linear Regression?
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.