BIZNIQUE / LINEAR ALGEBRA / 05
Read a batch training step
Follow predictions, residuals and a gradient without hiding them behind a training loop.
BIZNIQUE / LINEAR ALGEBRA / 05
Follow predictions, residuals and a gradient without hiding them behind a training loop.
THE IDEA
For half the mean squared error, the residual vector is Xw − y. Multiplication by Xᵀ aggregates each feature’s contribution to those residuals. A batch gradient uses the chosen batch of observations to propose one weight update.
∇L(w) = Xᵀ(Xw − y) / n
Faster arithmetic does not guarantee better generalisation. Keep preprocessing, data splits, objective definition and stopping conditions consistent when comparing implementations.
TRY IT YOURSELF
Why does changing the loss from half-MSE to MSE double this gradient?
MSE omits the factor 1/2, so differentiating the squared error leaves a factor of 2.