Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.A guarantee on top of any model
Suppose a model predicts a value and you want a range that contains the truth 90% of the time. Conformal prediction gives one without trusting the model at all. Take some held-out examples the model has not seen, see how far off the model was on each, and find the error size that 90% of them stayed within (rounded up slightly). Add that margin around every new prediction. If the new case behaves like the held-out ones, the range catches the truth at least 90% of the time. A bad model gives wide ranges, but the promise still holds. The demo shows how much the actual coverage varies with the number of held-out examples.
A satellite-image classifier for flood mapping can return a set of possible classes, such as water or wet soil, instead of one label. The set is guaranteed to contain the truth 95% of the time. Ambiguous pixels get larger sets, which tells analysts where to look.
- 1. Conformal prediction needs the model to be…
- 2. A bad model leads to…
- 3. Calibration data must be…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Score: a number s(x, y) that is large when y fits the model’s prediction badly, for example |y − f(x)| for regression or 1 − p_y(x) for classification.
- Split conformal: compute scores s_1…s_n on a calibration set; let q be the ⌈(n+1)(1 − α)⌉-th smallest. The prediction set C(x) holds every y with s(x, y) ≤ q. For regression with |y − f(x)| this is f(x) ± q.
- Guarantee: if the n + 1 points are exchangeable, P(Y ∈ C(X)) ≥ 1 − α, and also ≤ 1 − α + 1/(n+1) when scores have no ties. Coverage is marginal, averaged over calibration and test draws.
- Full conformal (Vovk, Gammerman and Shafer, 2005): for each candidate y, refit the model on all n points plus (x, y) and keep y if its conformal p-value exceeds α. It uses all the data but costs one fit per candidate. Cross-conformal and jackknife+ (Barber et al., 2021) are in between.
- Scores for classification: LAC / threshold, 1 − p_y (Sadinle, Lei and Wasserman, 2019), gives the smallest average sets. APS (Romano, Sesia and Candès, 2020) uses the probability mass of all more likely classes plus a random fraction of p_y, which adapts set size to difficulty. RAPS (Angelopoulos et al., 2021) adds a penalty on rank to shrink APS sets. Mondrian conformal calibrates per group or per class.
- Conditional coverage P(Y ∈ C(X) given X = x) ≥ 1 − α for every x is impossible to guarantee in general without infinite-width sets (Vovk, 2012; Foygel Barber et al., 2021). Group-conditional coverage is possible.
- 1. The conformal threshold is the…
- 2. APS sets adapt to…
- 3. Conformal coverage is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Building conformal sets
Exercise 1.
- The conformal quantile with the (n + 1) correction.
- Split-conformal regression intervals.
- LAC scores and sets.
- Randomised APS scores and sets.
Practice.
- Keep a calibration set the model never trained on; 500 to 2000 examples give realised coverage within about ±1 to 2 points.
- Choose the score for the use: LAC for the smallest sets, APS or RAPS for difficulty-adaptive sets, Mondrian (per-class or per-group) when coverage must hold within groups.
- Report coverage and average set size on a test set, overall and per group.
- Better models give smaller sets; conformal only guarantees coverage, not usefulness.
- Libraries: MAPIE (version 1 API below), crepes, TorchCP and puncc.
from mapie.classification import SplitConformalClassifier # MAPIE >= 1.0
mapie = SplitConformalClassifier(estimator=clf, confidence_level=0.9,
conformity_score="aps", prefit=True) # clf already trained
mapie.conformalize(X_cal, y_cal) # held-out calibration data
y_pred, y_sets = mapie.predict_set(X_test) # y_sets: (n, K, 1) boolean set membership
print("coverage", y_sets[np.arange(len(y_test)), y_test, 0].mean(), "size", y_sets.sum(1).mean())- 1. MAPIE's method that uses the calibration data is…
- 2. For coverage within each class use…
- 3. Conformal guarantees…
Level 3: Advanced
★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.Theory
Proof of the guarantee. Let s_1, …, s_n be the calibration scores and s_(n+1) the test score. If the n + 1 pairs are exchangeable, so are the scores, and the rank of s_(n+1) among all n + 1 is uniform on 1…n + 1 (with no ties). The event Y_(n+1) ∈ C(X_(n+1)) is s_(n+1) ≤ q, where q is the k-th smallest calibration score with k = ⌈(n+1)(1 − α)⌉. This happens exactly when s_(n+1) is among the k smallest of the n + 1 scores, which has probability k/(n+1) ≥ 1 − α. The same counting gives the upper bound 1 − α + 1/(n+1).
Realised coverage. For a fixed calibration set, the coverage on new data is F(q), where F is the score distribution. Over random calibration sets it is Beta(k, n + 1 − k), with mean k/(n+1) and standard deviation about √(α(1 − α)/n) (Vovk, 2012; Angelopoulos and Bates, 2023). With n = 20 that is about ±0.06; the guarantee holds on average, not for every calibration set.
Full conformal. For a candidate y, refit on all n + 1 points and compute every point’s score; keep y if its p-value (1 + the number of i with s_i ≥ s_(n+1))/(n + 1) exceeds α. The refitted model treats all points symmetrically, so exchangeability holds and the guarantee follows as before. For linear models the residuals are linear in y, so the set can be computed exactly.
Why the score matters. LAC thresholds every class probability at the same level, so it includes few classes for confident inputs and many for flat ones. Even so, it covers confident inputs more than needed and hard inputs less. APS’s score is uniform when the probabilities are correct, for every input, which gives approximately conditional coverage when the model is calibrated.
- 1. The rank of the test score among n + 1 exchangeable scores is…
- 2. Realised coverage over calibration sets follows…
- 3. Full conformal keeps a candidate when…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.How much does one calibration set’s coverage vary, which score adapts to difficulty, and what does full conformal gain?
History.
- V. Vovk, A. Gammerman and G. Shafer, “Algorithmic Learning in a Random World” (2005): full conformal prediction; H. Papadopoulos et al. (2002) inductive (split) conformal.
- J. Lei, M. G’Sell, A. Rinaldo, R. Tibshirani and L. Wasserman (2018) “Distribution-free predictive inference for regression”.
- M. Sadinle, J. Lei and L. Wasserman (2019) LAC; Y. Romano, M. Sesia and E. Candès (2020) APS; A. Angelopoulos et al. (2021) RAPS; A. Angelopoulos and S. Bates (2023) “Conformal prediction: a gentle introduction”.
Exercise 2. Three experiments at α = 0.1.
- Realised coverage: absolute-residual scores with N(0, 1) errors. For each of 400 random calibration sets of size n, measure coverage on 1000 test points.
- Classification: 10 classes; half the inputs easy (logits with scale 3), half hard (scale 0.5); the model outputs the true probabilities. 1000 calibration and 4000 test examples, 20 repetitions.
- Full against split: linear regression y = 1 + 2x + N(0, 1) with n = 20; full conformal on a grid of candidate labels versus split conformal (10 to fit, 10 to calibrate); 200 repetitions.
| calibration points | mean coverage | sd over calibration sets | share below 0.88 | Beta theory mean, sd |
|---|---|---|---|---|
| 20 | 0.907 | 0.059 | 0.292 | 0.905, 0.063 |
| 100 | 0.903 | 0.031 | 0.240 | 0.901, 0.030 |
| 1000 | 0.900 | 0.013 | 0.072 | 0.900, 0.009 |
| score | coverage | mean set size | coverage easy / hard | size easy / hard |
|---|---|---|---|---|
| LAC | 0.903 | 5.04 | 0.928 / 0.877 | 2.57 / 7.53 |
| APS | 0.899 | 5.21 | 0.898 / 0.899 | 2.48 / 7.97 |
| n = 20 regression | mean width | coverage |
|---|---|---|
| full conformal | 3.70 | 0.895 |
| split conformal | 4.18 | 0.900 |
- The guarantee held on average and matched k/(n + 1). A single small calibration set was another matter: with 20 points, 29% of calibration sets gave coverage below 0.88. With 1000 points the spread was 0.013. That is the Beta spread of 0.009 plus the noise of a 1000-point test set.
- LAC gave the smallest sets but split the coverage unevenly: 92.8% on easy inputs and 87.7% on hard ones. APS spent 0.17 more classes on average to give 90% on both.
- Full conformal was 11% narrower than split conformal, because it used all 20 points for both fitting and calibration. Both stayed valid.
- Seeds 1 and 2: LAC hard-input coverage 0.867 and 0.869; APS 0.896 and 0.898; full against split width 3.68 against 4.11 and 3.67 against 3.99; spread at n = 20 0.060 and 0.061.
Conformal prediction in AI, robotics and aerospace
- Perception for autonomy: conformal sets over object classes or bounding-box margins give guaranteed miss rates for planners (Lindemann et al., 2023, conformal prediction for motion planning).
- Remote sensing: land-cover maps with per-pixel conformal sets show where labels are ambiguous.
- LLMs: conformal language modelling (Quach et al., 2024) returns sets of sampled answers that contain an acceptable one with a guaranteed probability.
References
- V. Vovk, A. Gammerman and G. Shafer (2005). “Algorithmic Learning in a Random World.” Springer.
- J. Lei, M. G’Sell, A. Rinaldo, R. J. Tibshirani and L. Wasserman (2018). “Distribution-free predictive inference for regression.” JASA.
- Y. Romano, M. Sesia and E. Candès (2020). “Classification with valid and adaptive coverage.” NeurIPS.
- A. Angelopoulos, S. Bates, J. Malik and M. I. Jordan (2021). “Uncertainty sets for image classifiers using conformal prediction.” ICLR.
- A. Angelopoulos and S. Bates (2023). “Conformal prediction: a gentle introduction.” Foundations and Trends in ML.