PythiloLesson 6 of 12 · progress kept in this browser

Practice in Lab: Estimate calibration with explicit bin semantics →

Estimate calibration with explicit bin semantics

A calibration diagram compares average confidence with observed frequency. Expected calibration error summarizes absolute gaps weighted by bin occupancy. The binning rule is part of the metric: changing the bin count can change the score without changing the model.

The final bin must include probability one. Empty bins contribute no weight and should not invent an observed frequency. ECE is a diagnostic, not a universal proper scoring rule; a small value on coarse bins can conceal substantial errors. Keep Brier score or log loss and examine subgroup reliability as well.

probabilities=[.1,.9,1.0]
print([min(int(p*2),1) for p in probabilities])
Your task

Implement ece(labels,probs,bins) using equal-width bins [i/bins,(i+1)/bins), with 1 in the last. Validate binary labels, finite [0,1] probabilities, equal nonempty lengths and positive integer bins.