A derivative measures how a quantity changes when its input or a model parameter changes. For a loss function, it gives the direction and rate of change at an infinitesimally small neighborhood, avoiding the roughness of probing with a fixed step. section 5.4.2
In learning, calculate the derivative of the loss with respect to each parameter. Collecting those individual derivatives produces the gradient, which describes how the loss changes across the model’s parameters. section 5.4.2 section 5.1
For a linear model and mean squared loss, the calculation follows the chain rule:
- Differentiate the loss with respect to each prediction. For mean squared error, this produces 2 × (prediction − target) divided by the number of data points. section 5.4.2
- Differentiate the model with respect to its parameters. For model = weight × input + bias, the derivatives are the input for the weight and 1 for the bias. section 5.4.2
- Multiply corresponding derivatives and sum across data points to obtain the loss derivatives for the weight and bias. section 5.4.2
From derivatives to a gradient
With model(t_u, w, b) = w × t_u + b and a mean squared loss, compute the loss derivative for every prediction, multiply it by t_u for the weight derivative and by 1 for the bias derivative, then stack the two sums into a gradient. section 5.4.2
Figure 5.6 Comparing numerical vs. analytical gradient calculation. The numerical approach (arrow through points) estimates the gradient using finite differences between discrete points, while the analytical approach (arrow along the curves) calculates the exact gradient at a specific point.
Compare finite differences between discrete points with the analytical derivative evaluated at a specific point. section 5.4.2





