WRITE · TRACE · UNDERSTAND

Linear Regression

Move a fitted line by following the mean squared-error gradient

Your experiment

fit(xs, ys, steps, rate) begins at w=b=0 and returns (w, b) after steps of gradient descent on mean squared error. Compute both gradients from the old parameters; include the factor 2/n.

Python runs in your browser. Your draft stays on this device.

What to look for

The gradient tells which parameter direction increases loss. Subtracting it moves downhill. Watch the fitted line and loss curve; a large learning rate can overshoot even when the derivatives are correct.

Watch your code work

Ready to experiment

Write a solution or load the worked answer, then choose Trace & check.

Step through arrays, variables and training curves produced by your own Python.