Clevix Ed

Linear Regression & Gradient Descent

Coding & AI · Class 9–12 · Statistics · Machine learning

All simulations
Drag points · tap empty space to add one

What to explore

Key ideas

The model predicts ŷ = m x + c. Its error is the mean squared error:

J(m, c) = (1/n) Σ (ŷᵢ − yᵢ)²

Gradient descent takes small steps downhill on this cost surface:

m ← m − α ∂J/∂m   c ← c − α ∂J/∂c
∂J/∂m = (2/n) Σ (ŷᵢ − yᵢ) xᵢ   ∂J/∂c = (2/n) Σ (ŷᵢ − yᵢ)

Least squares solves for the bottom of the valley in one go.

Teacher tip

Link this to the Class 11 line of best fit: least squares and gradient descent reach the same line, by two very different routes.

Ask: “Why does the dot zig-zag across the valley instead of rolling straight down?” (The valley is long and narrow because x and 1 have very different sizes.)

Exam corner

In your syllabus

A free coding & ai simulation for Class 9–12.

Topics: regression, line of best fit, least squares, gradient descent, cost function, learning rate, machine learning