Lesson 20 — Gradient descent
Gradient descent with two weights
Now the model has two weights: pred = w * x + b, where b is the bias (the intercept). Training updates both. The gradient for w is error × x; the gradient for b is just error. Going through the data example by example and updating after each one is called stochastic gradient descent (SGD). One pass over all data is an epoch.
miss = (k * h + c) - p
k -= rate * miss * h
c -= rate * miss
Why it matters: real models have millions of weights, but each one is updated exactly like this.
Write the two update lines. After 200 epochs the model should find y = 2x + 1.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based AI / ML Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for AI / ML Foundations books — check the publication year so the examples match current versions.
Search Amazon →