PythiloLesson 5 of 8 · progress kept in this browser

Differentiate a regression loss by hand

A linear model predicts w times x plus b. For mean squared error, each example contributes its residual to both gradients, with an additional x factor for the weight. Compute both gradients from the same old parameters before updating either. Mixing old and new parameters changes the optimization step and can hide a derivative bug.

x, y, w, b = 2, 5, 1, 0
error = w*x + b - y
print(2 * error * x)
Your task

Write regression_step(xs, ys, w, b, rate). Nonempty xs and ys have equal length. Return (new_w, new_b) after one gradient step on mean squared error, using the factor 2/n in both gradients.