Skip to content

Scoring probabilities: log loss and Brier

A prediction is more than a yes or no. Proper scoring rules reward honest probabilities, and punish confident mistakes. Learn what each one measures.

Applied ~11 min9 steps

What runs in CodeSplash

You will be able to

  • Compute log loss and the Brier score for a row
  • Explain what makes a scoring rule proper
  • Read the Brier decomposition into reliability, resolution and uncertainty

Read first

01

The price of being wrong

Read

Brier score: mean squared difference between probability and outcome. Log loss: mean of the negative log of the probability you gave to what happened.

Brier=1n∑i(pi−yi)2LogLoss=−1n∑i[yiln⁡pi+(1−yi)ln⁡(1−pi)]\text{Brier} = \frac{1}{n}\sum_i (p_i - y_i)^2 \qquad \text{LogLoss} = -\frac{1}{n}\sum_i \big[y_i \ln p_i + (1-y_i)\ln(1-p_i)\big]

Both are lower when better. Unlike accuracy, they see the difference between 51% and 99%.

02

Confident and wrong

Predict

Predict first

The event happens. Model A gave it 40%, and model B gave it 1%. How much larger is B's log-loss penalty than A's on this row?

About doubleAbout five timesAbout fifty times
Reveal

About five times: −ln⁡0.01≈4.6-\ln 0.01 \approx 4.6 against −ln⁡0.4≈0.92-\ln 0.4 \approx 0.92. And there's no ceiling: at 0.1% it's about 6.96.9. This is why a single tree, whose leaves can say exactly 0 or 1, does so badly on log loss. On penguins it gets 0.429, and LDA gets 0.0242.

03

Proper means honesty pays

Read

A scoring rule is properProper scoring ruleA score whose expected value is best when you report your true probability. Log loss and Brier are proper. if your expected score is best when you report what you actually believe. Log loss and Brier are proper.

Accuracy isn't: it only sees which side of 50% you're on, so there's no reward for honest probabilities. If the probabilities will drive decisions, rank your models by a proper score, not by accuracy.

04

See the score move

Explore

Raise Overconfidence to make the model too extreme, then lower it to hedge. Read Brier, ECE and Calibration slope. Now look at AUC. Does it move?

HExplorable · Calibration and reliability

When a model says 80%, does the event happen 80% of the time?

If you make the model more overconfident, what happens to its AUC?

How sure?
2.00

Above 1 the model is too extreme; below 1 it hedges. At 1 it is perfectly calibrated.

2000
10
BrierECECalibration slopeAUC
0.1750.0870.500.835

Commit your prediction above to see the result

Make your prediction first; the figure appears when you commit.

Make your prediction to see the result.

Stretching probabilities doesn't change their order, so AUC stays still while the proper scores punish the distortion.

05

Three parts of a Brier score

Read

The app's Calibration table on a binary run splits the Brier score:

Brier=Reliability−Resolution+Uncertainty\text{Brier} = \text{Reliability} - \text{Resolution} + \text{Uncertainty}
  • Reliability: how far probabilities are from observed shares. Lower is better.
  • Resolution: how much predictions separate rows. Higher is better.
  • Uncertainty: set by the base rate alone.

For a logistic-style score on Pima, the Brier score is 0.144, and 1−Brier/Brierno-skill1 - \text{Brier} / \text{Brier}_\text{no-skill} gives 0.350: a skill score, like R2R^2.

06

Which one?

Reflect

Log loss is much harsher on confident mistakes, so it fits when you truly can't afford them, or as the training loss. It's the automatic primary metric for multiclass tasks.

Brier is bounded and easier to explain, and it's more forgiving of a stray extreme.

A model can win on one and lose on the other, usually because of a few confident misses. If that happened to you, whose decision would those rows change?

07

Check your understanding

Checkpoint

Check yourself

A model gives 70% to an event that happens. What is the Brier penalty on this row?

Show the answer

Answer: 0.09

(0.7−1)2=0.09(0.7 - 1)^2 = 0.09.

Check yourself

With a 50% base rate, what Brier score does the constant prediction 50% get?

Show the answer

Answer: 0.25

(0.5−y)2=0.25(0.5 - y)^2 = 0.25 for every row. A useful probabilistic model must beat that. In general the no-skill value is p(1−p)p(1-p).

Check yourself

Why prefer a proper score over accuracy for choosing between probability models?

Show the answer

Answer: b

Accuracy treats 51% and 99% the same. Proper scores reward getting the probability itself right.

08

On your run

In the app

Pick Log loss or Brier score (binary) as the Primary metric in Setup to rank by probability quality. Overview reports both on any binary run, and Evaluation has the Calibration table.

Python
import numpy as np

y = np.array([1, 0, 1, 1, 0])
for name, p in [("hedged", np.array([0.7, 0.3, 0.6, 0.8, 0.4])),
                ("overconfident", np.array([0.99, 0.01, 0.99, 0.99, 0.99]))]:
    brier = np.mean((p - y) ** 2)
    logloss = -np.mean(y * np.log(p) + (1 - y) * np.log(1 - p))
    print(name, round(brier, 3), round(logloss, 3))
R
y <- c(1, 0, 1, 1, 0)
score <- function(p) c(brier = mean((p - y)^2), logloss = -mean(y * log(p) + (1 - y) * log(1 - p)))
round(rbind(hedged = score(c(0.7, 0.3, 0.6, 0.8, 0.4)),
            overconfident = score(c(0.99, 0.01, 0.99, 0.99, 0.99))), 3)
09

Recap

Recap
  • Log loss and Brier score the probability, not only the side of 50%.
  • Proper scores reward honesty, and log loss punishes confident mistakes hardest.
  • Brier splits into reliability, resolution and uncertainty, and a proper score can move while AUC doesn't.

Concepts in this lesson