Skip to content

Linear Regression Explained

For people

The simplest predictive model: how linear regression fits a line through data, how to read its coefficients, and when it breaks down.

Editorial team 2 min read

Share X LinkedIn Reddit Bluesky Email

Linear regression predicts a number as a weighted sum of input features. It is simple, fast and surprisingly useful.

How It Works

The model assumes the target is roughly a straight-line function of the features: price ≈ b0 + b1 × size + b2 × bedrooms. Training finds the coefficients (b0, b1, b2…) that minimise the squared differences between predictions and actual values — the method of least squares.

Reading the Coefficients

Each coefficient says how much the prediction changes when that feature increases by one unit, holding the others fixed. That makes linear models easy to explain, provided features are on sensible scales and not strongly correlated with each other.

Assumptions to Check

  • The relationship is roughly linear.
  • Errors are independent and have similar spread across predictions.
  • Features aren't highly collinear (which makes coefficients unstable).
  • Outliers aren't dominating the fit.

Plotting residuals (actual minus predicted) against predictions reveals most problems.

Extending It

  • Add transformed features (logs, squares, interactions) to capture curves.
  • Use regularised versions — ridge and lasso — to prevent overfitting with many features.

When to Use It

Use linear regression as a baseline for any numeric prediction, and as a final model when explainability matters more than squeezing out the last bit of accuracy.

from sklearn.linear_model import LinearRegression
model = LinearRegression().fit(X_train, y_train)
print(model.coef_, model.intercept_)

More in Machine learning

All Machine learning guides →
Machine learning Guide · 2 min

Logistic Regression for Classification

Despite its name, logistic regression is a classification method. How it produces probabilities and why it remains a strong baseline.

Machine learning 2 min read 24 Sep 2026 For people

Machine learning Guide · 2 min

Decision Trees

How decision trees split data with simple questions, why they are easy to explain, and why single trees overfit.

Machine learning 2 min read 23 Sep 2026 For people

Machine learning Guide · 2 min

Random Forests

Why averaging many randomised decision trees produces a robust, accurate model with little tuning.

Machine learning 2 min read 22 Sep 2026 For people

Machine learning Guide · 2 min

Gradient Boosting

How gradient boosting builds trees that correct each other's mistakes, and why it dominates tabular machine learning.

Machine learning 2 min read 21 Sep 2026 For people

Discussion 0

Use @handle to bring somebody in, and #tag to file it.

Nothing here yet. Ask a question, or say how you used it.

Sign in to join the discussion. Sign in