⚡ Gradient Descent: Batch, Mini-batch and Stochastic

Noah's notes in chapter 2 describe the decisions around gradient descent: how many examples each update uses, how many epochs, which learning rate, where to start and when to stop. This notebook implements all of them with a single training loop, on 1,000 days of patients and masks, and measures the effect of each one.

The interactive notebook includes:

  • One training loop for batch, mini-batch and stochastic descent.
  • Updates per epoch and the cost after each epoch for batches of 1,000, 100, 10 and 1 example.
  • The paths of the three variants on the cost surface.
  • Why the data is shuffled at the start of every epoch.
  • Learning rates that are too small, good, too large and divergent, as in Noah's figure.
  • Three stopping criteria: cost change, gradient size and a maximum number of updates.
  • Random and heuristic initializations.
  • Watching the cost on a validation set and halving the learning rate when it stops improving.

Want to modify the code and experiment on your own?
Open the notebook in Google Colab

Bibliography