Skip to content
svginterval-coverage

Interval coverage

Do prediction intervals contain the truth as often as they promise?

Demo data · seed 20261101 · 18 rows · default settings · 640 × 360SVG, lightSVG, darkDemo CSV

How to read it

  1. Read x as the promised coverage, y as what was achieved.
  2. On the diagonal: honest intervals.
  3. Below the diagonal: intervals are too narrow.
  1. Callout 1: On the diagonal: honest intervals.
  2. Callout 2: Below the diagonal: overconfident.
  3. Callout 3: The perfect-calibration line.

Watch out

  • Overall coverage can hide subgroups that are badly covered.

Defaults

No settings: the chart draws one way.

Pinned in the code

  • Draws the run's numbers as given (computed by the Python/R engine); the chart computes nothing statistical.
  • Points below the diagonal under-cover (intervals too narrow); split-conformal intervals guarantee at least nominal coverage on exchangeable data. Compare widths only between methods with adequate coverage.
# Interval coverage — Codesplash Chart Lab (recipe "interval-coverage")
# controls: defaults
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

try:
    import codesplash as cs  # optional: the app's chart theme
except ImportError:
    cs = None
if cs:
    cs.use_codesplash(dark=False)
PALETTE = cs.palette(dark=False)["categorical"] if cs else plt.rcParams["axes.prop_cycle"].by_key()["color"]
# non-colour encodings per series (same table as the app: series are never told apart by colour alone)
SERIES_DASHES = ["-", (0, (6, 3)), (0, (1.5, 2.5)), (0, (8, 3, 2, 3)), (0, (12, 4)), (0, (3, 3)), (0, (8, 2, 2, 2, 2, 2)), (0, (1.5, 5))]
SERIES_MARKERS = ["o", "s", "^", "D", "P", "*", "2", "v"]

df = pd.read_csv("interval-coverage-demo.csv", keep_default_na=False, na_values=[""])  # demo data (only empty cells are missing): Chart Lab → Code → Download demo CSV
df["method"] = pd.Categorical(df["method"].astype("string"), categories=["Split conformal", "CQR", "Gaussian (model SD)"])

def levels_of(s):
    """Declared level order (categoricals), else order of first appearance."""
    if isinstance(s.dtype, pd.CategoricalDtype):
        return [v for v in s.cat.categories if (s == v).any()]
    return list(dict.fromkeys(s.dropna().astype(str)))
N = "nominal coverage"
C = "empirical coverage"
W = "mean width ($100k)"
M = "method"
groups = levels_of(df[M]) if M else [None]
series = []
for name in groups:
    d = df if name is None else df[df[M].astype(str) == str(name)]
    series.append((name if name is not None else "", d.dropna(subset=[N]).sort_values(N)))
fig, ax = plt.subplots(figsize=(6, 5))
lo = max(0, min(df[N].min(), df[C].min()) - 0.05)
ax.plot([lo, 1], [lo, 1], color="grey", linestyle="--", linewidth=1, label="perfect calibration")
for i, (name, d) in enumerate(series):
    ax.plot(d[N], d[C], marker=SERIES_MARKERS[i % 8], linestyle=SERIES_DASHES[i % 8], ms=5, color=PALETTE[i % len(PALETTE)], linewidth=1.8, label=name or C)  # dash + marker per method, as in the app
ax.set_xlim(lo, 1)
ax.set_ylim(lo, 1)
ax.set_xlabel(N)
ax.set_ylabel(C)
ax.legend(fontsize=8)
plt.show()

Needs pandas, numpy, matplotlib · reads interval-coverage-demo.csv · app theme from the optional codesplash helper