One curve, 16 days 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out A logistic regression curve is drawn with w = 0.30, b = −6.60. It gives a probability for every day. We want to measure with one number how good this curve is.
One day's loss 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out The day with the largest loss is day 14: the ice cream did not sell out, but the model gives selling out 0.71. The right class gets 1 − 0.71; the loss is −ln(1 − 0.71) = 1.24.
All the days 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out Each day's line is the distance between its real class and the model's probability. The longer the line, the smaller the probability given to the right class and the larger the loss.
Why a logarithm 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out A model giving the right class 0.9 loses 0.11, one giving 0.5 loses 0.69, one giving 0.01 loses 4.6. A confident but wrong prediction is punished very hard; as the probability nears 0, the loss grows without limit.
The mean loss 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out loss 0.34 The mean of the 16 days' losses is the binary cross-entropy: 0.34. The gauge at the top shows this number. Drag the rings to change the curve and the loss changes too.
Why not squared error 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out loss 0.34 We could square the gap between the probability and 0 or 1. But with a sigmoid, squared error makes the loss surface flat and gradient descent slows down. Cross-entropy balances the sigmoid's slope; the gradient is simply prediction minus truth.
The smallest loss 8 12 16 20 24 28 32 36 0 0.25 0.50 0.75 1 temperature, degrees chance of selling out loss 0.34 The blue curve is found by making the mean cross-entropy smaller with gradient descent: w = 0.68, b = −15.81, loss 0.27. Yours has a loss of 0.34.
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 loss 0.34 Binary cross-entropy is the loss every two-class model minimises in training, logistic regression and neural networks alike. Its many-class form is the cross-entropy used with softmax.