Gradient Descent Intuition
Part of the Machine Learning Roadmap
In short
Almost every model, from a simple regression to a giant neural network, learns the same way: take small steps that make the error a bit smaller. That's gradient descent.
Gradient descent finds good model weights by repeatedly taking a small step opposite the gradient of the loss, like walking downhill in fog. The learning rate sets the step size: too big and you overshoot, too small and training crawls.

Think of it like this
Walking down a dark valley
It's night and your torch only lights the ground at your feet. To reach the bottom, you check which way slopes down, take a step, and check again. Steep ground, bigger steps. Nearly flat, you're almost there.
Watch it happen
w after each step (loss = (w − 3)², lr = 0.1)
1/5Start at w = 0. The slope 2(w − 3) is −6, so moving right lowers the loss.
The big ideas
What you need to know
Step against the gradient
New weight = old weight − learning rate × gradient. That moves you downhill on the error.
Learning rate sets step size
Too small and training crawls. Too big and you overshoot and the loss can blow up.
Mini-batches save time
Stochastic and mini-batch versions use a few rows per step instead of the whole dataset.
Not every valley is simple
Complex models have bumpy error surfaces. You may land in a good spot, not the perfect one.
See it in code
Walk through the code
1def loss(w):2 return (w - 3) ** 23 4def grad(w):5 return 2 * (w - 3)6 7w, lr = 0.0, 0.18for step in range(50):9 w = w - lr * grad(w)10print(round(w, 4), round(loss(w), 6)) # 3.0 0.01/4The loss we want to shrink and its slope (gradient).
Gradient descent in four lines. Real libraries do the same thing with millions of weights.
Save yourself the pain
Common mistakes
Oops
Setting a huge learning rate to 'train faster'.
Do this instead
Try lr = 1.1 in the code above. w jumps further each step. Start small and tune.
Oops
Running gradient descent on features with wildly different scales.
Do this instead
Scale features first. Otherwise the steps zigzag and training takes far longer.
Your mission
Break and fix the learning rate
Quick check
Your training loss jumps up and down and keeps getting bigger. What's the most likely fix?
Go deeper
- 1Minimise (x - 3) squared by hand for five steps with a learning rate of 0.1.
- 2Try learning rates of 0.01, 0.1 and 1.1 and see which ones converge.
- 3Plot the loss after each step to see the curve flatten.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.