Loading...
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Logistic regression learns a line that separates classes by turning raw features into probabilities. Play the simulation to watch weights update and the boundary refine.
Turn numbers into decisions.
Classification is the task of taking an input (like an email’s text features or a patient’s test results) and outputting a category (spam/not spam, disease/not disease).
Imagine a bouncer with two doors. A simple model watches your features and decides which door you should walk through—then it gives a confidence based on how close you are to the boundary.
A mental model you can reuse.
A classifier doesn’t just pick a label. It learns a boundary where the meaning shifts from class 0 to class 1.
Because we want decisions that generalize—not guesses.
You’re given examples: some points are class 1, others are class 0. The job of the model is to learn a rule that predicts the label for new, unseen points.
Each training step nudges weights to make misclassified points less likely.
In the simulation below, if the loss is going down, the boundary is becoming more helpful.
Decision boundary learns a line
Loading Lab...
Each formula maps to a visual part of the simulation.
If a point is class 1 but the model says probability is tiny, the log penalty is large—so loss shoots up.
Think of as your step size (learning rate). In the lab, moving the learning-rate slider changes how fast the boundary tries to improve.
Industry use-cases + why teams choose it.
A few extra visuals to deepen intuition.
Copy-friendly Python example.
# Logistic Regression (binary classification) - tiny gradient descent demo
import math
import random
def sigmoid(z):
return 1 / (1 + math.exp(-z))
def cross_entropy(points, w):
# w = [b, w1, w2]
eps = 1e-8
total = 0.0
for x1, x2, y in points:
z = w[0] + w[1]*x1 + w[2]*x2
p = sigmoid(z)
total += -(y*math.log(p+eps) + (1-y)*math.log(1-p+eps))
return total / len(points)
def grad(points, w):
gb = gw1 = gw2 = 0.0
n = len(points)
for x1, x2, y in points:
z = w[0] + w[1]*x1 + w[2]*x2
p = sigmoid(z)
err = p - y
gb += err
gw1 += err * x1
gw2 += err * x2
return [gb/n, gw1/n, gw2/n]
# Synthetic data: (x1, x2, y) where y in {0,1}
points = [(0.1,0.2,0), (0.9,0.8,1)] # replace with your dataset
lr = 0.2
steps = 100
w = [0.0, 0.0, 0.0]
for t in range(steps):
loss = cross_entropy(points, w)
g = grad(points, w)
w = [w[0]-lr*g[0], w[1]-lr*g[1], w[2]-lr*g[2]]
if t % 10 == 0:
print(t, "loss=", loss, "w=", w)Visual failure modes you can recognize.
Cheat sheet + interview-friendly questions.