WRITE · TRACE · UNDERSTAND

Measure probability error instead of only decisions

Implement brier(labels,probabilities), validating equal nonempty sequences, binary integer labels and finite probabilities in [0,1].

Read lesson: Measure probability error instead of only decisions →

Your experiment

Implement brier(labels,probabilities), validating equal nonempty sequences, binary integer labels and finite probabilities in [0,1]. Return mean squared probability error.

Python runs in your browser. Your draft stays on this device.

What to look for

A proper scoring rule rewards truthful probabilities in expectation, but finite test scores still have uncertainty. Use held-out calibration data and avoid choosing a calibrator on the final test set.

Watch your code work

Ready to experiment

Write a solution or load the worked answer, then choose Trace & check.

Step through arrays, variables and training curves produced by your own Python.

About this algorithm

How Measure probability error instead of only decisions works

The idea

Accuracy only asks whether a prediction landed on the right side of a threshold. The Brier score asks how good the probability itself was: it is the mean of (p - y) ** 2 over all rows, where p is the predicted probability of class 1 and y is the 0 or 1 outcome.

Perfect probabilities score 0, a constant guess of 0.5 scores 0.25, and being certain and wrong on every row scores 1. Squaring the error makes this a proper scoring rule: the expected score is best when the stated probability equals the true frequency, so neither hedging nor exaggerating can improve it on average.

How it works

  1. Reject empty or unequal lists, labels that are not integer 0 or 1, and probabilities that are not finite or fall outside 0 to 1.
  2. Pair each label with its probability using zip.
  3. Compute the squared error (p - y) ** 2 for every pair.
  4. Add the squared errors into total_error.
  5. Divide by the number of rows and return the mean.

What it costs

Time
O(n)
Space
O(n)

One pass computes a squared error per row; the worked answer keeps them in a list, though a running sum would need constant memory.

Where it is used

  • Glenn Brier introduced the score in 1950 to verify weather forecasts stated as probabilities.
  • scikit-learn provides it as brier_score_loss.
  • The Good Judgment Project scored its geopolitical forecasters with Brier scores in the IARPA ACE tournament.

Watch out for

  • Passing hard 0 or 1 predictions instead of probabilities, which turns the score into the plain error rate.
  • Using abs(p - y) instead of the square; absolute error is not a proper scoring rule and rewards pushing probabilities to 0 or 1.
  • Judging a score without a baseline: on rare events, always predicting the base rate already gives a low Brier score.