Unit 6, lesson 41

Prediction Intervals and Split Conformal Prediction

How a prediction interval differs from a confidence interval, what aleatoric and epistemic uncertainty mean, and how split conformal prediction turns calibration conformity scores into marginal coverage under exchangeability.

  • Video 41
  • Uncertainty and Learning Guarantees

A delivery model predicts 12 minutes for the next order, and a dispatcher wants a range that will contain the actual delivery time with probability at least 80 percent. A confidence interval for the average delivery time does not answer this, because a single delivery varies around the average however well the average is known. Split conformal prediction builds such a range from the errors of a frozen model on a separate calibration set, with a guarantee that needs no assumption about the shape of the error distribution. This lesson constructs the interval step by step and states exactly what the guarantee assumes and what it does not promise.

Key terms

Prediction interval

Definition Let (X,Y)(\mathbf{X}, Y) be a new case whose outcome YY has not been observed. A prediction interval with level 1−α1 - \alpha, for 0<α<10 < \alpha < 1, is an interval C(X)=[L(X),U(X)]C(\mathbf{X}) = [L(\mathbf{X}), U(\mathbf{X})], computed from observed data and the new features but not from YY, such that

P(Y∈C(X))≥1−αP\bigl(Y \in C(\mathbf{X})\bigr) \ge 1 - \alpha

under stated assumptions, where the probability is taken over the data used to build the interval and the new case. A confidence interval targets a fixed quantity, such as the conditional mean E[Y∣X=x]E[Y \mid \mathbf{X} = \mathbf{x}] or a model coefficient, while a prediction interval targets one random future outcome.

In plain words A confidence interval for a mean narrows as data accumulate, because the mean becomes better known. A prediction interval cannot narrow below the spread of individual outcomes, because even a perfectly known mean leaves each delivery free to vary around it. Whether the probability is computed over all new cases together or separately at each input is a further question, taken up under marginal coverage.

Example As a constructed assumption, let delivery times at some input be normal with mean 12 minutes and standard deviation 2 minutes, both known exactly. The central 80 percent prediction interval is 12±1.2816⋅212 \pm 1.2816 \cdot 2, about [9.44,14.56][9.44, 14.56] minutes, with width about 5.135.13 minutes, and no interval that has probability at least 0.80.8 under this distribution is shorter. An 80 percent confidence interval for the mean, computed from 100 such deliveries with the standard deviation known, has half-width 1.2816⋅2/100≈0.261.2816 \cdot 2 / \sqrt{100} \approx 0.26 minutes.

Aleatoric and epistemic uncertainty

Definition For the given features write μ(x)=E[Y∣X=x]\mu(\mathbf{x}) = E[Y \mid \mathbf{X} = \mathbf{x}] and σ2(x)=Var⁡(Y∣X=x)\sigma^2(\mathbf{x}) = \operatorname{Var}(Y \mid \mathbf{X} = \mathbf{x}). Aleatoric uncertainty is the variation of the outcome that remains even when the conditional distribution of YY given X=x\mathbf{X} = \mathbf{x} is known exactly. Epistemic uncertainty is uncertainty about that conditional distribution itself, such as the value of μ(x)\mu(\mathbf{x}), arising from limited data, an imperfect model or limited knowledge. For squared loss and a prediction y^=f^(x)\hat{y} = \hat{f}(\mathbf{x}) computed from data independent of the new outcome,

E[(Y−y^)2∣X=x]=σ2(x)+(μ(x)−y^)2.\begin{aligned} &E\bigl[(Y - \hat{y})^2 \mid \mathbf{X} = \mathbf{x}\bigr] \\[0.4em] &= \sigma^2(\mathbf{x}) + \bigl(\mu(\mathbf{x}) - \hat{y}\bigr)^2 . \end{aligned}

The first term is aleatoric. The second is the error of the learned function at x\mathbf{x}, which is unknown in practice, and epistemic uncertainty is uncertainty about its size. More data or a better model with the same features can reduce the second term but not the first.

In plain words Aleatoric uncertainty is the noise that the chosen features cannot explain, and epistemic uncertainty is what the model has not yet learned. The boundary between them depends on the features. A previously unmeasured factor, such as whether a building has an elevator, can turn part of the apparent noise into predictable variation once it is recorded. The split conformal method below does not separate the two kinds. It calibrates one overall interval from observed errors, which contain both.

Example In the normal example above, the 2 minute standard deviation is aleatoric for those features, and more data with the same features would not reduce it. If the mean of 12 minutes had instead been estimated from a handful of deliveries, a different handful would give a different estimate, and that spread is epistemic. A prediction of 12.512.5 minutes at an input where the true mean is 12 minutes has expected squared error 4+0.52=4.254 + 0.5^2 = 4.25 squared minutes, of which 4 is noise and 0.250.25 comes from the error in the fitted mean.

Conformity score

Definition A conformity score is a function s(x,y)s(\mathbf{x}, y), chosen before any calibration label is seen and computed with the frozen predictor f^\hat{f}, that measures how poorly an outcome yy agrees with the prediction at x\mathbf{x}. Here a larger score means worse agreement. Many texts call a score with this direction a nonconformity score, and some use conformity scores in which larger means better, so a score is always given with its formula. For regression the usual choice is the absolute residual

s(x,y)=∣y−f^(x)∣.s(\mathbf{x}, y) = \bigl\lvert y - \hat{f}(\mathbf{x}) \bigr\rvert .

Given a threshold qq, the prediction set at x\mathbf{x} contains every yy with s(x,y)≤qs(\mathbf{x}, y) \le q. For the absolute residual this is the interval from f^(x)−q\hat{f}(\mathbf{x}) - q to f^(x)+q\hat{f}(\mathbf{x}) + q, endpoints included, with the same width 2q2q at every input. A scaled residual ∣y−f^(x)∣/σ^(x)\lvert y - \hat{f}(\mathbf{x}) \rvert / \hat{\sigma}(\mathbf{x}), with a positive spread estimate σ^\hat{\sigma} fitted on the fitting data, gives intervals f^(x)±q σ^(x)\hat{f}(\mathbf{x}) \pm q\,\hat{\sigma}(\mathbf{x}) that widen where outcomes are expected to vary more.

In plain words The score turns each calibration case into one number, in outcome units for the absolute residual. A score chosen after looking at the calibration residuals has been tuned on them, and the coverage argument below no longer applies to it. The absolute residual gives the same width everywhere, even when deliveries on some routes vary much more than on others.

Example Three constructed fitting cases have inputs 0, 1 and 2 and delivery times 2, 4 and 6 minutes. Least squares with an intercept gives the predictor f^(x)=2+2x\hat{f}(x) = 2 + 2x, which fits them exactly, and it is frozen. Nine separate calibration cases have inputs 0 through 8, with the outcomes, predictions and scores below, all in minutes.

Input xxOutcome yyPredictionScore
00332211
11664422
22776611
3311118833
441212101022
551616121244
661515141411
771818161622
882323181855

Sorted, the scores are 1, 1, 1, 2, 2, 2, 3, 4 and 5 minutes. Every calibration outcome lies above its prediction, so the frozen line underpredicts here. The absolute residual ignores the sign, which leaves the guarantee intact but puts half of each interval below the prediction, the side on which no calibration outcome fell. Switching to a shifted or one-sided score because of this pattern would tune the score on the calibration labels, so such a change belongs on the fitting data or on a separate set of cases.

Split conformal prediction

Definition Split conformal prediction builds a prediction interval from a frozen predictor and a separate calibration set. The development data are split into a fitting set and a calibration set of m≥1m \ge 1 cases, with no case in both. The predictor f^\hat{f} is fitted and tuned on the fitting set only and then frozen. The calibration scores si=∣yi−f^(xi)∣s_i = \lvert y_i - \hat{f}(\mathbf{x}_i) \rvert for i=1,…,mi = 1, \dots, m are sorted as s(1)≤⋯≤s(m)s_{(1)} \le \dots \le s_{(m)}. For a miscoverage level α\alpha in (0,1)(0, 1) chosen in advance, the rank and the radius are

k=⌈(m+1)(1−α)⌉,q={s(k),k≤m,+∞,k=m+1,\begin{gathered} k = \bigl\lceil (m + 1)(1 - \alpha) \bigr\rceil , \\[0.4em] q = \begin{cases} s_{(k)}, & k \le m, \\ +\infty, & k = m + 1, \end{cases} \end{gathered}

and the interval C(x)C(\mathbf{x}) for a new input x\mathbf{x} runs from f^(x)−q\hat{f}(\mathbf{x}) - q to f^(x)+q\hat{f}(\mathbf{x}) + q, endpoints included. Because 0<α<10 < \alpha < 1, the rank kk is always between 1 and m+1m + 1, and k=m+1k = m + 1 happens exactly when α<1/(m+1)\alpha < 1/(m + 1). Suppose that, given the fitting set, the mm calibration cases and the new case (Xm+1,Ym+1)(\mathbf{X}_{m+1}, Y_{m+1}) are exchangeable, and that f^\hat{f} and the score were fixed without using them. Then

P(Ym+1∈C(Xm+1))≥1−α.\begin{aligned} P\bigl(Y_{m+1} &\in C(\mathbf{X}_{m+1})\bigr) \\[0.4em] &\ge 1 - \alpha . \end{aligned}

If in addition the scores are distinct with probability one and k≤mk \le m, the coverage equals k/(m+1)k/(m + 1), which is less than 1−α+1/(m+1)1 - \alpha + 1/(m + 1).

In plain words The new case adds one score to the mm calibration scores. Under exchangeability every one of the m+1m + 1 cases is equally likely to hold any given rank, so with distinct scores the rank of the new score is uniform over 1,…,m+11, \dots, m + 1. The new outcome is covered exactly when its score is at most s(k)s_{(k)}, which means its rank is at most kk, an event with probability k/(m+1)≥1−αk/(m + 1) \ge 1 - \alpha. Ties can only help, since a new score equal to the radius is covered. When k=m+1k = m + 1 no calibration score is large enough. Using the largest calibration score instead would give, with distinct scores, coverage only m/(m+1)m/(m + 1), which is below 1−α1 - \alpha in that case, so the radius is infinite. Residuals on the fitting data cannot replace the calibration set, because the model was fitted to make them small.

Example For the nine calibration scores and α=0.2\alpha = 0.2, the target coverage is 80 percent, and m+1=10m + 1 = 10 gives k=⌈10⋅0.8⌉=8k = \lceil 10 \cdot 0.8 \rceil = 8. The eighth smallest score is 4 minutes, so q=4q = 4. At the new input x=5x = 5 the frozen model predicts 12 minutes, and the interval is [8,16][8, 16] minutes with both endpoints included, a width of 8 minutes. An observed time of 16 minutes would be covered and one of 16.116.1 minutes would not. The fitting residuals are all zero, and calibrating on them would give a radius of zero, an interval that covers none of the nine calibration outcomes. With α=0.05\alpha = 0.05 instead, k=⌈9.5⌉=10k = \lceil 9.5 \rceil = 10 exceeds m=9m = 9, and the radius is infinite. These rows are constructed to make each step checkable. They do not show that real deliveries are exchangeable or that the intervals cover 80 percent of them.

Exchangeability

Definition Random cases Z1,…,ZNZ_1, \dots, Z_N, here Zi=(Xi,Yi)Z_i = (\mathbf{X}_i, Y_i), are exchangeable if for every permutation π\pi of {1,…,N}\{1, \dots, N\} the reordered sequence (Zπ(1),…,Zπ(N))(Z_{\pi(1)}, \dots, Z_{\pi(N)}) has the same joint distribution as (Z1,…,ZN)(Z_1, \dots, Z_N). Independent and identically distributed cases are exchangeable. Exchangeable cases need not be independent, as with draws without replacement from a finite pool. Split conformal prediction needs the mm calibration cases and the new case, so N=m+1N = m + 1, to be exchangeable given the fitting data. Applying the same fixed score function to each of them then makes the scores s1,…,sm+1s_1, \dots, s_{m+1} exchangeable as well.

In plain words Exchangeability says that the order of the cases carries no information, so nothing marks the new case as different from the calibration cases. Drift over time breaks it, because later cases come from a different process than earlier ones. So does a new case from a population that the calibration set did not sample. Repeated cases from the same customers also need a design that accounts for their dependence. A distribution-free guarantee is not assumption-free. It drops assumptions about the shape of the distribution but keeps this one.

Example Suppose that after a change in operations every delivery takes 3 minutes longer than it would have before, while the frozen model and the radius of 4 minutes stay the same. If the new signed residuals behaved like the calibration residuals shifted by 3, they would be 4, 5, 4, 6, 5, 7, 4, 5 and 8 minutes. Only the three equal to 4 fall within the radius, a coverage of 1/31/3 in this stand-in instead of at least 0.80.8. The rank argument fails because the new score is systematically larger than the calibration scores rather than equally likely to land at any rank.

Marginal coverage

Definition Marginal coverage is the probability

P(Ym+1∈C(Xm+1)),P\bigl(Y_{m+1} \in C(\mathbf{X}_{m+1})\bigr),

taken jointly over the calibration set and the new case. Split conformal prediction guarantees that it is at least 1−α1 - \alpha under the conditions above. Stronger properties are not guaranteed. Conditional coverage would require the same bound given Xm+1=x\mathbf{X}_{m+1} = \mathbf{x} for every input x\mathbf{x}, and coverage within each subgroup would require it given membership in the group, and either can fail. The coverage of one realized calibration set, the fraction of future cases covered once qq is fixed, is itself random. When the cases are independent and identically distributed, the scores have a continuous distribution and k≤mk \le m, this fraction follows a beta distribution with parameters kk and m+1−km + 1 - k, whose mean is k/(m+1)k/(m + 1).

In plain words The guarantee is an average over everything random, the calibration set, the new input and the new outcome. It allows the interval to cover easy inputs too often and hard ones too rarely, or to serve a large group well and a small group poorly. For one calibration set the realized coverage can land above or below the target, especially when mm is small. Coverage and width measured on protected data, by subgroup and over time, show how the intervals behave where it matters.

Example Suppose 90 percent of a population has coverage 0.950.95 and the other 10 percent has coverage 0.450.45. The overall coverage is 0.9⋅0.95+0.1⋅0.45=0.900.9 \cdot 0.95 + 0.1 \cdot 0.45 = 0.90, a valid 90 percent marginal statement alongside poor coverage for the small group. For calibration sets of m=9m = 9 cases with continuous scores and α=0.2\alpha = 0.2, so k=8k = 8, the coverage of one calibration set follows a beta distribution with parameters 8 and 2. Its mean is 0.80.8, but it falls below 0.80.8 for about 44 percent of calibration sets and below 0.60.6 for about 7 percent.

Check yourself

  1. A frozen model has four calibration residuals 1, 1.5, 0.5 and 3 units, and its prediction for a new case is 7. With α=0.4\alpha = 0.4, find the rank kk, the radius and the interval.
Show the answer

Sorted, the residuals are 0.50.5, 11, 1.51.5 and 33, and m=4m = 4. The rank is

k=⌈5⋅0.6⌉=3,k = \lceil 5 \cdot 0.6 \rceil = 3,

so the radius is the third smallest residual, 1.51.5. The interval is [7−1.5,7+1.5]=[5.5,8.5][7 - 1.5, 7 + 1.5] = [5.5, 8.5], with both endpoints included. With distinct exchangeable scores its marginal coverage is 3/5=0.63/5 = 0.6, exactly the target.

  1. Repeat the first question with α=0.1\alpha = 0.1. Why is the largest residual, 3, not a valid radius, and how many calibration cases would a finite radius at this level need?
Show the answer

The rank is k=⌈5⋅0.9⌉=⌈4.5⌉=5k = \lceil 5 \cdot 0.9 \rceil = \lceil 4.5 \rceil = 5, which exceeds m=4m = 4, so the radius is infinite and the interval is the whole real line. A radius of 3 covers the new case exactly when its score ranks at most fourth among the five scores, which with distinct exchangeable scores has probability 4/5=0.84/5 = 0.8, short of the required 0.90.9.

A finite radius needs k≤mk \le m, which holds exactly when (m+1)(1−α)≤m(m + 1)(1 - \alpha) \le m, that is when α≥1/(m+1)\alpha \ge 1/(m + 1). For α=0.1\alpha = 0.1 this means m≥9m \ge 9. With nine calibration cases the rank is k=9k = 9, the radius is the largest of the nine scores, and the coverage with distinct scores is 9/109/10.

  1. A team fits a delivery model on data from January to June. It tries five hyperparameter settings and keeps the one whose calibration residuals give the narrowest interval, then computes the radius from those same residuals. It reports that the interval covers 90 percent of deliveries in every region in December, after a change of delivery routes. What is wrong with each part of the claim, and what would make it sound?
Show the answer

Choosing the setting by its calibration residuals uses the calibration labels for tuning, so the scores are no longer those of a predictor fixed without them, and the guarantee does not apply. Tuning belongs on the fitting data, for example by cross-validation inside the fitting set, followed by calibration on cases that took no part in it.

The December cases follow a route change, so they are not exchangeable with calibration cases from the first half of the year, and the rank argument says nothing about them. The calibration set should come from cases that represent the new conditions, and coverage should be monitored on later protected cases.

The guarantee is marginal, so it does not promise 90 percent in every region. Coverage within each region can be targeted by running the calibration separately in each region, which needs enough calibration cases per region and exchangeability within it, and the coverage and width by region should be reported from protected data.

How this lesson connects