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)Think before coding
Both partial derivatives come from the same loss surface location. Dividing by the sample count keeps the update scale independent of duplicating a batch. The factor of two follows the unhalved squared-error definition. Work through the example by hand before changing the starter. Decide what should happen for an empty input, a single value and a repeated value where those cases apply. The checks use several inputs so a hard-coded answer cannot stand in for the rule.
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.
The explanation opens here once every check passes.