When a model says "70% chance of rain", we need two questions answered: was that number a good bet? (log-loss) and does 70% actually mean 70%? (calibration). Everything on this page is the vocabulary needed to turn those two plain-English questions into arithmetic you can compute.
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 .
A probability is a number between 0 and 1 that measures how strongly we believe something will happen. 0 means "certain it won't", 1 means "certain it will", 0.5 means "no idea, coin-flip".
Picture a horizontal bar from left (0 ) to right (1 ). Sliding a marker along it is exactly "changing your confidence".
We write a probability with the letter p . When it is a probability the model predicts (a guess, not a truth), we put a little hat on it: p ^ — read aloud as "p-hat". The hat always means "estimated / predicted by us", never "the real answer".
Intuition Why the topic needs
p ^
Log-loss and calibration are both about grading these predicted numbers p ^ . Without a symbol for "the model's guessed probability", we couldn't even state the questions.
Before we use them, let us pin down two bracket conventions you will meet everywhere.
Definition Square brackets vs curly braces
[ 0 , 1 ] (square brackets ) means "all the real numbers from 0 to 1, including the two ends". It is a continuous range — a whole ruler of values like 0.03 , 0.7 , 0.999 .
{ 0 , 1 } (curly braces ) means "only the two listed values, nothing in between". It is a discrete set — a short list.
A round bracket like ( 0 , 1 ) means the range from 0 to 1 but excluding the ends themselves.
So p ^ ∈ [ 0 , 1 ] says "a guess can be any value on the ruler", while y ∈ { 0 , 1 } says "the truth is only ever one of two labels". The symbol ∈ reads "is an element of / lives in".
Reality is not a probability — it either happened or it did not. We record that with y .
y
y is the true outcome , and in the simplest (binary) case it is only ever 0 or 1 .
y = 1 means "the event happened / this is class 1" (rain fell).
y = 0 means "it did not happen / class 0" (stayed dry).
We write y ∈ { 0 , 1 } using the set notation from Section 2: "y is one of these two values".
Contrast the two symbols so they never blur (both bracket conventions were defined above):
Symbol
Lives where
Meaning
Example
p ^
anywhere in [ 0 , 1 ]
model's guess
0.7
y
only { 0 , 1 }
reality's verdict
1
The whole game is comparing a soft guess p ^ against a hard truth y .
p ^ with y
p ^ = 0.7 is not a wrong answer when y = 1 . The truth is 1, and 0.7 was a reasonably confident bet toward 1. Log-loss will give it a small penalty, not a zero-or-one "wrong". Keep "guess" and "verdict" in separate mental boxes.
This is the tool the topic is named after , so we build it carefully.
− ∞
− ∞ is read "negative infinity ". It is not an ordinary number; it is shorthand for "grows without bound in the negative direction — more negative than any number you can name". When we say a curve "goes to − ∞ " we mean it keeps plunging downward forever, never bottoming out.
log ( x ) answers the question: "what power do I raise the base to, to get x ?" If we work in base e ≈ 2.718 (the "natural log", the default in machine learning), then log ( x ) = z means e z = x .
Intuition Does the choice of base matter?
No, only cosmetically. Switching from base e to base 2 (bits) or base 10 multiplies every log by the same fixed constant, so it rescales the whole loss by that constant and never changes which model wins. Machine learning defaults to natural log (base e ) because it plays nicely with calculus; Information Theory often prefers base 2 so the answer comes out in bits.
The only facts we actually need are visual:
Read three things off the curve of log ( x ) for x between 0 and 1:
log ( 1 ) = 0 . A perfect prediction earns zero penalty.
As x shrinks toward 0 , log ( x ) dives to − ∞ (negative infinity, just defined). A tiny probability produces a huge negative number.
log ( x ) is negative for every x in ( 0 , 1 ) . That is why the loss formulas always have a minus sign out front — to flip the penalty back to positive.
Intuition Why a logarithm and not just
1 − p ^ ?
We want the penalty for being confidently wrong to blow up dramatically, not gently. Saying "p ^ = 0.01 but y = 1 " should feel catastrophic. Because log dives to − ∞ near zero, − log ( 0.01 ) ≈ 4.6 is far bigger than − log ( 0.5 ) ≈ 0.69 . A plain difference like 1 − p ^ would only ever reach 1 — too forgiving of disasters.
Second reason: probabilities of independent events multiply , and log turns multiplication into addition. That converts an ugly product over a whole dataset into a friendly sum.
We will lean on two algebraic properties of logs, so let us name them explicitly.
The parent writes the Bernoulli likelihood p ^ y ( 1 − p ^ ) 1 − y . The trick is that y (which is 0 or 1) acts as an on/off switch in the exponent.
Intuition Exponent as a light-switch
Anything raised to the power 0 equals 1 (a "do-nothing" factor). Anything raised to the power 1 is itself.
If y = 1 : the expression becomes p ^ 1 ( 1 − p ^ ) 0 = p ^ ⋅ 1 = p ^ .
If y = 0 : it becomes p ^ 0 ( 1 − p ^ ) 1 = 1 ⋅ ( 1 − p ^ ) = 1 − p ^ .
So one formula silently picks the right branch. This is why the topic can write a single clean line instead of an if/else.
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.
We rarely grade one prediction; we grade a whole dataset of N of them.
Definition The summation sign
∑
∑ i = 1 N a i is shorthand for "add up a 1 + a 2 + ⋯ + a N ". The little i = 1 underneath says start counting at 1, the N on top says stop at N , and a i is the thing being added for each i .
The subscript i is just a name tag on each sample: y i is the truth of sample number i , p ^ i its predicted probability. Multiplying the whole sum by N 1 turns a total into an average — so datasets of different sizes stay comparable.
Common mistake The formula quietly assumes
p ^ ∈ ( 0 , 1 )
If a model outputs exactly p ^ = 0 or p ^ = 1 , then a wrong prediction hits log ( 0 ) = − ∞ (Section 4) and the loss becomes infinite — a single such sample would blow up the whole average. In practice we clip predictions into a safe range like [ ε , 1 − ε ] with a tiny ε (e.g. 1 0 − 7 ), or add smoothing, so the log is always taken of a strictly positive number. Treat the clean formula as valid on the open interval ( 0 , 1 ) .
With more than two classes we need a second name tag. The class index is k , running from 1 to K (the number of classes).
Definition One-hot vector
Instead of a single y ∈ { 0 , 1 } , the truth is a list y = [ y 1 , … , y K ] where the true class slot holds 1 and every other slot holds 0 . "One-hot" = exactly one entry is "hot" (=1). The predicted list p ^ = [ p ^ 1 , … , p ^ K ] holds one guessed probability per class, and they must sum to 1 : ∑ k p ^ k = 1 .
The bold letters y , p ^ signal "this is a whole list (vector)", not a single number.
Calibration needs us to group predictions with similar confidence and check reality inside each group.
B m
Chop the confidence axis [ 0 , 1 ] into M equal slices. Bin B m is the set of all predictions whose p ^ falls in slice number m . ∣ B m ∣ (vertical bars) means "how many predictions are in that bin" — the size of the set.
Inside a bin we compute two averages:
conf ( B m ) = average of the model's guesses p ^ i in the bin (what it claimed ).
acc ( B m ) = average of the truths y i in the bin, i.e. the fraction that actually happened (what reality delivered).
Common mistake Empty bins (
∣ B m ∣ = 0 )
If no prediction lands in a slice, then ∣ B m ∣ = 0 and both averages would be 0 1 — undefined. The convention is simple: skip empty bins entirely. In the ECE sum below such a bin contributes weight N ∣ B m ∣ = N 0 = 0 , so dropping it changes nothing, but computing conf /acc on an empty set must be avoided (never divide by zero). Only bins that actually contain predictions enter the sum.
Intuition Why compare these two numbers?
Perfect calibration means: among all "70% confident" predictions, exactly 70% come true. So we want conf ( B m ) (claim) to equal acc ( B m ) (reality) in every bin. The gap ∣ acc − conf ∣ is the lie in that bin.
The Expected Calibration Error rolls all (non-empty) bins into one number, weighting each by its share N ∣ B m ∣ so a tiny bin can't dominate:
Plotting conf on the x-axis and acc on the y-axis gives a reliability diagram ; the perfect diagonal is y = x . 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.
Bernoulli switch p^y times 1-p to the 1-y
Logarithm log x plus its rules
Class index k and one-hot vectors
Multi-class cross-entropy
Bins B_m accuracy and confidence
Expected Calibration Error
Cover the right side and test yourself. If any line is fuzzy, re-read its section above.
Difference between [ 0 , 1 ] , ( 0 , 1 ) and { 0 , 1 } ? [ 0 , 1 ] = all reals 0 to 1 incl. ends; ( 0 , 1 ) = same but excluding ends; { 0 , 1 } = only the two values 0 and 1.
What does the hat in p ^ mean? The number is the model's predicted/estimated probability, not the true answer.
What two values can a binary label y take, and what do they mean? 0 = event did not happen, 1 = event happened.
What does − ∞ mean? Negative infinity — plunges more negative than any nameable number, never bottoming out.
What question does log ( x ) answer? "What power must I raise the base e to, in order to get x ?"
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 log ( 1 ) , and why does that matter for log-loss? It is 0 , so a perfect prediction earns zero penalty.
State the product and power rules for logs. log ( ab ) = log a + log b ; log ( a b ) = b log a .
Why does log-loss have a minus sign out front? log ( x ) is negative for x in ( 0 , 1 ) ; the minus flips the penalty back to positive.
In p ^ y ( 1 − p ^ ) 1 − y , what happens when y = 0 ? It collapses to 1 − p ^ , because p ^ 0 = 1 .
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 p ^ is exactly 0 or 1, and the fix? A wrong prediction gives log 0 = − ∞ = infinite loss; clip p ^ into [ ε , 1 − ε ] .
What does ∑ i = 1 N a i mean? Add up a 1 through a N .
What does multiplying a sum by N 1 do? Turns a total into an average, comparable across dataset sizes.
How does multi-class log-loss extend the binary average? Same N 1 over samples, plus an inner sum over the K classes.
What is a one-hot vector? A list with 1 in the true-class slot and 0 everywhere else.
What is a bin B m in calibration? The set of all predictions whose confidence falls in slice m of [ 0 , 1 ] .
How do you handle an empty bin in ECE? Skip it — it carries weight 0/ N = 0 and its averages would divide by zero.
What is conf ( B m ) vs acc ( B m ) ? 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 y = x .