The Cross-Entropy Loss That Knows Its Own Calibration
Suppose you are training a binary classifier with outputs and true labels . The average cross-entropy loss on training examples is:
Now suppose the model is perfectly calibrated on the training set, meaning the predicted probability equals the empirical class frequency within every "bucket." In the simplest case: suppose all examples share the same predicted score , and the fraction of positives among them is .
Question: Show that the cross-entropy loss satisfies
where is the binary entropy, with equality if and only if .
In other words: among all constant predictions , the calibrated prediction minimizes the cross-entropy loss, and the minimum value is exactly the irreducible entropy of the label distribution.
Answer: Cross-Entropy Decomposition: Entropy + KL Divergence
Key Idea / Intuition
When you predict a constant for all examples, the cross-entropy loss is a function of alone, and it turns out to be the KL divergence from the true empirical distribution to your predicted distribution , plus the entropy . Since KL divergence is always non-negative and vanishes only when the two distributions match, the minimum is achieved exactly at , yielding .
The deeper message: cross-entropy = entropy + KL divergence. The entropy part is irreducible (it depends only on the labels, not your model). The KL part is the "extra cost" of miscalibration.
Formal Proof / Solution
Step 1: Simplify for constant .
Since all :
Step 2: Decompose into entropy plus KL divergence.
Add and subtract :
So:
Step 3: Apply non-negativity of KL divergence.
By Gibbs' inequality (or Jensen's inequality applied to the convex function ):
with equality if and only if .
Step 4: Conclude.
with equality if and only if .
Why this is the right intuition for ML:
The decomposition is fundamental:
- is the irreducible uncertainty โ you cannot do better than this with a constant predictor, no matter how you set .
- measures your miscalibration penalty โ it is zero only when your predicted probability matches the empirical frequency.
This generalizes: for any model (not just constant predictors), minimizing cross-entropy is equivalent to minimizing KL divergence between the true conditional label distribution and your model's output .
Source: The Elements of Statistical Learning, Ch. 10; mathematical folklore in information theory