Logistic Regression & The Sigmoid Curve
Despite the name, it is a classifier. Watch a straight line get bent into an S, see how one threshold splits the world into two decisions, and learn the loss that keeps probabilities honest.
The Sigmoid Transformation
Topic 01 predicted numbers. But “spam or not?” needs a probability — and probabilities must live in , while a straight line runs off to .
The fix is a squashing function. Feed the unbounded line score into the sigmoid and it gets bent into a soft S that saturates at exactly 0 and 1:
In the animation, a prediction point slides along the input axis: far left the model is almost sure class 0, far right almost sure class 1, and near the center — where — it genuinely cannot decide and outputs .
Flat ends = confident. Steep middle = everything is decided here.
Steer the Curve, Fit the Data
The weight controls how steep the S is (how quickly the model becomes confident), and the bias slides the decision boundary left or right. Fit the 10 observations below by hand.
Lower the loss to win. The boundary sits where , i.e. — a hyperplane in feature space.
The Decision Boundary & Its Casualties
A linear boundary can never be perfect — those two blinking points are where Topic 03 begins.
The sigmoid outputs a continuous probability, but the world wants verdicts. Applying a threshold (default ) turns the S-curve into a linear decision boundary — everything on one side is class 0, everything on the other is class 1.
In 2D that boundary is a line; in 3D a plane; in 100 dimensions a hyperplane. Same idea, same equation .
Squared error over a sigmoid creates a non-convex, wavy loss surface — gradient descent gets stranded in fake minima. Cross-entropy keeps the bowl-shaped surface that made Topic 01's descent work, and it punishes confident wrong answers without mercy: predicting on a true costs per point and grows without bound.
Those two blinking misclassified points are exactly the FP / FN cells of the confusion matrix — Topic 03 teaches you to price them properly.
Odds, Logits & Binary Cross-Entropy
Probability asks “how likely?”. Odds ask “how many times more likely?” — a 75% event has odds 3:1. Take the log and you get the logit, and something beautiful happens:
The log-odds is linear in the features — logistic regression is linear regression running in odds-space, then translated back by . Each weight multiplies the odds by per unit of .
To train it, maximize the likelihood of the observed labels — equivalently minimize binary cross-entropy:
Each term of the loss is a curve, and the ball riding it tells you what the model feels: when a true-1 point gets probability near 1, the cost flattens to zero; let it drift toward 0 and the cost rockets to infinity.
Because the loss is convex in (w, b), gradient descent always finds the global minimum.
Multi-class? Stack sigmoids and normalize — that is softmax regression, the last layer of every neural network in Topics 07–09.
Weights Multiply Odds, Not Probabilities
A weight is not a nudge on the probability dial. It acts on the odds — the ratio of an event happening to it not happening.
Because the logit is linear, adding one unit of adds to the log-odds — and exponentiating turns that addition into a multiplication: the odds scale by . A weight of doubles the odds; multiplies them by .
That multiplicative reading is the whole reason logistic regression counts as interpretable: each coefficient is a self-contained odds ratio, legible without inspecting the rest of the model.
Ranking raw coefficients across features is meaningless when the features live on different scales — a weight of 2 on a centimetre axis is not the same as 2 on a kilometre axis. Standardize first (mean 0, unit variance), then compare. Same model, comparable numbers.
Slide w negative to shrink the odds toward zero · positive to inflate them · the probability never moves additively
Why Cross-Entropy, Not MSE
Training maximizes the likelihood of the labels you actually saw — equivalently, it minimizes log loss, one term per point, scored only against the truth:
The logarithm is the entire point. is nearly flat near , so a confident correct answer costs almost nothing — but it plunges toward infinity as . Being confidently wrong is not merely penalized; it is catastrophically penalized.
| p̂ | cost | y=0 | cost | y=1 |
|---|---|---|
| 0.99 | 4.61 | 0.01 |
| 0.90 | 2.30 | 0.11 |
| 0.50 | 0.69 | 0.69 |
| 0.10 | 0.11 | 2.30 |
| 0.01 | 0.01 | 4.61 |
Predicting on a true costs . Flip the blunder — predict on that same true — and you pay only . Confidence is cheap when it is right and ruinous when it is wrong.
That explode-to-infinity edge is not a bug to be capped. It is the gradient reporting, in exact proportion, how far the model has strayed.
Watch the cost as the marker sweeps . One bar tracks the penalty for a true 1, the other for a true 0 — and at either edge one of them races off the top of the frame.
Bar height ∝ −ln p, clipped at 3 nats · one bar fills the frame as the other vanishes
A single bowl with one global minimum — gradient descent cannot get stranded, no matter where it starts.
A wavy surface with flat plateaus. Squared error saturates the sigmoid, vanishing gradients stall training, and the descent can settle in a fake minimum.
Pair the sigmoid with log loss and the surface stays convex; pair it with squared error and it does not. That single compatibility is why every modern classifier — up to the softmax heads of Topics 07–09 — trains on cross-entropy.
