Overview
Many strong forecasters (gradient boosting, most neural nets) output a single number. Conformal prediction turns them into interval forecasters: measure how wrong the model is on data it hasn’t seen (the calibration set), take a high quantile of those errors, and put that margin around new forecasts.
Under exchangeability the intervals have finite-sample coverage of at least \(1-\alpha\). Time series break exchangeability, so use a recent calibration window, recalibrate as you roll forward, or use adaptive methods such as ACI or EnbPI that adjust to drift.
How it works
Split conformal with absolute-error scores on a calibration set of size \(n\):
\[s_i=\lvert y_i-\hat f(x_i)\rvert,\qquad \hat q=s_{(\lceil (n+1)(1-\alpha)\rceil)}\] \[\hat C(x)=\big[\hat f(x)-\hat q,\;\hat f(x)+\hat q\big],\qquad \mathbb P\big(y\in\hat C(x)\big)\ge 1-\alpha\]Adaptive conformal inference updates the working level online: \(\alpha_{t+1}=\alpha_t+\gamma(\alpha-\text{err}_t)\), where \(\text{err}_t=1\) if \(y_t\) fell outside the interval.
When to use it
Use it for
- Intervals for boosting, random forests or neural nets
- When you need a stated coverage level for decisions
- Comparing models on interval quality, not just point accuracy
Avoid it for
- Tiny calibration sets (fewer than ~100 points)
- Strong regime shifts without recalibration
Key settings
| Setting | What it controls | Typical value |
|---|---|---|
alpha | Miscoverage level | 0.1 for 90% intervals |
calibration window | Most recent data held out from training | last season or year |
score | Nonconformity measure | absolute error; scaled error for varying volatility |
Python example
import numpy as np import pandas as pd from sklearn.ensemble import HistGradientBoostingRegressor URL = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/daily-min-temperatures.csv" y = pd.read_csv(URL, index_col="Date", parse_dates=True)["Temp"] X = pd.DataFrame({f"lag{k}": y.shift(k) for k in (1, 2, 3, 7, 365)}) X["doy"] = y.index.dayofyear data = X.assign(target=y).dropna() # three consecutive blocks: fit the model, calibrate the intervals, then test them n = len(data) fit, cal, test = data.iloc[: n - 730], data.iloc[n - 730 : n - 365], data.iloc[n - 365 :] model = HistGradientBoostingRegressor(max_iter=300, learning_rate=0.05, random_state=0) model.fit(fit.drop(columns="target"), fit["target"]) alpha = 0.1 # target 90% coverage scores = np.abs(cal["target"] - model.predict(cal.drop(columns="target"))) # nonconformity scores k = int(np.ceil((len(scores) + 1) * (1 - alpha))) q = np.sort(scores)[min(k, len(scores)) - 1] # finite-sample quantile pred = model.predict(test.drop(columns="target")) lo, hi = pred - q, pred + q covered = np.mean((test["target"] >= lo) & (test["target"] <= hi)) print(f"interval half-width: ±{q:.2f} °C empirical coverage on the test year: {covered:.1%}")
Tips & pitfalls
- Calibrate per horizon for multi-step forecasts: errors grow with h.
- Normalise scores by a volatility estimate to get intervals that widen in turbulent periods.
- Always report empirical coverage on a test period, as in the example.
References
- Vovk, V., Gammerman, A., & Shafer, G. (2005). Algorithmic Learning in a Random World. Springer.
- Gibbs, I., & Candès, E. (2021). Adaptive conformal inference under distribution shift. Advances in Neural Information Processing Systems 34.
- Xu, C., & Xie, Y. (2021). Conformal prediction interval for dynamic time-series. Proceedings of ICML 2021.