-
Notifications
You must be signed in to change notification settings - Fork 132
expected calibration error explained
Expected calibration error is the average gap between what a model's probabilities claim and how often they come true, computed over bins and weighted by how many answers fall in each bin. Sort the answers into bins by probability, take the absolute difference between each bin's mean prediction and its observed frequency, and average those differences weighted by bin size. Zero means the numbers match the frequencies; 0.05 means that, on average, the claim is off by about five percentage points.
It is the most reported calibration number and one of the easiest to over-read. It depends on the number of bins, it can hide errors that cancel inside a bin, and it describes one mix of data. A low ECE is necessary for trusting probabilities, not sufficient.
This page is the definition, a worked example with made-up numbers, the two conventions you will meet for yes/no models, a short piece of code, and the limits.
Guo and colleagues (2017) give the form most papers use. Split the n predictions into M bins B_1 to B_M by predicted confidence. For each bin, compute acc(B_m), the fraction of answers in the bin that were right, and conf(B_m), the mean predicted confidence. Then:
ECE = sum over m of (|B_m| / n) times |acc(B_m) - conf(B_m)|
The related maximum calibration error (MCE) is the largest of those per-bin gaps instead of the
weighted average. Guo and colleagues used M = 15 bins in their experiments; scikit-learn's
calibration_curve defaults to 5.
For a model that returns P(yes), you can bin in two ways, and they give different numbers:
- On P(yes) against the fraction of yes. Bins run from 0 to 1 on P(yes), and each bin's mean P(yes) is compared with the share of its cases whose true answer is yes. This is what a reliability diagram of a binary classifier in scikit-learn plots.
- On confidence against accuracy. Confidence is max(P(yes), 1 - P(yes)), the probability of the answer the model would give; bins run from 0.5 to 1; each bin's mean confidence is compared with how often that answer was right. This is the multiclass form applied to two classes.
Neither is wrong. When you compare an ECE you computed with one someone else published, check the convention and the number of bins before comparing the values.
The table below is made up to show the arithmetic. It is not a measurement of jevos or of any model. Imagine 200 labelled answers binned on P(yes) into 5 equal bins:
| Bin of P(yes) | Answers | Mean P(yes) | Fraction really yes | Gap |
|---|---|---|---|---|
| 0.0 to 0.2 | 60 | 0.08 | 0.05 (3 of 60) | 0.03 |
| 0.2 to 0.4 | 30 | 0.30 | 0.20 (6 of 30) | 0.10 |
| 0.4 to 0.6 | 20 | 0.50 | 0.45 (9 of 20) | 0.05 |
| 0.6 to 0.8 | 30 | 0.70 | 0.60 (18 of 30) | 0.10 |
| 0.8 to 1.0 | 60 | 0.92 | 0.95 (57 of 60) | 0.03 |
Weighted sum: (60 times 0.03 + 30 times 0.10 + 20 times 0.05 + 30 times 0.10 + 60 times 0.03) / 200 = 10.6 / 200 = 0.053. The MCE is 0.10.
Reading it: this illustrative model is fine at the extremes and too eager in the middle, where its 0.3s and 0.7s both overstate yes by ten points. The ECE of 0.053 says "something is off"; only the per-bin table says where. On a reliability diagram those two middle bins would sit below the diagonal.
With the probabilities from your labelled requests in p and the true answers (1 for yes) in
y:
import numpy as np
def ece(p, y, bins=10):
p, y = np.asarray(p), np.asarray(y)
idx = np.minimum((p * bins).astype(int), bins - 1)
total = 0.0
for b in range(bins):
m = idx == b
if m.any():
total += m.mean() * abs(p[m].mean() - y[m].mean())
return totalThis is the first convention above, with equal-width bins. Print the per-bin counts too: a bin of four answers contributes noise, not evidence.
- It depends on the bins. Nixon and colleagues (2019) show that conclusions, including the ranking of recalibration methods, change with the calibration measure and the number of bins, and that adaptive bins with equal counts are more stable than fixed ones.
- Errors can cancel inside a bin. If half a bin is overconfident and half underconfident, the bin's mean looks perfect.
- It says nothing about accuracy. A model that answers 0.5 to everything on a half-yes set has an ECE of zero.
-
It describes one mix of data. On the natural yes/no questions of our held-out split,
jevos-q8_0had an ECE of 0.009. On 999 new questions, the mean P(yes) given to arithmetic questions whose answer was no was 0.59. Both are true; the first does not predict the second. Compute ECE per kind of question, as on accuracy by kind of question. - Small samples inflate or deflate it. With 200 answers and 15 bins, several bins hold a handful of cases. Use fewer bins, or equal-count bins, when data is scarce.
What is a good ECE? It depends on the data and the binning, but values of a few hundredths mean the probabilities are close to the frequencies on that data. Always look at the per-bin table too.
How many bins should I use? With a few hundred answers, 5 to 10. Guo and colleagues used 15 on much larger sets.
Is ECE the same as the Brier score? No. The Brier score is the mean squared difference between P(yes) and the 0/1 answer, so it scores the whole probability, not calibration alone: a model that always says 0.5 has an ECE of zero on half-yes data but a Brier score of 0.25.
Does a low ECE mean the model is accurate? No. A model that always says 0.5 on balanced data has an ECE of zero.
What ECE does jevos have? 0.009 on 6,397 natural yes/no held-out questions and 0.018 on the dev split. On new kinds of question it leans toward yes, which those numbers do not show.
See also: LLM calibration explained, temperature scaling for LLM probabilities and evaluation metrics for yes/no classifiers.
- Our measurements: ECE 0.009 (held-out, 6,397 natural yes/no questions) and 0.018 (dev),
jevos-q8_0; mean P(yes) 0.59 on no-answer arithmetic questions, 999-question set,jevos-q4_k_m. - The worked example table is illustrative and invented for this page.
- Guo, Pleiss, Sun, Weinberger (2017), On Calibration of Modern Neural Networks: ECE and MCE definitions, M = 15, fetched 2026-09-29.
- Nixon et al. (2019), Measuring Calibration in Deep Learning, fetched 2026-09-29.
- scikit-learn calibration_curve, default of 5 bins, and brier_score_loss, fetched 2026-09-29.
From the notes of jev, where the same model has an ECE of 0.009 on one test set and a clear yes-lean on another.
- Ask a local LLM a yes/no question and get P(yes)
- Zero-shot text classification with yes/no questions
- LLM policy decisions: put the rule in the question
- LLM as a judge on a CPU
- Why a small LLM says yes when the answer is no
- Small LLMs and arithmetic in yes/no questions
- Our held-out benchmark said 0.855, new questions said 0.757
- jevos vs Jev vs Laya for yes/no decisions
- An open-source alternative to Jev for yes/no decisions
- jevos vs the OpenAI API for yes/no classification
- jevos vs Ollama for yes/no decisions
- jevos vs bart-large-mnli for zero-shot classification
- A yes/no LLM vs a fine-tuned BERT classifier
- jevos vs SetFit: zero-shot vs few-shot classification
- jevos vs Llama Guard for content safety checks
- jev serve vs llama.cpp server for classification
- jevos vs LM Studio: a decision server, not a chat app
- Local vs hosted LLM decisions: latency, cost, privacy
- A yes/no LLM vs a business rules engine
- LLM decisions vs keyword rules and regex
- The fastest AI model for yes/no decisions
- What makes a local LLM fast on a CPU
- Why one forward pass beats generating an answer
- Prefill vs decode: where LLM latency comes from
- Why LLM latency grows with the length of the text
- Why a hosted LLM API cannot answer in 50 ms
- Many questions about one text: why the extra ones are cheap
- CPU or GPU for a small LLM
- Latency budgets: where a 200 ms model fits
- Measuring LLM latency: median, p90 and warm-up
- Q4_K_M vs Q8_0: speed and size for a small model
- Throughput vs latency for a decision server
- What P(yes) means, and what it does not
- LLM calibration explained with yes/no answers
- Expected calibration error (ECE), explained
- Temperature scaling for LLM probabilities
- Platt scaling for a yes/no model
- Reading a reliability diagram
- How to choose a threshold for P(yes)
- Thresholds when a wrong yes costs more than a wrong no
- Human in the loop AI with a review band
- Precision and recall at a P(yes) threshold
- Base rates: why a 0.9 yes can still be wrong often
- Combining yes/no answers with AND, OR and NOT
- Logits, log-odds and P(yes)
- LLM confidence scores: probabilities vs self-reports
- How to write yes/no questions an LLM answers well
- Negation in yes/no questions for an LLM
- One condition per question: splitting compound questions
- Ask whether the text says it at all
- Scores as yes/no thresholds: is it at least high?
- Sending JSON as the text: designing the state
- Why wording changes an LLM's answer, and how to test it
- Mainly about: questions for messages with several topics
- Yes/no questions about tone and emotion
- Asking about intent: what does the writer want?
- Yes/no questions about long documents
- Using an English-only LLM with other languages
- Content moderation with a local LLM
- A Discord moderation bot with a local LLM
- Spam detection with yes/no questions
- Review moderation with a local LLM
- Email triage with a local LLM
- Support ticket routing with yes/no questions
- Urgency detection in customer messages
- Sentiment analysis with yes/no questions
- Intent detection with a local LLM
- Lead qualification with yes/no questions
- Fraud case triage with a local LLM
- Phishing email screening with a local LLM
- Log and alert triage with a local LLM
- Checking text for personal data with yes/no questions
- Prompt injection screening with a small model
- Document classification with a local LLM
- Product categorization with yes/no questions
- Contract clause detection with a local LLM
- Refund request triage with a local LLM
- Detecting cancellation intent in customer messages
- RAG evaluation with yes/no questions
- RAG faithfulness check with a local LLM
- Hallucination detection with a local LLM
- LLM regression tests in CI with yes/no checks
- Rubric design for an LLM judge
- Pairwise comparison with a yes/no judge
- LLM judge bias and how to control it
- Evaluation metrics for yes/no classifiers
- Building a yes/no test set for your own data
- Accuracy by kind of question: why one number hides failures
- Generating test questions with answers computed by code
- Benchmark contamination and truly held-out tests
- An LLM router with yes/no questions
- A model cascade: small model first, large model on doubt
- Semantic routing vs yes/no questions
- Gating AI agent tool calls with yes/no checks
- AI agent guardrails with yes/no questions
- Stop conditions for AI agents
- Logging LLM decisions for audit
- Reducing LLM cost with local yes/no decisions
- Replacing chat LLM calls with yes/no questions
- Structured output vs a probability
- A Python client for local LLM decisions
- Calling a local LLM decision server from JavaScript
- Local LLM yes/no decisions in n8n
- A Slack bot that uses local LLM decisions
- Home Assistant automations with local LLM decisions
- A LangChain tool for local yes/no decisions
- Batch decisions from files with jev decide
- Running LLM yes/no checks in GitHub Actions
- Securing a local LLM server with an API key
- curl examples for a local LLM decision API
- Self-hosted AI for decisions
- A private LLM for text classification
- On-premise LLM for business decisions
- GDPR and automated decision-making with an LLM
- Offline AI for decisions: no network needed
- Edge AI decisions on a CPU
- Run an LLM locally without a GPU
- Small language models explained
- When a small model is enough, and when it is not
- An LLM on a laptop: what it can do in real time
- What is GGUF, for someone deploying a classifier
- GGUF quantization types explained: Q4_K_M, Q8_0 and others
- GGUF vs safetensors
- llama.cpp vs Ollama for a classification service
- llama-cpp-python vs calling llama.cpp through ctypes
- llama.cpp on Windows without compiling
- Running llama.cpp CPU only
- Using llama.cpp prebuilt binaries instead of building