
Stochastic Gradient Descent (60 Pages)
You can already ask an AI to write you a stochastic gradient descent training loop. The problem is knowing why a learning rate that looks reasonable makes the loss explode in the first epoch, why a run with a constant step size jitters around the answer forever instead of settling on it, or why a script that never reshuffles its data, or that gets one sign wrong in a gradient, can still show a falling loss while learning the wrong thing. None of that is visible from model.fit(). This is the course that gives you that judgment.
Five parts, one algorithm, no gaps:
· Part 1 — Intro. Why the gradient of a single random example points downhill on average, why that noise is the price of cheap steps and how a shrinking learning rate tames it, and how mini-batches, momentum, Adam and variance reduction refine the same loop. The intuition before the notation.
· Part 2 — By Hand. A complete worked example: fitting a straight line to four points with four SGD steps, one full epoch, where every prediction, error, gradient and update is shown and checked against the exact least-squares answer. Nothing waved away, nothing left “as an exercise.” You watch two steps make the fit slightly worse before the fourth cuts the loss sharply, and prove the algorithm to yourself.
· Part 3 — In Excel. The same example built out in a spreadsheet you can open and poke at, one SGD step per row, so you see exactly which point is visited and how the line moves each step, and watch 200 steps (50 epochs) converge onto the known answer as you change the learning rate, the decay, the starting point or the data.
· Part 4 — In Python. A clean, executable, verified reference implementation that checks its own answer against the exact least-squares solution and a brute-force grid search, prints PASS or FAIL, and lets you try mini-batches and momentum with a one-line change: the known-good version you can check any other code against.
· Part 5 — With AI. A tested prompt that directs an AI assistant to carry this same algorithm to your problem, plus the understanding to catch it when it's wrong.
By the end you won't just have working code. You'll have followed the algorithm from first principles through a hand calculation, a spreadsheet, and production Python — so when you point an AI at your own training problem, you'll know how to choose a learning rate and schedule on purpose, insist on a gradient check and a baseline before trusting a falling loss, and tell when the answer is right.