Lesson 4.5 · 7 min read · about 45 min to master at a very slow pace
Cross-entropy / Log-loss
Cross-entropy is the negative average log-likelihood. Why it punishes confident wrong predictions so hard, how to compute it, and how it differs from accuracy as a measure.
Binary cross-entropy (log-loss)
For each observation, only one term is active: if , and if . So the loss is "minus the log of the probability you gave to the truth".
true y = 1: −ln ptrue y = 0: −ln(1 − p)
| given to the truth | 0.99 | 0.9 | 0.5 | 0.1 | 0.01 |
|---|---|---|---|---|---|
| 0.010 | 0.105 | 0.693 | 2.303 | 4.605 |
Why use it to fit classifiers?
- It is the maximum-likelihood loss for a yes/no (Bernoulli) outcome.
- It rewards good probabilities, not just correct classes. Predicting 0.51 and 0.99 for a true positive both count as "correct" for accuracy, but cross-entropy prefers 0.99.
- It is smooth and, for logistic regression, convex: easy to optimise.
Cross-entropy vs accuracy
| Accuracy | Cross-entropy | |
|---|---|---|
| Uses | Hard class predictions | Predicted probabilities |
| Depends on threshold | Yes | No |
| Rewards confidence | No | Yes (and punishes overconfidence) |
| Good for fitting | No (not smooth) | Yes |
Sign conventions
The log-likelihood has no minus sign and is maximised. Cross-entropy is and is minimised. Both are correct; don't mix them in one sentence.
Cheatsheet
Log-loss values
: 0.99→0.01, 0.9→0.105, 0.5→0.693, 0.1→2.303, 0.01→4.6.
Sign of the log-likelihood
is maximised (≤ 0). Cross-entropy is minimised (≥ 0).
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.