Part IV — Supervised Learning: Regression & Linear Classifiers · Chapter 6

Logistic regression & the sigmoid

Hook

Linear regression outputs any number at all. What if the answer you actually want is a probability — something that has to stay between 0 and 1?

Intuition

Drag the point along the curve. Near the middle it swings quickly from "probably not" to "probably so" — but far to either side, it barely moves at all, no matter how much further you drag.

Formalize

That S-shaped squashing function is the sigmoid

σ(z)=11+ez\sigma(z) = \frac{1}{1 + e^{-z}}
  • σ(z)\sigma(z) — the sigmoid function: squashes any real number into a probability between 0 and 1.
  • zz — the raw input score being squashed, before it's turned into a probability.
  1. Applied to the same linear score

    Feed in the same linear score from Chapter 1 of this part, z=wx+bz = wx + b. Together, σ(wx+b)\sigma(wx+b) turns any real number into a valid probability.

  2. Where it crosses 0.5 is the decision boundary

    The point where σ(wx+b)\sigma(wx+b) crosses exactly 0.50.5 — where wx+b=0wx+b=0 — is the decision boundary.

Play
z = 1.00(2.0) + (-5.00) = -3.00 → P = 0.05

Drag ww and bb and watch the boundary itself move: bb shifts it sideways, ww controls how sharply the curve turns from 0 to 1 around it.

Worked example

With w=1,b=5w=1, b=-5:

  1. Evaluate at x = 5

    z=1(5)+(5)=0z = 1(5) + (-5) = 0, so σ(0)=0.5\sigma(0) = 0.5 exactly — the boundary.

  2. Evaluate at x = 8

    z=1(8)+(5)=3z = 1(8) + (-5) = 3, so σ(3)0.953\sigma(3) \approx 0.953 — confidently on the "yes" side.

Checkpoint

Balance w and b until the decision boundary — where P = 0.5 — lands exactly at x = 5.

P(x = 5) = 0.95
Move a slider to try it
Summary
σ(z)=11+ez,z=wx+b\sigma(z) = \frac{1}{1+e^{-z}}, \qquad z = wx+b

Logistic regression is linear regression's score, squashed into a probability. Its derivative is exactly the chain rule from Part I — σ\sigma applied to a line, differentiated as σ(z)w\sigma'(z)\cdot w. Next: the loss function built specifically for this kind of output.