←Back to 03 / Published Articles
03 / Resources/Classification · Logistic Regression
Interactive Diagnostic Essay · Topic 02

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.

01 / From Line to Probability

The Sigmoid Transformation

Topic 01 predicted numbers. But “spam or not?” needs a probability — and probabilities must live in [0,1][0, 1], while a straight line z=wx+bz = wx + b runs off to ±∞\pm\infty.

The fix is a squashing function. Feed the unbounded line score zz into the sigmoid and it gets bent into a soft S that saturates at exactly 0 and 1:

σ(z)=11+e−zP(Y=1∣x)=σ(wx+b)\sigma(z) = \frac{1}{1 + e^{-z}} \quad\quad P(Y=1|x) = \sigma(wx + b)

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 z=0z = 0 — it genuinely cannot decide and outputs 0.50.5.

σ(z) SELF-DRAWING · DOT TRAVERSES FOREVERP(y=1|x)
1.00.50.0z = wx + bclass 0 zoneclass 1 zone0.5 — the fence

Flat ends = confident. Steep middle = everything is decided here.

02 / The Sigmoid Lab

Steer the Curve, Fit the Data

The weight ww controls how steep the S is (how quickly the model becomes confident), and the bias bb slides the decision boundary left or right. Fit the 10 observations below by hand.

WEIGHT (w) · SLOPE SHARPNESS1.20
BIAS (b) · HORIZONTAL SHIFT-2.40
DECISION BOUNDARY (z=0):x = 2.00
LOG LOSS (BCE):0.1459

Lower the loss to win. The boundary sits where wx+b=0wx + b = 0, i.e. x∗=−b/wx^* = -b/w — a hyperplane in feature space.

Class 0 (y=0)Class 1 (y=1)
P(y=1|x)
1.00.50.0x* = 2.0
03 / Drawing the Border

The Decision Boundary & Its Casualties

2D CLASSIFICATION · BLINKING = MISCLASSIFIEDP > 0.5 ?
w·x + b = 0FPFPpredict class 0predict class 1

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 0.50.5) 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 w⋅x+b=0w \cdot x + b = 0.

Why Not Just Use MSE (Like Topic 01)?

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 0.990.99 on a true 00 costs −ln⁡(0.01)≈4.6-\ln(0.01) \approx 4.6 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.

04 / The Betting Interpretation

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:

Log-Odds (Logit) Formln⁡(p1−p)=w⋅x+b\ln \left( \frac{p}{1 - p} \right) = w \cdot x + b

The log-odds is linear in the features — logistic regression is linear regression running in odds-space, then translated back by σ\sigma. Each weight multiplies the odds by ewe^{w} per unit of xx.

To train it, maximize the likelihood of the observed labels — equivalently minimize binary cross-entropy:

Cross-Entropy LossL(w,b)=−1N∑i=1N[yiln⁡(y^i)+(1−yi)ln⁡(1−y^i)]\mathcal{L}(w, b) = -\frac{1}{N} \sum_{i=1}^N \left[ y_i \ln(\hat{y}_i) + (1 - y_i) \ln(1 - \hat{y}_i) \right]

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 −ln⁡(p)-\ln(p) cost flattens to zero; let it drift toward 0 and the cost rockets to infinity.

PER-POINT COST −ln(p)
y = 1y = 0
predicted probability p →cost −ln(p) →confident & right = cheapp = 0.5 → ln 2 ≈ 0.69confident & wrong = ∞ expensive

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.

05 / Reading The Coefficients

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.

odds=p1−plogit(p)=ln⁡ ⁣(p1−p)=w⋅x+b\text{odds} = \frac{p}{1-p} \qquad \text{logit}(p) = \ln \!\left( \frac{p}{1-p} \right) = w \cdot x + b

Because the logit is linear, adding one unit of xx adds ww to the log-odds — and exponentiating turns that addition into a multiplication: the odds scale by ewe^{w}. A weight of ln⁡2≈0.69\ln 2 \approx 0.69 doubles the odds; w=1.2w = 1.2 multiplies them by e1.2≈3.3e^{1.2} \approx 3.3.

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.

The Scale Trap

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.

ONE-UNIT PUSH · START AT p = 0.5Δ logit = w
0.50 before0.769 after
WEIGHT (w) · LOG-ODDS SHIFT1.20
ODDS MULTIPLIER e^w:×3.320
p AFTER x + 1 (FROM 0.5):0.769
WRONG · 0.5 + w1.70

Slide w negative to shrink the odds toward zero · positive to inflate them · the probability never moves additively

06 / Log Loss

Why Cross-Entropy, Not MSE

Training maximizes the likelihood of the labels you actually saw — equivalently, it minimizes log loss, one −ln⁡(p^)-\ln(\hat{p}) term per point, scored only against the truth:

L=−1N∑i=1N[yiln⁡y^i+(1−yi)ln⁡(1−y^i)]\mathcal{L} = -\frac{1}{N} \sum_{i=1}^{N} \left[ y_i \ln \hat{y}_i + (1 - y_i) \ln(1 - \hat{y}_i) \right]

The logarithm is the entire point. −ln⁡(p)-\ln(p) is nearly flat near p=1p = 1, so a confident correct answer costs almost nothing — but it plunges toward infinity as p→0p \to 0. Being confidently wrong is not merely penalized; it is catastrophically penalized.

Asymmetry · Cost In Nats
p̂cost | y=0cost | y=1
0.994.610.01
0.902.300.11
0.500.690.69
0.100.112.30
0.010.014.61

Predicting 0.990.99 on a true 00 costs −ln⁡(0.01)≈4.61-\ln(0.01) \approx 4.61. Flip the blunder — predict 0.010.01 on that same true 00 — and you pay only −ln⁡(0.99)≈0.01-\ln(0.99) \approx 0.01. 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 pp. 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.

CONFIDENCE PENALTY · MARKER WALKS pLOOP · 8s

Bar height ∝ −ln p, clipped at 3 nats · one bar fills the frame as the other vanishes

Cross-Entropy + SigmoidCONVEX

A single bowl with one global minimum — gradient descent cannot get stranded, no matter where it starts.

MSE + SigmoidNON-CONVEX

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.