Mini-Batch SGD with a Decaying Learning Rate

medium
Checkpoint challenge
Solve this to show you know the material and jump straight to Unit 18. Everything before it counts as cleared.

Implement sgd_logistic(X, y, lr0=0.5, decay=0.01, epochs=20, batch=16, seed=0) for binary logistic regression:

  • each epoch, shuffle the rows with rng = np.random.default_rng(seed) (create rng once, before the first epoch)
  • walk through mini-batches of size batch (the last can be smaller)
  • at update number t (starting at 0), use learning rate lr0 / (1 + decay * t)
  • update with the mean gradient of the log loss over the batch

Return (w, b), starting from zeros.

#optimization#logistic-regression#sgd2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Mini-Batch SGD with a Decaying Learning Rate · TechGradify