Sam Babichenko

Reading notes / Conformal prediction and distribution shift

Split conformal prediction

Lei et al., 2018; Romano et al., 2019

Context. Regression had confidence intervals for coefficients, each resting on a correct model, and almost nothing for the question a user asks: how far can the next response be from the prediction? A quantile of the training residuals undercovers, because a model's residuals on its own data are biased low; an interpolator has zero training residuals whatever its test error. Lei et al. turn conformal prediction (Vovk et al., 2005) into a regression toolkit; Romano et al. conformalize quantile regression (CQR) so that the band's width follows the noise. If the test point is scored by the same symmetric rule as the training points, its score is exchangeable with theirs, so its rank is uniform and a score quantile is a valid threshold whatever the model; the model affects only the width. With CQR's score the band takes its shape from a quantile model and its validity from the rank argument. The guarantee is marginal in both papers.

Setting. Zi=(Xi,Yi)∈Rd×RZ_i=(X_i,Y_i)\in\mathbb R^d\times\mathbb R, i=1,…,n+1i=1,\dots,n+1, are i.i.d. (exchangeable suffices), α∈(0,1)\alpha\in(0,1), and A\mathcal A is any regression algorithm symmetric in its input points. Full conformal: for each trial value yy, fit μ^y=A(Z1,…,Zn,(Xn+1,y))\hat\mu_y=\mathcal A(Z_1,\dots,Z_n,(X_{n+1},y)), set Ry,i=∣Yi−μ^y(Xi)∣R_{y,i}=|Y_i-\hat\mu_y(X_i)| and Ry,n+1=∣y−μ^y(Xn+1)∣R_{y,n+1}=|y-\hat\mu_y(X_{n+1})|, and keep yy unless the test residual ranks too high: π(y)=1n+1∑i=1n+11{Ry,i≤Ry,n+1},Cconf(x)={y: (n+1)π(y)≤⌈(1−α)(n+1)⌉}.\pi(y)=\frac1{n+1}\sum_{i=1}^{n+1}\mathbf 1\{R_{y,i}\le R_{y,n+1}\},\qquad C_{\rm conf}(x)=\big\{y:\ (n+1)\pi(y)\le\lceil(1-\alpha)(n+1)\rceil\big\}. Split conformal: fit μ^\hat\mu once on a random half I1I_1, take residuals Ri=∣Yi−μ^(Xi)∣R_i=|Y_i-\hat\mu(X_i)| on the other half I2I_2, let dd be their kk-th smallest with k=⌈(n/2+1)(1−α)⌉k=\lceil(n/2+1)(1-\alpha)\rceil, and output μ^(x)±d\hat\mu(x)\pm d. CQR instead fits quantile regressions q^αlo,q^αhi\hat q_{\alpha_{\rm lo}},\hat q_{\alpha_{\rm hi}} at αlo=α/2\alpha_{\rm lo}=\alpha/2, αhi=1−α/2\alpha_{\rm hi}=1-\alpha/2 on I1I_1 (typically by pinball loss) and calibrates on I2I_2: Ei=max⁡{q^αlo(Xi)−Yi, Yi−q^αhi(Xi)},C(x)=[q^αlo(x)−Q, q^αhi(x)+Q],E_i=\max\{\hat q_{\alpha_{\rm lo}}(X_i)-Y_i,\ Y_i-\hat q_{\alpha_{\rm hi}}(X_i)\},\qquad C(x)=\big[\hat q_{\alpha_{\rm lo}}(x)-Q,\ \hat q_{\alpha_{\rm hi}}(x)+Q\big], where QQ is the ⌈(1−α)(∣I2∣+1)⌉\lceil(1-\alpha)(|I_2|+1)\rceil-th smallest score, that is, the (1−α)(1+1/∣I2∣)(1-\alpha)(1+1/|I_2|)-th empirical quantile.

Coverage theorems. For every distribution and every symmetric A\mathcal A (with ties handled as in Step 1), P(Yn+1∈Cconf(Xn+1))≥1−α\mathbb P(Y_{n+1}\in C_{\rm conf}(X_{n+1}))\ge1-\alpha, and if the fitted residuals have a continuous joint distribution, P(Yn+1∈Cconf(Xn+1))≤1−α+1n+1.\mathbb P\big(Y_{n+1}\in C_{\rm conf}(X_{n+1})\big)\le1-\alpha+\frac1{n+1}. Split conformal satisfies the same lower bound and, with continuous residuals, the upper bound 1−α+2/(n+2)1-\alpha+2/(n+2); CQR covers with probability at least 1−α1-\alpha for any quantile regression algorithm, and at most 1−α+1/(∣I2∣+1)1-\alpha+1/(|I_2|+1) with almost surely distinct scores, both conditionally on the fitting half. The probabilities are over all n+1n+1 draws, so the guarantee is marginal over Xn+1X_{n+1}; the lower bound is Vovk's, the upper bound is new in Lei et al. Calibrating each CQR end with its own one-sided score, q^αlo(Xi)−Yi\hat q_{\alpha_{\rm lo}}(X_i)-Y_i and Yi−q^αhi(Xi)Y_i-\hat q_{\alpha_{\rm hi}}(X_i), with inflated quantiles at levels (1−αlo)(1+1/∣I2∣)(1-\alpha_{\rm lo})(1+1/|I_2|) and (1−αhi)(1+1/∣I2∣)(1-\alpha_{\rm hi})(1+1/|I_2|), where αlo,αhi\alpha_{\rm lo},\alpha_{\rm hi} now denote the two tail miscoverages, guarantees each tail separately (Theorem 2): P{Yn+1≥lower end}≥1−αlo\mathbb P\{Y_{n+1}\ge\text{lower end}\}\ge1-\alpha_{\rm lo} and P{Yn+1≤upper end}≥1−αhi\mathbb P\{Y_{n+1}\le\text{upper end}\}\ge1-\alpha_{\rm hi}, so with α=αlo+αhi\alpha=\alpha_{\rm lo}+\alpha_{\rm hi} the band covers with probability at least 1−α1-\alpha.

Efficiency theorems. The conformal band is as short as the best band built around the fitted model, and as short as the best band outright when the fit is consistent. Assume ε=Y−μ(X)\varepsilon=Y-\mu(X) is independent of XX with a density symmetric about 0 and nonincreasing on [0,∞)[0,\infty). The super oracle μ(x)±qα\mu(x)\pm q_\alpha, qαq_\alpha the upper α\alpha quantile of ∣ε∣|\varepsilon|, is the shortest band with conditional coverage; the oracle μ^n(x)±qn,α\hat\mu_n(x)\pm q_{n,\alpha} uses the upper α\alpha quantile of ∣Y−μ^n(X)∣|Y-\hat\mu_n(X)| for a fresh draw. With Δn=μ^n−μ\Delta_n=\hat\mu_n-\mu, a noise density with derivative bounded by MM and at least rr near qαq_\alpha, ∣qn,α−qα∣≤(M/2r) EΔn2(X)|q_{n,\alpha}-q_\alpha|\le(M/2r)\,\mathbb E\Delta_n^2(X). Under sampling stability, P(∥μ^n−μ~∥∞≥ηn)≤ρn\mathbb P(\|\hat\mu_n-\tilde\mu\|_\infty\ge\eta_n)\le\rho_n for a fixed μ~\tilde\mu with ηn,ρn→0\eta_n,\rho_n\to0 (and a density lower bound for ∣Y−μ~(X)∣|Y-\tilde\mu(X)| near its upper α\alpha quantile), the split width satisfies νsplit−2qn,α=OP(ηn+ρn+n−1/2)\nu_{\rm split}-2q_{n,\alpha}=O_P(\eta_n+\rho_n+n^{-1/2}); full conformal needs in addition perturb-one sensitivity, P(sup⁡y∥μ^n−μ^n,(X,y)∥∞≥ηn)≤ρn\mathbb P(\sup_{y}\|\hat\mu_n-\hat\mu_{n,(X,y)}\|_\infty\ge\eta_n)\le\rho_n. Under consistency, P(EX[(μ^n−μ)2∣μ^n]≥ηn)≤ρn\mathbb P(\mathbb E_X[(\hat\mu_n-\mu)^2\mid\hat\mu_n]\ge\eta_n)\le\rho_n, the split band differs from μ(X)±qα\mu(X)\pm q_\alpha by a set of vanishing length, so it has asymptotic conditional coverage (coverage 1−α−oP(1)1-\alpha-o_P(1) at every xx outside sets of vanishing probability).

In-sample bands and LOCO. Rank-one-out (ROO) split conformal fits μ^k\hat\mu_k on half IkI_k and gives each point ii of the other half the interval μ^k(Xi)±di\hat\mu_k(X_i)\pm d_i, did_i the mm-th smallest of the other residuals in that half, m=⌈(n/2)(1−α)⌉m=\lceil(n/2)(1-\alpha)\rceil; Theorem 5.1 puts its in-sample coverage within ϵ\epsilon of [1−α,1−α+2/n][1-\alpha,1-\alpha+2/n] with probability at least 1−2e−cnϵ21-2e^{-cn\epsilon^2}. For variable importance, refit without covariate jj and define the excess error Δj(x,y)=∣y−μ^(−j)(x)∣−∣y−μ^(x)∣\Delta_j(x,y)=|y-\hat\mu_{(-j)}(x)|-|y-\hat\mu(x)|. With Wj(x)={Δj(x,y):y∈C(x)}W_j(x)=\{\Delta_j(x,y):y\in C(x)\} for a conformal band CC, P(Δj(Xn+1,Yn+1)∈Wj(Xn+1) for all j=1,…,d)≥1−α.\mathbb P\big(\Delta_j(X_{n+1},Y_{n+1})\in W_j(X_{n+1})\ \text{for all }j=1,\dots,d\big)\ge1-\alpha .

Step 1

The test point's rank is uniform, so inverting the rank test covers. Fix the trial value at the truth, y=Yn+1y=Y_{n+1}. The augmented fit treats all n+1n+1 points symmetrically, so exchangeable data give exchangeable residuals, and with no ties the last one's rank is uniform on {1,…,n+1}\{1,\dots,n+1\}: P((n+1)π(Yn+1)≤⌈(1−α)(n+1)⌉)=⌈(1−α)(n+1)⌉n+1≥1−α.\mathbb P\big((n+1)\pi(Y_{n+1})\le\lceil(1-\alpha)(n+1)\rceil\big)=\frac{\lceil(1-\alpha)(n+1)\rceil}{n+1}\ge1-\alpha . Nothing about μ^\hat\mu or PP enters; refitting with the candidate removes the naive method's bias by fitting the test point on the same footing as the others. Read as a test, CconfC_{\rm conf} keeps the yy that the p-value 1−π(y)+1/(n+1)1-\pi(y)+1/(n+1) for H0:Yn+1=yH_0:Y_{n+1}=y does not reject (the paper writes 1−π(y)1-\pi(y), which is anti-conservative by 1/(n+1)1/(n+1): for n=1n=1 it is 0 with probability 1/2). The cost is one refit per (x,y)(x,y) on a grid, and the set need not be an interval.

Step 2

Without ties, coverage is at most 1−α+1/(n+1)1-\alpha+1/(n+1). With distinct residuals the display above is an equality, and ⌈(1−α)(n+1)⌉/(n+1)<1−α+1/(n+1)\lceil(1-\alpha)(n+1)\rceil/(n+1)\lt1-\alpha+1/(n+1). The upper bound shows that the method does not reach coverage by inflating the band; it is calibrated, and the excess 1/(n+1)1/(n+1) comes from the rank being discrete. Random tie-breaking removes the continuity assumption.

Step 3

Split conformal and CQR are the same argument given the first half, and the inflated quantile accounts for the unseen test score. Conditional on I1I_1 the fitted functions are fixed, so the m=∣I2∣m=|I_2| calibration scores and the test score are exchangeable. The inflation lemma takes the unknown test score out of the threshold: with k=⌈(1−α)(m+1)⌉k=\lceil(1-\alpha)(m+1)\rceil, En+1≤E(k,m)  ⟺  En+1≤E(k,m+1),E_{n+1}\le E_{(k,m)}\iff E_{n+1}\le E_{(k,m+1)}, because inserting En+1E_{n+1} below the kk-th smallest of mm values makes it at most the kk-th smallest of m+1m+1, and conversely. The right side is a quantile of all m+1m+1 exchangeable scores, so the test score falls below it with probability at least 1−α1-\alpha, and at most 1−α+1/(m+1)1-\alpha+1/(m+1) without ties; averaging over I1I_1 gives the marginal statements, and m=n/2m=n/2 gives split conformal's 2/(n+2)2/(n+2). A single fit is what makes conformal practical around the lasso, a forest or a quantile network; the cost is that only half the data are used for fitting. Removing the split's randomness by intersecting NN bands at level 1−α/N1-\alpha/N is valid by Bonferroni but widens the band (Theorem 2.4, under stability with ρn=o(1/n)\rho_n=o(1/n)): the fits are within ηn=o(1)\eta_n=o(1) of each other, so intersecting gains almost nothing, while by DKW each empirical (1−α/N)(1-\alpha/N) quantile stays above the (1−α)(1-\alpha) quantile by a fixed gap.

Step 4

CQR's signed score turns coverage into one inequality, and the sign lets calibration shrink the band. Below the fitted interval EE is the distance to the lower end, above it the distance to the upper end, and inside it the larger of two nonpositive numbers, so Yn+1∈C(Xn+1)  ⟺  En+1≤QY_{n+1}\in C(X_{n+1})\iff E_{n+1}\le Q and coverage depends only on the rank of one score. When the quantile model is too generous most calibration scores are negative, Q<0Q\lt0, and both ends move in; when it is too tight, Q>0Q\gt0 widens it. The correction is one additive shift at every xx, so the band keeps the quantile model's shape. Per-tail calibration applies the inflation lemma twice and costs width (average length 1.40 to 1.58 for the network), since the symmetric version lets the miscoverage fall in whichever tail the model gets wrong.

Step 5

The guarantee is marginal, and conditional coverage is out of reach without assumptions. Lei et al. cite the impossibility without proving it (Lei and Wasserman, 2014): a band with P(Y∈C(x)∣X=x)≥1−α\mathbb P(Y\in C(x)\mid X=x)\ge1-\alpha for almost every xx and every PP has infinite expected length at non-atom points x0x_0 of PXP_X. The proof uses a local perturbation: spread YY given XX over a huge range on a small ball around x0x_0. No training point is likely to land in the ball, so the two sample laws are close in total variation and the band, which must cover the huge range under the perturbed law, is huge under PP too. Steps 6 to 8 recover conditional coverage under assumptions on the estimator.

Step 6

The regression error moves the oracle width only at second order. Independence of ε\varepsilon and XX writes the CDF of ∣Y−μ^n(X)∣|Y-\hat\mu_n(X)| as the noise CDF F0F_0 averaged over shifts by the fit error: Fn(t)=E[F0(t+Δn(X))−F0(−t+Δn(X))].F_n(t)=\mathbb E\big[F_0(t+\Delta_n(X))-F_0(-t+\Delta_n(X))\big]. In a Taylor expansion the first-order terms Δnf0(t)\Delta_nf_0(t) and −Δnf0(−t)-\Delta_nf_0(-t) cancel because the noise density is symmetric, leaving sup⁡t∣Fn(t)−F(t)∣≤(M/2)EΔn2\sup_t|F_n(t)-F(t)|\le(M/2)\mathbb E\Delta_n^2, and the density lower bound turns this into the quantile bound. A biased fit costs width only through its mean squared error.

Step 7

Under stability, the conformal width is the oracle width. A fit within ηn\eta_n of a fixed μ~\tilde\mu moves every residual by at most ηn\eta_n, so every quantile involved is within ηn\eta_n of a quantile of residuals about μ~\tilde\mu: the empirical calibration quantile is within ηn\eta_n of the empirical quantile of ∣Yi−μ~(Xi)∣|Y_i-\tilde\mu(X_i)|, which is within OP(n−1/2)O_P(n^{-1/2}) of its population value, and qn,αq_{n,\alpha} is within ρn/r+ηn\rho_n/r+\eta_n of that value. Full conformal refits for every yy, so it also needs perturb-one, which keeps the augmented residuals within 2ηn2\eta_n of residuals about μ~\tilde\mu for all trial yy at once and pins the width between two nearby quantiles. Since μ~\tilde\mu need not be μ\mu, stability alone makes the band as short as the fitted model allows.

Step 8

A consistent fit gives the super oracle and conditional coverage in the limit. Consistency controls only the mean squared error, so split xx-space into a small bad set where the fit is off and the rest. By Markov the bad set Bn={x:∣μ^n(x)−μ(x)∣≥ηn1/3}B_n=\{x:|\hat\mu_n(x)-\mu(x)|\ge\eta_n^{1/3}\} has probability at most ηn1/3\eta_n^{1/3}; it is independent of the calibration half, so by Hoeffding only o(n)o(n) calibration points fall in it, and off it the residuals about μ^n\hat\mu_n and μ\mu differ by at most ηn1/3\eta_n^{1/3}. The empirical quantile is then sandwiched between quantiles of ∣εi∣|\varepsilon_i| at levels α+oP(1)\alpha+o_P(1), and a test point lands off BnB_n with probability tending to one, so the band converges to μ(X)±qα\mu(X)\pm q_\alpha. For the lasso, restricted eigenvalues give both with ηn\eta_n of order slog⁡d/ns\sqrt{\log d/n}, enough for split conformal; full conformal's perturb-one needs support recovery.

Step 9

In-sample coverage is exact by construction, and LOCO inherits simultaneous coverage. The paper proves Theorem 5.1 with McDiarmid, but sorting gives more (not in the paper): with distinct residuals the point of rank rr in its half is covered exactly when r≤mr\le m, since the mm-th smallest of the others is R(m+1)R_{(m+1)} if r≤mr\le m and R(m)R_{(m)} otherwise. So in-sample coverage equals 2m/n∈[1−α,1−α+2/n]2m/n\in[1-\alpha,1-\alpha+2/n] with probability one; my simulation (OLS, heavy-tailed heteroskedastic noise, n=20,50,200n=20,50,200) returned exactly 2m/n2m/n in every run. Theorem 2.3 (the half-sample statement for split conformal) is deterministic for the same reason; since that coverage holds by construction, it cannot test the method, and the in-sample band serves only for display. For LOCO, if Yn+1∈C(Xn+1)Y_{n+1}\in C(X_{n+1}) then Δj(Xn+1,Yn+1)∈Wj(Xn+1)\Delta_j(X_{n+1},Y_{n+1})\in W_j(X_{n+1}) for every jj at once, since each WjW_j is an image of the same set: one event of probability 1−α1-\alpha covers all dd intervals.

Step 10

In experiments the bands keep their coverage, and CQR gives the shortest. Conformal bands are valid under misspecification, and their length tracks the model. At 90% Lei et al.'s bands covered within 2 points in every setting, including t2t_2 heteroskedastic noise and nonlinear means; at n=500n=500, d=490d=490 with least squares, full conformal covered 0.903 with length 8.1, against 0.867 and 24.2 for the parametric interval and 0.883 and 26.1 for the jackknife. Locally weighted bands (residuals divided by a fitted spread σ^\hat\sigma) adapt only partly, because σ^\hat\sigma is fit to the fitting half's residuals, which are biased low and nearly zero for a network that almost interpolates; CQR's model is trained on the quantiles themselves, and anything done on I1I_1, such as tuning the nominal levels, does not affect validity. On eleven benchmarks at α=0.1\alpha=0.1 average lengths were 2.24 and 2.16 for forest and network, 1.82 and 1.81 locally weighted, and 1.41 and 1.40 for CQR, all conformal methods at 89.9 to 90.3%; unconformalized quantile networks covered only 88.5% and quantile forests 92.6%, so calibration fixes both. CQR overcovered on the two Facebook datasets, which the paper attributes to ties among discrete scores, which void the upper bound. Coverage within slices of XX, what adaptivity is meant to improve, is not measured.

Consequences and limits. Conformal inference separates the two jobs of a prediction interval: validity comes from exchangeability alone and efficiency from the estimator, so a good model gives a near-oracle band, a bad one a valid but wide band, and interval length becomes a measure for comparing models. Split conformal and CQR became defaults because each costs one fit. The guarantee is marginal, which in fraud or credit monitoring suits portfolio statements but is too weak for decisions about a segment, since a band can hold 90% overall while covering a small high-risk segment far less; one constant CQR correction fixes a quantile model too narrow in one region and too wide in another only on average. Limits: exchangeability excludes covariate shift and drift (the covariate-shift paper in this section reweights the rank argument); full conformal is impractical for most estimators; the jackknife has no finite-sample guarantee without stability, later supplied at level 1−2α1-2\alpha by the jackknife+ (Barber et al., 2021); separately fitted quantile ends can cross; and LOCO's global inference is conditional on the first half's fit.

Terms

CconfC_{\rm conf}
full conformal set: refit with each trial yy, keep yy if its residual ranks within ⌈(1−α)(n+1)⌉\lceil(1-\alpha)(n+1)\rceil
CsplitC_{\rm split}
μ^(x)±d\hat\mu(x)\pm d, dd the ⌈(n/2+1)(1−α)⌉\lceil(n/2+1)(1-\alpha)\rceil-th smallest held-out residual; one fit
π(y)\pi(y)
rank of the candidate's residual among the n+1n+1 augmented residuals; 1−π(y)+1/(n+1)1-\pi(y)+1/(n+1) is a p-value
Coverage bounds
1−α≤P(Y∈C)≤1−α+1/(n+1)1-\alpha\le\mathbb P(Y\in C)\le1-\alpha+1/(n+1) (split: +2/(n+2)+2/(n+2)); upper side needs no ties (with π\pi as printed, the lower side too)
Marginal coverage
averaged over Xn+1X_{n+1}; conditional coverage at every xx forces infinite expected length at non-atoms
CQR score EiE_i
max⁡{q^lo(Xi)−Yi, Yi−q^hi(Xi)}\max\{\hat q_{\rm lo}(X_i)-Y_i,\ Y_i-\hat q_{\rm hi}(X_i)\}: signed distance outside the fitted interval
CQR band
[q^lo(x)−Q, q^hi(x)+Q][\hat q_{\rm lo}(x)-Q,\ \hat q_{\rm hi}(x)+Q], QQ the ⌈(1−α)(∣I2∣+1)⌉\lceil(1-\alpha)(|I_2|+1)\rceil-th smallest score; may be negative
Inflation lemma
En+1≤E_{n+1}\le the (1+1/m)(1+1/m)-inflated quantile of mm scores iff ≤\le the plain quantile of m+1m+1
qn,αq_{n,\alpha}, qαq_\alpha
oracle (law of ∣Y−μ^n(X)∣|Y-\hat\mu_n(X)|) and super oracle (law of ∣ε∣|\varepsilon|) half-widths; stability reaches the first, consistency the second
LOCO Δj\Delta_j
∣y−μ^(−j)(x)∣−∣y−μ^(x)∣|y-\hat\mu_{(-j)}(x)|-|y-\hat\mu(x)|; intervals WjW_j valid simultaneously over jj

Quiz

  1. Split conformal's upper bound is 1−α+2/(n+2)1-\alpha+2/(n+2) rather than full conformal's 1−α+1/(n+1)1-\alpha+1/(n+1). Where does the difference come from?
  2. With an interpolating base fit (min-norm least squares, d≥n+1d\ge n+1), what does tie-safe full conformal (strict counting, or the quantile with a point at +∞+\infty) return?
  3. Why can no finite-length band have conditional coverage 1−α1-\alpha at almost every xx for every distribution?
  4. Suppose the fitted quantiles are too narrow for large xx and too wide for small xx. What does CQR's calibration do?

Sources