BeginnerCoder

Lesson 24 — Logistic regression training

Train a classifier from scratch

Now combine everything: sigmoid, a score w × x + b, and gradient descent. For logistic regression the gradient is beautifully simple: error = p − y (probability minus true label), then w moves by error × x and b by error — the same shape as linear regression.

p = sigmoid(w * x + b)
error = p - y

After training, check accuracy on the data.

Why it matters: you have just built, by hand, the model behind countless spam filters, credit scores and click predictors.

Want it another way?
Task

Write the two update lines for w and b. After training, accuracy should be 1.0.

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with AI / ML Foundations

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.