2.6.11 · D2Model Evaluation & Selection

Visual walkthrough — Log-loss and calibration

1,990 words9 min readBack to topic

This page rebuilds the parent result one picture at a time. We start with nothing but a coin flip and a guess, and end holding the exact log-loss formula, understanding why every symbol is there. Bring only middle-school arithmetic — everything else we build.


Step 1 — A guess and a truth

Let us name the two things carefully, in plain words first.

  • The truth is a switch that is either OFF or ON. We write it . We agree means "didn't happen" and means "happened". Nothing more — is just a label, a flag.
  • Your guess is a number between 0 and 1, written (say "p-hat"). The little hat means "this is your estimate, not the truth." means "I'm 90% sure it happens."

WHY these two and nothing else? Because scoring a forecaster needs exactly two ingredients: what you said () and what reality did (). The whole rest of the page is one question — how do we turn this pair into a fair penalty?

Look at the picture: a number line from 0 to 1 with your guess as a blue dot, and reality shown as a single lit-up bulb (ON = ). The gap between your dot and the true corner is what we want to punish.


Step 2 — The probability you assigned to what actually happened

Two cases, because reality has two doors:

  • If it happened (): you had put on that door. Your credit is .
  • If it didn't (): the two guesses had to sum to 1, so you had put on the "no" door. Your credit is .

WHY ? Because "happens" and "doesn't happen" cover everything and can't both be true — their probabilities must add to 1. So whatever you gave to YES, the leftover automatically went to NO.

The figure splits into two panels — the YES door and the NO door — with the slice of probability you assigned to the door reality actually opened highlighted in yellow. That yellow slice is your credit.


Step 3 — One formula for both doors (the clever exponent trick)

Watch what these exponents do:

:: raise your YES-guess to the power . This term is a light switch. :: raise your NO-guess to the power . The other light switch. :: multiply the two switches together.

WHY does this work? Anything to the power is — a "do nothing" factor. So the exponent acts as a selector:

  • When : first term is ; second is . Product . ✅ matches Step 2.
  • When : first term is ; second is . Product . ✅ matches Step 2.

This is the Bernoulli likelihood — the probability of one yes/no outcome under your forecast. (See Cross-Entropy Loss for where this line reappears.)

The picture shows the exponent as a dimmer switch: the power dims a term all the way to (invisible), the power leaves it fully lit. Only the door reality chose stays lit.


Step 4 — Turn "good is big" into "penalty is small": take

Right now, big credit = good. But a loss should be small = good, so gradient descent can push it down. We need a machine that flips "big is good" into "small is good" — and does three extra favours.

Apply it to the credit from Step 3:

Now use the log rule and — exactly the "products become sums" magic we chose it for:

:: active only when (else kills it). Penalty for the YES door. :: active only when . Penalty for the NO door. :: the flip that makes "confident-and-right" cost near zero.

The figure plots across : flat near the right (credit 1 → cost 0) and diving to the sky on the left (credit 0 → cost ). This cliff is the whole personality of log-loss — it punishes confident wrongness without mercy.


Step 5 — Degenerate cases: the edges of the cliff

A formula you cannot trust at its extremes is a trap. Let us walk every corner.

Truth Guess What you did
1 right & sure (no penalty)
1 wrong & sure (ruin)
0 right & sure (no penalty)
0 wrong & sure (ruin)

WHY the infinities? If you swear ("impossible") and it happens, you claimed a real event had no probability. The log of is ; negated, it's . The math is telling you: never say never. In code we clip to so a single lunatic prediction doesn't blow the whole average to infinity.

The picture is a square of the four corners; two are painted green (cost ), two are painted pink and marked with spikes — the confident-wrong corners where the cliff of Step 4 becomes a wall.


Step 6 — From one event to a whole dataset: just add and average

:: "walk through every sample and total up its penalty." :: divide by the count so 4 samples and 4 million samples live on the same scale. :: the truth and guess for the -th sample.

WHY average instead of just sum? So the number means "typical penalty per prediction" — comparable across datasets of different sizes. This averaged is exactly the Cross-Entropy Loss, and it is a genuine proper scoring rule: its minimum is reached only by telling the honest truth.

The bar chart shows each sample's individual penalty as a chalk bar; the tall pink bar (confident-wrong sample) towers over the rest, and the dashed line marks the average — visibly dragged up by that one bar.


Step 7 — Worked walk-through on 4 points


The one-picture summary

The final figure stitches the whole journey: a guess meets a truth → the exponent selector picks the credit → flips it up the cliff → sum and average gives . Follow the arrows once and you have re-derived binary log-loss.

Recall Feynman retelling — say it like a friend

You made a bet about a yes/no thing. First we asked: how much of your probability landed on what actually happened? — that's your credit. A slick exponent trick, , writes both the "it happened" and "it didn't" cases in one line, because anything to the power zero just switches itself off. But "big credit is good" is backwards for a loss, so we hit it with negative-log — a machine that gives zero pain when you were sure-and-right and infinite pain when you were sure-and-wrong, and conveniently turns the multiplying of probabilities into simple adding. We checked all four corners so nothing surprises us, agreed to never literally say 0 or 1 (or we'd get infinity), then added everyone's pain and divided by how many there were. That average is log-loss. It rewards honesty above all — the way to make it smallest is to say numbers that are actually true.

Recall Quick checks

Why negative log and not, say, ? ::: Only turns products into sums, so many predictions' penalties add cleanly — and it makes the confident-wrong penalty explode, which is the behaviour we want. What does the exponent in actually do? ::: It's a selector: power 0 makes a term equal 1 (off), power 1 leaves it on. So only the door reality opened contributes. Why can log-loss be infinite? ::: If you predict exactly 0 for something that happens, you claimed an impossible event occurred; . Fix by clipping to . Where is calibration in all this? ::: Log-loss scores sharpness+honesty per point; calibration (Reliability Diagrams, Brier Score) separately checks that your stated 70% really happens 70% of the time.

Related: Information Theory (log-loss = expected bits of surprise), Temperature Scaling and Focal Loss (post-hoc and training-time fixes), ROC-AUC (ranking, ignores calibration), Bayesian Neural Networks (calibrated uncertainty by construction).