Lab

Ideas you can poke at

Two of the algorithms I use most often, small enough to fit in a browser. Drag the sliders and watch what breaks — that's usually where the intuition is.

Gradient descent

Optimisation

This is a loss landscape — dark valleys are low, bright ridges are high. The ball follows the slope downhill. Click anywhere to drop it somewhere new, then turn the learning rate up until it stops converging and starts bouncing.

step 0
loss
∇ magnitude

A high learning rate overshoots the minimum and diverges. Momentum helps it roll through shallow dips instead of settling in the first one it finds.

K-means clustering

Unsupervised

Each point joins the nearest centre, then each centre moves to the average of its members. Repeat until nothing changes. Click to add your own points, and try running it twice from the same data — the starting positions are random, so you won't always get the same answer.

iteration 0
points 0
inertia

Inertia is the total squared distance from every point to its centre. It only ever goes down — which is why a lower number doesn't mean a better k.