Linear Regression

Fitting a linear model to data using least squares optimisation.

beginner classical ml supervised-learningregression
linear-algebraoptimisationstatisticsleast-squares

Author @Praneeth-Suresh Updated 2026-06-24

Overview

Linear Regression is perhaps the simplest Machine Learning (ML) model out there. Classical Machine Learning tasks are generally categorized into:

  1. Classification: Predict which discrete class label the set of feature values correspond to.
  2. Regression: Predict a continuous numerical value corresponding to the set of feature values.

Linear Regression is the simplest approach to perform the latter.

Linear regression models the relationship between a dependent variable yy and one or more independent variables xix_i using a linear function. In an ML context, we define the prediction of the linear regression model (y^\hat{y}) on the basis of a vector of independent variables x\mathbf{x} as follows:

y^=w⊤x+b\hat{y} = \mathbf{w}^\top \mathbf{x} + b

Note: By convention, the hat notation (carat symbol placed over the variable) is used to denote the estimated or predicted value.

Model Training

We train a linear regression model by minimizing the Mean Squared Error (MSE) loss function defined as follows:

L(w,b)=1n∑i=1n(yi−y^i)2\mathcal{L}(\mathbf{w}, b) = \frac{1}{n}\sum_{i=1}^{n}(y_i - \hat{y}_i)^2

To train the model, we seek to minimize L(w,b)\mathcal{L}(\mathbf{w}, b) with respect to w\mathbf{w} and bb. This objective minimizes the large errors heavier (because of the squared term), leading to a line that is balanced across the dataset.

It can be proven mathematically that this leads to the line of best fit through the set of data-points. In other words, the set of weights and biases that minimize the loss function gives the parameters for the line of best fit.

Closed-Form Solution

If we define the matrix X\mathbf{X} with columns being the features x\mathbf{x}, then we can give a precise set of weights for the line of best fit using the following equation:

w∗=(X⊤X)−1X⊤y\mathbf{w}^* = (\mathbf{X}^\top \mathbf{X})^{-1}\mathbf{X}^\top \mathbf{y}

This is sometimes referred to in the literature as the Normal Equation. Although this gives the precise solution directly, it is important to remember that computing a matrix inverse is a O(N3)O(N^3) operation so with very large sets of features, this becomes computationall intractible.

Note that to account for the bias, the first column of X\mathbf{X} must be filled with 1s.

Limitations

Linear regression is a simple technique to model straight-linear relationships but this makes it very restrictive. In classical machine learning, linear regression is extremely limited because of:

  1. The strict linearity assumption
  2. High sensitivity to outliers (because we deal with squared errors, one large error can significantly skew the line)
  3. Vulnerability to multi-collinearity (when features have correlation, the coefficients become unstable)

This is why vanilla linear regression (the basic version we have seen) is rarely used in working with real world data. It is more a tool that is used to lay the theoretical foundation for more advanced techniques.

Connection to Other Topics

Linear regression forms the basis for Gradient Descent optimisation techniques. Linear regression is a highly interpretable technique, and helps us reason about Explainable AI techniques such as Classical Interpretability Techniques.

Learning Path

What should I learn before Linear Regression?

Linear Regression is marked as a starting topic with no required prerequisites in the corpus.

How does Linear Regression connect to other AI topics?

Linear Regression belongs to Classical ML and connects to supervised-learning, regression, linear-algebra, optimisation, statistics, least-squares.

Further Reading

  1. An Introduction to Statistical Learning