← All AI/ML articles

Multiple linear regression, visualised.

One feature draws a line. Two features draw a plane. Rotate it, tilt it, and see how a model weighs several things at once to predict a price.

1. Tilt the plane2. See who gets the credit3. Watch it learn
above the planebelow the planeDrag the chart to rotate it.
MSE (error)0
R²0
Adjusted R²0
Points0
Behind the scenes · 1

From a line to a plane

Simple regression uses one input. Here the model uses two: Size (x₁) and Age (x₂) to predict Price (y). Each input gets its own weight, and the intercept lifts or lowers the whole plane: ŷ = b + w₁·x₁ + w₂·x₂.


Which feature matters more?
Weight × spread of the feature, so inputs on different scales can be compared fairly.
Behind the scenes · 2

The error is the vertical gap to the plane

Exactly like before: for each point, error = prediction − real value. Squared and averaged, that is the MSE. Turn on Show errors to see each gap as a vertical line.


Behind the scenes · 3

Watch gradient descent tilt the plane

Now there are three numbers to learn (b, w₁, w₂). Gradient descent starts from any plane and nudges all three at once, a little downhill each step. Press Run and watch the plane swing toward the data.


Dashed cyan grid = best possible plane.
White dot = current value, cyan ring = best value.
What the computer does on the next step

Every weight has its own gradient: how much the error changes if that weight moves. Each step subtracts η times its gradient. If the two features are strongly linked, one direction of the bowl is very flat and descent crawls. Try the second challenge below.

Behind the scenes · 4

Alone vs together

Why not run two separate simple regressions? Because a weight in a multiple model means “the effect of this feature while the others stay fixed”. When features overlap, that can differ a lot from the effect on its own.


Behind the scenes · 5

The shortcut: the normal equation

Like the single-feature case, the best plane can be solved directly. Collect sums of the data into a small matrix, then solve the three equations at once: w = (XTX)−1 XTy.


Experiment

Break it on purpose

Nearly identical features

Link Size and Age at 0.95. See the weights become unstable and “alone” differ from “together”.

One outlier

Add a point far from the plane. Watch the best plane tilt to chase it.

Learning rate too high

Set η to 0.18 and run. All three weights overshoot and the plane flies away.

Check yourself

Three quick questions

Key takeaways

  • One feature fits a line, two fit a plane, more fit a hyperplane you cannot draw but can still compute.
  • Each weight is the effect of its feature while the others are held fixed.
  • Learning still means minimising the mean squared error, now over several weights at once.
  • Correlated features share credit, which makes weights unstable and gradient descent slow.
  • Adjusted R² is fairer than R² because plain R² never drops when you add features.
← Back to all articles