← All AI/ML articles

Logistic regression, visualised.

Linear regression predicts a number. Logistic regression predicts a probability and draws a line between two classes. Add points, bend the boundary, and watch a model learn to say “yes” or “no”.

1. Separate the classes2. Read the probabilities3. Tune the threshold
Hover over the chart to read the model’s probability anywhere.
class 1class 0misclassifiedClick to add · drag to move · double-click to remove · right-click adds the other class
Log-loss0
Accuracy0
Misclassified0
Points0
Behind the scenes · 1

From a line to a probability

First the model computes a score z = w₁x₁ + w₂x₂ + b, exactly like linear regression. That score can be any number, so the sigmoid squashes it into 0 to 1: p = 1 ÷ (1 + e−z). Below, every point sits on the curve at its own score. Class 1 points should land high on the right, class 0 low on the left.


Vertical line = where p reaches your threshold. Score 0 means p = 50%.
Behind the scenes · 2

Log-loss: punish confident mistakes

Suppose a point truly belongs to class 1. If the model says p = 0.99 the cost is tiny. If it says p = 0.01 (confidently wrong) the cost explodes. Log-loss grows without limit as the model becomes confidently wrong, while squared error is capped at 1. That steep penalty is what drives learning. Drag the slider.


Behind the scenes · 3

Watch gradient descent find the boundary

Start from any boundary and nudge the three numbers downhill on the log-loss. Remarkably, the gradient has the same shape as in linear regression: (prediction − truth) times the input. Only the prediction is now a probability.


Log-loss over steps.
What the computer does on the next step
Behind the scenes · 4

Threshold, confusion matrix and ROC

The model outputs a probability. You choose the cut-off for saying “class 1”. Slide it and watch the boundary in the main chart move, the confusion matrix change, and the dot travel along the ROC curve.


Precision0
Recall0
F10
AUC0
Precision = of the points called class 1, how many truly are. Recall = of the true class 1 points, how many we caught.
ROC: each threshold gives one point. Top-left is perfect, the diagonal is guessing. White dot = your threshold.
Behind the scenes · 5

What the weights mean: odds

Logistic regression is linear in the log-odds. So adding 1 to a feature multiplies the odds of class 1 by ew.


Experiment

Try it yourself

Overlapping classes

When classes mix, no boundary is perfect. Watch accuracy and log-loss hit a ceiling.

Catch every positive

Drop the threshold to 0.2. Recall rises, but more false alarms appear.

Perfectly separable

With no overlap, the weights grow forever and the loss creeps to zero.

Check yourself

Three quick questions

Key takeaways

  • Logistic regression is a classifier: it outputs the probability of class 1.
  • The sigmoid squashes any score into 0 to 1; the boundary is where p equals your threshold.
  • Log-loss heavily punishes confident wrong answers and is what training minimises.
  • The threshold is your choice: trade precision against recall to suit the problem.
  • Each weight multiplies the odds by ew for every +1 in its feature.
← Back to all articles