2.6.11 · D1Model Evaluation & Selection

Foundations — Log-loss and calibration

2,709 words12 min readBack to topic

This is the ground floor for the parent topic. Read Hinglish version: 2.6.11 Log-loss and calibration (Hinglish). Nothing below assumes you have seen probability notation, logarithms, or summation signs before. We build each symbol, anchor it to a picture, and say why the topic needs it.


1. What is a probability? The symbol

Picture a horizontal bar from left () to right (). Sliding a marker along it is exactly "changing your confidence".

Figure — Log-loss and calibration

We write a probability with the letter . When it is a probability the model predicts (a guess, not a truth), we put a little hat on it: — read aloud as "p-hat". The hat always means "estimated / predicted by us", never "the real answer".


2. Interval vs set notation: and

Before we use them, let us pin down two bracket conventions you will meet everywhere.

So says "a guess can be any value on the ruler", while says "the truth is only ever one of two labels". The symbol reads "is an element of / lives in".


3. The true outcome: the symbol

Reality is not a probability — it either happened or it did not. We record that with .

Contrast the two symbols so they never blur (both bracket conventions were defined above):

Symbol Lives where Meaning Example
anywhere in model's guess
only reality's verdict

The whole game is comparing a soft guess against a hard truth .


4. The logarithm: the symbol

This is the tool the topic is named after, so we build it carefully.

The only facts we actually need are visual:

Figure — Log-loss and calibration

Read three things off the curve of for between 0 and 1:

  • . A perfect prediction earns zero penalty.
  • As shrinks toward , dives to (negative infinity, just defined). A tiny probability produces a huge negative number.
  • is negative for every in . That is why the loss formulas always have a minus sign out front — to flip the penalty back to positive.

We will lean on two algebraic properties of logs, so let us name them explicitly.


5. Combining guess and truth: exponents as switches

The parent writes the Bernoulli likelihood . The trick is that (which is 0 or 1) acts as an on/off switch in the exponent.

Now we turn that likelihood into the per-sample log-loss, one justified algebra step at a time.

Each step had a named reason: product rule to split, power rule to drop exponents, negation to make the score positive. See Cross-Entropy Loss for where this exact expression comes from in Information Theory (it is "bits of surprise"), and Brier Score / Proper Scoring Rules for sibling ways to grade probabilities.


6. Summation and averaging: the symbols and

We rarely grade one prediction; we grade a whole dataset of of them.

The subscript is just a name tag on each sample: is the truth of sample number , its predicted probability. Multiplying the whole sum by turns a total into an average — so datasets of different sizes stay comparable.


7. Multi-class notation: the extra index and one-hot vectors

With more than two classes we need a second name tag. The class index is , running from to (the number of classes).

The bold letters signal "this is a whole list (vector)", not a single number.


8. Calibration symbols: bins , accuracy, confidence

Calibration needs us to group predictions with similar confidence and check reality inside each group.

Figure — Log-loss and calibration

Inside a bin we compute two averages:

  • = average of the model's guesses in the bin (what it claimed).
  • = average of the truths in the bin, i.e. the fraction that actually happened (what reality delivered).

The Expected Calibration Error rolls all (non-empty) bins into one number, weighting each by its share so a tiny bin can't dominate:

Plotting on the x-axis and on the y-axis gives a reliability diagram; the perfect diagonal is . See Temperature Scaling for the standard fix when the curve sags below it, and ROC-AUC for a ranking-based metric that ignores calibration entirely.


9. Prerequisite map

Probability p and p-hat

Bernoulli switch p^y times 1-p to the 1-y

True label y in 0 or 1

Logarithm log x plus its rules

Log-loss formula

Summation and averaging

Class index k and one-hot vectors

Multi-class cross-entropy

Bins B_m accuracy and confidence

Expected Calibration Error

Log-loss and Calibration


Equipment checklist

Cover the right side and test yourself. If any line is fuzzy, re-read its section above.

Difference between , and ?
= all reals 0 to 1 incl. ends; = same but excluding ends; = only the two values 0 and 1.
What does the hat in mean?
The number is the model's predicted/estimated probability, not the true answer.
What two values can a binary label take, and what do they mean?
= event did not happen, = event happened.
What does mean?
Negative infinity — plunges more negative than any nameable number, never bottoming out.
What question does answer?
"What power must I raise the base to, in order to get ?"
Does the choice of log base change which model wins?
No — it only rescales every loss by the same constant; ML defaults to natural log.
What is , and why does that matter for log-loss?
It is , so a perfect prediction earns zero penalty.
State the product and power rules for logs.
; .
Why does log-loss have a minus sign out front?
is negative for in ; the minus flips the penalty back to positive.
In , what happens when ?
It collapses to , because .
Which two log rules turn the Bernoulli likelihood into the log-loss sum?
Product rule splits the product into two logs; power rule drops each exponent to the front.
What breaks if is exactly 0 or 1, and the fix?
A wrong prediction gives = infinite loss; clip into .
What does mean?
Add up through .
What does multiplying a sum by do?
Turns a total into an average, comparable across dataset sizes.
How does multi-class log-loss extend the binary average?
Same over samples, plus an inner sum over the classes.
What is a one-hot vector?
A list with in the true-class slot and everywhere else.
What is a bin in calibration?
The set of all predictions whose confidence falls in slice of .
How do you handle an empty bin in ECE?
Skip it — it carries weight and its averages would divide by zero.
What is vs ?
Average claimed probability in the bin vs. fraction of events that truly happened.
What does perfect calibration look like on a reliability diagram?
The points lie on the diagonal .