2.6.11 · D3Model Evaluation & Selection

Worked examples — Log-loss and calibration

2,185 words10 min readBack to topic

This page is the exhaustive drill. The parent note 2.6.11 gave you the formulas. Here we throw every kind of input at those formulas — perfect predictions, catastrophic ones, the edge cases that produce or , the degenerate model, and an exam trap — and grind each one to a number.

Before any formula appears we re-anchor its meaning in one line, because the promise of this vault is: no symbol used before it is earned.

Recall Two symbols we lean on constantly

::: the probability your model announced for the event happening (a number between 0 and 1). ::: the truth, written as if the event happened and if it did not. Log-loss for one sample ::: when , and when — "surprise at the truth".


The scenario matrix

Every log-loss / calibration problem is one of these case classes. The examples below each carry a tag like [Cell A] so you can see the whole space is covered.

Cell Case class What makes it special Example
A Confident & correct near the true label → loss near Ex 1
B Confident & wrong near the opposite of truth → loss explodes Ex 2
C Timid / uncertain () moderate loss regardless of outcome Ex 3
D Degenerate input ( or ) : the clipping fix Ex 4
E Multi-class (one-hot) only the true class term survives Ex 5
F Calibration: over- vs under-confident bins ECE via reliability gap Ex 6
G Degenerate calibration (empty bin, perfect bin) how ECE handles and gap Ex 7
H Real-world word problem translate a story → Ex 8
I Exam twist (accuracy vs log-loss disagree) which model "wins"? Ex 9

Two anchor pictures for the whole page:

Figure — Log-loss and calibration

The loss curves above are the single most important image on this page. Read the amber curve as "the penalty when the truth was ": it dives to as your announced (you were right and confident), and rockets toward as (you were confidently wrong). The cyan curve is the mirror for .

Figure — Log-loss and calibration

The reliability diagram above is the picture behind every calibration example: the diagonal is "confidence tells the truth"; a bar's height above/below the diagonal is its calibration gap.


The worked examples


Recall

Recall Which branch of the log-loss do I use?

When ::: use . When ::: use .

Recall Why does one confidently-wrong sample dominate a batch?

Because of a tiny number is huge (unbounded above) ::: while a correct confident sample only earns a penalty near — the curve is steep on the wrong side, flat on the right side.

Recall Do empty calibration bins change ECE?

No ::: their weight multiplies away any (undefined) gap.

Recall Can a lower-accuracy model have lower log-loss?

Yes (Ex 9) ::: log-loss rewards honest, informative probabilities; accuracy only checks the side of the threshold.

Related deep tools: Reliability Diagrams, Temperature Scaling, Focal Loss, ROC-AUC, Bayesian Neural Networks.