1 · Gradient descent · How does a model learn?
Calculate a gradient update in a synthetic delivery model. Compare loss, learning rates, and stable or unstable training, with a worked example and data.
Calculate one gradient update
The model predicts delivery time from distance. Its gradient describes how mean squared error changes when the slope changes.
Four synthetic deliveries. Fixed intercept: 1 minute. Starting slope: 0.5 min/km. Learning rate: 0.05.
This fixed worked example is separate from the interactive lab settings. Interactive controls require JavaScript.
| Distance (km) | Synthetic time (min) | Before (min) | After (min) |
|---|---|---|---|
| 1 | 3 | 1.50 | 2.55 |
| 2 | 5 | 2.00 | 4.10 |
| 3 | 6 | 2.50 | 5.65 |
| 4 | 9 | 3.00 | 7.20 |
new w = 0.5 − 0.05 × (-21) = 1.55
MSE changes from 14.875 to 1.094 min² after this update.
A negative gradient increases w in this update rule. A positive gradient decreases it.
Limits
- This example fixes the intercept. The later two-parameter lab also trains it.
- A learning rate that works here is not a universal setting for other data or models.
Reproduce the calculation
- Reset the delivery model to w = 0.5.
- Use learning rate 0.05 and take one Step.
- Compare each prediction and the mean of its squared errors before and after the update.