All writing

5 min read

Calibration over accuracy: when your output is a threshold

When a risk score fires alerts at 60 and 80, a calibrated probability matters more than raw discrimination. What an ECE of 0.0093 buys you.

The alert thresholds in Bhoomi Drishti sit at risk scores of 60 and 80. That one design decision is why I report Expected Calibration Error 0.0093 and a Brier score of 0.0681 ahead of ROC AUC 0.8254. As soon as a number crosses a line and becomes a warning on somebody's screen, the number has to mean what it says. Getting the order right is not enough.

What a threshold demands from a probability

Discrimination and calibration are separate properties. Discrimination asks whether risky region-hours score above safe ones, which is what ROC AUC measures and all it measures. Calibration asks whether a score of 0.30 matches a real-world frequency near 30 percent. The transformation that separates them is trivial: square every probability in a perfectly ranked set. The ordering is untouched, so AUC does not move a decimal, but every probability is now too low and the thresholds have shifted without anyone editing a threshold.

That is the failure mode a warning system has to avoid. A miscalibrated model that ranks correctly still tells you which places are riskiest, which feels like enough until you have to decide who gets woken at two in the morning. If a model score of 80 corresponds to a true probability of 30 percent, the HIGH tier fires on ordinary wet days and people learn to swipe it away. If it corresponds to 95 percent, the system stays quiet through conditions that deserved a warning. Neither case is a ranking error, and neither shows up in the AUC.

What ECE measures, in plain terms

Expected Calibration Error is an average of broken promises. Sort every prediction into bins by predicted probability, ten bins of width 0.1. Inside each bin, compare the mean prediction against the observed positive rate and take the absolute difference. Weight each bin by how many predictions it holds and add them up. An ECE of 0.0093 says the predicted probability sits about nine tenths of a percentage point from the frequency actually observed at that confidence level.

import numpy as np

def expected_calibration_error(y, p, bins=10):
    """Volume-weighted mean gap between promised and observed rates."""
    edges = np.linspace(0.0, 1.0, bins + 1)
    which = np.clip(np.digitize(p, edges[1:-1]), 0, bins - 1)

    ece = 0.0
    for b in range(bins):
        m = which == b
        if not m.any():
            continue
        gap = abs(p[m].mean() - y[m].mean())   # promise minus outcome
        ece += m.mean() * gap                  # weight by share of rows
    return ece

def brier(y, p):
    return float(np.mean((p - y) ** 2))        # no bins needed

Two caveats travel with it. ECE depends on the binning, and a low value can hide errors that cancel inside a wide bin. So I read the reliability curve too, which is the same computation without the final sum, and the Brier score, which needs no bins.

Why PR AUC is the more honest headline

Brier score is the mean squared error of a probability, 0.0681 on the grouped test set. Its useful property is that it is a proper scoring rule, minimised only by the true probability, so it rewards sharpness and calibration together and cannot be gamed by confident guessing. Its dull failure mode shows up on rare events: at an 11.08 percent positive rate, predicting 0.1108 for every row scores about 0.0985 while knowing nothing. Brier needs the base rate quoted beside it.

That same 11.08 percent is why I lead with PR AUC 0.5245 rather than ROC AUC 0.8254. ROC AUC plots true positive rate against false positive rate, and the false positive rate carries the entire negative class in its denominator, 21,340 rows against 2,660 positives. A few hundred false alarms barely register against a denominator that size. Precision-recall swaps in precision, whose denominator is the alerts you actually raised, so it moves with the quantity an operator would complain about. The baselines settle it: an uninformative model scores 0.5 on ROC AUC whatever the data, but only 0.1108 on PR AUC here. So 0.5245 is about 4.7 times its baseline while 0.8254 is 1.65 times its own.

MetricValueWhat it is good for
ROC AUC0.8254Ranking quality. Ignores imbalance, blind to miscalibration.
PR AUC0.5245Alert precision when positives are rare. Baseline 0.1108, not 0.5.
Brier0.0681Calibration and sharpness in one proper score. Quote the base rate with it.
ECE0.0093Whether a stated probability matches observed frequency. What a threshold stands on.

Calibration does not arrive by accident, and the levers differ from the ones that move AUC.

  • Train against log loss, so the objective cares about the value of the probability and not just which side of the boundary it landed on.
  • Early-stop on validation log loss. Extra boosting rounds keep sharpening confident predictions after the ranking has stopped improving, and calibration degrades first.
  • Check calibration inside the region groups, not only overall. A model can be calibrated on average and wrong in the wettest districts, which are the ones the thresholds exist for.

What it looks like in the product

The scenario smoke test makes calibration visible without plotting anything. Dry conditions score 1.9 and read VERY LOW. A normal monsoon day scores 30.4 and reads LOW. Heavy rain scores 79.2 and reads HIGH. Extreme rain scores 86.1 and reads CRITICAL. That spread checks the two lines: routine monsoon rain in India is not an emergency and must not be treated as one, and the distance between 30.4 and 79.2 is what keeps the HIGH tier worth reading.

If a human reads your ranked list, optimise discrimination. If an if statement reads your number, optimise calibration.

The same discipline runs through the interface. Every data surface carries a badge, LIVE DATA, DEMO DATA, SIMULATED DATA or MIXED DATA, so a demo figure is never dressed up as a measurement. The image-screening feature states in the UI that it is not a trained network, and the terrain basemap states that it is not a satellite pass. No random numbers appear anywhere in the prediction path either, by rule, so the same inputs give the same score every run. A threshold on a score that wobbles is not a rule, it is a mood.

So the rule I work to now: report calibration error next to the AUC whenever the output feeds a threshold, and quote the base rate next to any score a constant predictor could fake. My lines are at 60 and 80, they sit in the alert logic, and ECE 0.0093 is what lets me defend them.