How does linear regression work?
Linear regression works by finding the linear relationship between input features and a continuous target that best fits the training data.
It learns coefficients for the input features and then uses those coefficients to make numerical predictions.
Basic idea
With one input feature, the model has the form:
ŷ = b0 + b1xwhere:
ŷis the predicted valueb0is the interceptb1is the coefficient or slopexis the input feature
The model tries to find values for b0 and b1 that make the predicted values close to the actual targets.
How training works
During training:
- the model starts with candidate coefficient values
- it generates predictions for the training examples
- it measures the difference between each prediction and the actual target
- it adjusts the coefficients to reduce those errors
For ordinary linear regression, the coefficients are commonly chosen to minimize the sum of squared residuals.
What is a residual?
A residual is the difference between an observed target and the model's prediction:
Residual = Actual value - Predicted valueFor example:
Actual price = 50
Predicted price = 46
Residual = 4The model tries to find a line that keeps these residuals as small as possible overall.
With multiple features
When several input features are used, the model becomes:
ŷ = b0 + b1x1 + b2x2 + ... + bnxnEach coefficient represents how the prediction changes with that feature while the other included features are held constant.
Making a prediction
After the coefficients have been learned, a new observation is passed into the equation.
For example:
Predicted Price = Intercept
+ Size Coefficient × Size
+ Room Coefficient × RoomsThe result is the model's numerical prediction.
Why it is called linear
Linear regression is linear in its coefficients: the prediction is a weighted sum of the input features plus an intercept.
If the underlying relationship is strongly nonlinear and the features do not represent that shape, a basic linear model may underfit the data.
In short, linear regression learns coefficients that define a best-fitting linear relationship between the inputs and target, then uses that learned equation to predict numerical values for new observations.
Learning Sequence
Machine Learning Curriculum
What is the equation of a linear regression model?
Explore Related Questions
Deepen your understanding across related Machine Learning topics.