Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA025 · Metric

Expected calibration error and reliability diagrams

Summarizes agreement between predicted confidence and observed correctness within bins.

Runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through diagnostic.calibration. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Summarizes agreement between predicted confidence and observed correctness within bins.

Question / hypotheses

When the model assigns a confidence level, how often is its prediction correct?

Architecture / computational structure

A fixed scoring/calibration pipeline applied to model outputs or supplied observations; the formula and usage sections identify its operations.

Assumptions

Use untouched labeled evaluation data and declare whether top-label, classwise, or another calibration notion is measured. Adequate counts are needed in each bin.

Formula / computational definition

ECE=∑b=1B∣Ib∣n∣acc⁡(Ib)−conf⁡(Ib)∣.ECE=\sum_{b=1}^B\frac{|I_b|}{n}\left|\operatorname{acc}(I_b)-\operatorname{conf}(I_b)\right|.

Parameters and notation

Bins, boundaries, weighting, and class treatment are hyperparameters. Temperature scaling fits a separate scalar on calibration data; the evaluation metric itself has no learned parameters.

Fitting, fine-tuning, and adaptation

There is no model fine-tuning step for this evaluation procedure. Freeze the evaluated systems and evaluator before the final test. Select evaluation settings on development data; if a learned evaluator or calibration model is adapted, use separate fitting data, version it, and reassess its validity.

How to use and calibrate

Plot reliability with bin counts and uncertainty, then report ECE with binning rules. Fit calibration transforms on a separate split and reassess discrimination as well as calibration.

Example application

Evaluate confidence after adapting a speech-command classifier to new microphones.

Interpretation / pitfalls

Watch out

ECE depends on binning and is not a proper scoring rule. Aggregate calibration can conceal subgroup errors; lower ECE can accompany worse useful predictions.

Python and R code examples

Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs numpy

import numpy as np
conf=np.array([.6,.7,.8,.9]); correct=np.array([0,1,1,1]); bins=[np.array([0,1]),np.array([2,3])]
print(sum(len(b)/len(conf)*abs(correct[b].mean()-conf[b].mean()) for b in bins))
R

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

conf <- c(.6,.7,.8,.9); correct <- c(0,1,1,1); bins <- list(1:2,3:4)
print(sum(vapply(bins,function(b) length(b)/length(conf)*abs(mean(correct[b])-mean(conf[b])),0.0)))

Sources

From the CodeSplash reference, entry EVA025.