Sold out or not 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out
The ice cream seller's 16 days. The red circles are days when the ice cream sold out by evening, at the top, 1. The blue squares are days when it did not, at the bottom, 0. We now predict a class, not a number.
Why a straight line fails 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out straight line
A least squares line can be drawn through these 0s and 1s: prediction = 0.06 · temperature + −0.99. But the line goes above 1 in one place and below 0 in another; a probability must stay between 0 and 1.
The sigmoid curve 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out First a linear score is computed: z = w · x + b. Then the sigmoid, σ(z) = 1 / (1 + e⁻ᶻ), squeezes every number between 0 and 1. The black curve is drawn with w = 0.30, b = −6.60.
One day's probability 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out p = 0.71 For a 25 degree day the score is z = 0.90 and the probability is p = σ(z) = 0.71. This is how the model gives the chance that the ice cream sells out on that day.
Threshold and decision 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out p = 0.71 To go from probability to decision, a threshold is chosen, here 0.50. If p is at or above the threshold the model says sold out, otherwise not. Drag the red line up or down to change the threshold.
The decision boundary 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out p = 0.71 The temperature where the probability equals the threshold is 22 degrees. For every day to the right of this boundary the model says sold out, to the left it says not.
The learned curve 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out The blue curve is the logistic regression learned from the data: w = 0.68, b = −15.81. How it is learned is told by the next topic, binary cross-entropy.
Why it matters 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out Logistic regression is still the first model tried for loan approval, disease risk and click prediction, because it gives probabilities and its weights can be read. The last layer of a neural network often does the very same sigmoid computation.