Prediction Intervals and Split Conformal Prediction › Formula
Machine Learning from ScratchAll chapters Prediction Intervals and Split Conformal Prediction › FormulaSection view · Sections in this chapter4 / 10 ↓
Reading tools Definitions, links & notes
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
We now build the machinery. The aim is to turn a bare point prediction into a band, and to do it in a way that comes with a guarantee we can state precisely. Three questions have to be answered along the way:
- What are we trying to cover? Not the regression surface, but the next observation. If the response retains nondegenerate noise, additional fitting data do not remove that noise.
- How do we measure a miss? We need a number that grows when a candidate observation becomes implausible under the fitted model, a nonconformity score.
- How do we convert finitely many measured misses into a margin that is valid for the next one? This is where exchangeability enters, and where a seemingly cosmetic turns out to carry the entire guarantee.
Notation throughout: fit the predictor and score on , then use a disjoint calibration set . A fresh test pair is . Conditional on the fitted score function, require these calibration and test scores to be exchangeable. Independent observations from one distribution, with an independent fitting split, are a sufficient setting. The separate test sample in the example evaluates the completed procedure.
Confidence intervals, prediction intervals, and prediction sets
Before building the procedure, distinguish three targets: a population quantity, a future observation, and a class label. The target determines which inclusion statement we need to establish.
A confidence interval targets a population quantity, such as a mean, coefficient or quantile. For example, an interval for aims to contain that fixed conditional mean across repeated fitting samples at the specified input. Its width can shrink under regular consistent estimation; shrinking is not an unconditional property of every confidence procedure.
A prediction interval targets a future observation and aims for a specified inclusion probability. It accounts for response variation as well as uncertainty in the fitted predictor. With persistent nondegenerate noise it can remain wide even when mean estimation is precise. For a symmetric noise distribution, a symmetric band around its center uses the quantile of the absolute noise as its half-width.
A prediction set is the classification analogue: a random subset with . Whereas an interval is an ordered range on the real line, a set is an unordered collection of labels, and its natural size measure is cardinality rather than length.
For comparison, consider the correctly specified linear model with fitting observations and nonconstant predictors plus an intercept. In this comparison only, denotes fitting size rather than calibration size. Assume , a fixed full-rank design, independent Gaussian errors with variance , and an independent future error with the same variance. At a fixed new design vector , the Gaussian prediction interval is
where:
- : the fitted value at the new input
- : the residual variance estimate (the sum of squared residuals divided by )
- : the full-rank training design matrix, including an intercept column and nonconstant predictors
- : the quantile of a distribution with degrees of freedom
- : the new-point leverage, with containing the intercept and the same predictors as the design matrix
The "" inside the square root reflects the additional noise of the future observation. It is there because the error of prediction decomposes as
Under these Gaussian-model assumptions, conditional on the fixed design and new input, the new observation error is independent of the fitting-sample estimation error. Their variances therefore add:
where:
- : the future observation whose value is not yet known
- : the fitted model's prediction at the future input
- : the true conditional mean
- : the noise variance
Under regular increasing-sample designs with a fixed number of predictors, mean-estimation uncertainty decreases. The mean confidence interval uses only the estimation term, while the prediction interval also contains the future-noise term. For a 95% Gaussian interval, its large-sample noise margin is approximately . This comparison explains the extra in the displayed square root.
The weakness of this construction is the assumption stack: Gaussian errors, constant variance, a correctly specified linear model, and independent observations. Split conformal keeps the same target, the observation, but replaces every one of those assumptions with exchangeability alone.
Calibration scores and finite-sample quantiles
The engine of conformal prediction is the nonconformity score. The idea is to condense each candidate pair and the fitted model into a single number, , that grows as the pair becomes less plausible under the model. A score is doing its job when it is small for observations the model explains well and large for observations it explains poorly.
For regression with a scalar response the standard choice is the absolute residual
where:
- : the nonconformity score for calibration point , measuring how far the model's prediction misses the observed response
- : the observed response for calibration point
- : the fitted model's prediction for calibration point
For classification with fitted class probabilities the standard choice is
where:
- : the nonconformity score for calibration point , equal to one minus the probability of the observed label
- : the fitted probability the model assigns to the observed label at input
- : the observed class label of calibration point
This score is small when the model assigns high probability to the observed label and large when it assigns low probability. Many other scores are possible; we will meet several. Choose and freeze the score function without using the calibration or test outcomes for fitting or selection. At prediction time, evaluate it for candidate labels or responses; the unknown true future response is not supplied to the procedure.
Given the scores , sort them and write the order statistics as
The conformal quantile at miscoverage level is the order statistic at index
For , set . If , set and return the full response space. Clipping to would lose the requested guarantee at small calibration sizes.
where:
- : the calibration set size
- : the miscoverage level, so is the nominal coverage
- : the ceiling index , which can equal ; that case uses an infinite threshold
- : the -th smallest calibration score
- : the conformal score threshold; for absolute-residual regression it is the interval half-width
This implementation selects an order statistic without interpolation. Other quantile conventions need to be checked against the stated finite-sample cutoff; an ordinary interpolating call is not generally equivalent.
The symbol denotes the ceiling function: the smallest integer greater than or equal to its argument. For and we get , so and .
To see the role of , first assume the exchangeable scores are almost surely distinct. The test score then has a uniform rank in . For , it falls below the th calibration score exactly when that rank is at most . Thus
where:
- : the nonconformity score of the future test point, an exchangeable draw from the same pool as the calibration scores
- : the -th smallest calibration score, used as the conformal quantile
- : the ceiling index , computed from the calibration size and miscoverage level
The equality holds because happens exactly when the rank of is one of the smallest.
The rank calculation behind the guarantee can be inspected directly. With and , we have , so . Under distinct exchangeable scores, the test score has eleven equally likely ranks, and ranks one through ten fall at or below the calibrated cutoff ; only the largest rank falls outside it. The cell below prepares the rank probabilities for the figure: it computes the ceiling index without clipping, builds uniform rank probabilities, and flags the ranks covered by the cutoff. This is an exact rank illustration, with no sampled data.
PythonIn [2]Expand
import numpy as np
n_rank = 10
alpha_rank = 0.10
k_rank = int(np.ceil((n_rank + 1) * (1 - alpha_rank)))
ranks = np.arange(1, n_rank + 2)
rank_prob = np.full(ranks.shape, 1.0 / (n_rank + 1))
covered_rank = (k_rank - ranks) >= 0VisualizationOut [3]Expand

Setting gives
The ceiling gives the lower bound in the distinct-score case, provided so the displayed finite order statistic is used. Below the finite-threshold cutoff, , so and the infinite threshold covers the full response space. With ties, independently randomizing the order within equal scores gives a uniform rank, and the deterministic event includes every rank-at-most- case. Its probability is therefore at least , although equality need not hold. If , the infinite threshold covers the full response space. Using or an ordinary interpolating quantile does not supply this general finite-sample guarantee; the values can coincide for some inputs, so the issue is the missing guarantee rather than universal under-coverage.
There is a matching upper bound. If the scores are almost surely distinct, then
so the guarantee is tight to within . For and , coverage lands between and roughly . This statement requires exchangeable scores, while leaving the response distribution otherwise unrestricted.
A finite threshold under this convention requires , equivalently . At least nine calibration observations permit a finite 90% threshold; at least 99 permit a finite 99% threshold. Smaller calibration samples still give valid sets through , but those sets are uninformative. These cutoffs do not guarantee stable or narrow finite thresholds.
The finite-threshold cutoff is only part of the story. At fixed , the guaranteed floor equals one while the infinite-threshold branch is active at small calibration sizes. Once a finite threshold exists, the ceiling index makes the floor vary nonmonotonically as grows. The figure below plots the rank-based floors for calibration sizes from 1 to 200. It evaluates the formula directly, with no sampled data.
PythonIn [4]Expand
n_grid = np.arange(1, 201)
def coverage_floor_for(nominal):
alpha_level = 1.0 - nominal
k = np.ceil((n_grid + 1) * (1.0 - alpha_level)).astype(int)
return np.where(k > n_grid, 1.0, k / (n_grid + 1))
coverage_floor_90 = coverage_floor_for(0.90)
coverage_floor_95 = coverage_floor_for(0.95)VisualizationOut [5]Expand

This bound arises because requires , equivalently since is an integer. Solving:
Split conformal regression and classification
Putting the pieces together, split conformal regression is a four-step procedure, sometimes called inductive conformal prediction (Papadopoulos et al., 2002). Notice how cleanly the steps separate the modelling from the calibration. The model is fit and frozen first, and only then does the conformal machinery measure its mistakes.
- Fit the point predictor on . Nothing about this step is special; use whatever model you like and whatever model selection procedure you like, as long as it never touches .
- Compute calibration scores for .
- Compute . Set if and otherwise.
- For a new input , return when is finite, and return the full response space when .
The interval is the point prediction plus or minus a constant margin. When is finite its width is exactly everywhere, independent of ; when the set is the full response space. Here is the conformal quantile computed from calibration scores, and there is no guarantee that averaging a realized test batch reproduces the nominal coverage. That is both its simplicity and its main weakness, and we will return to the consequence shortly.
Step 4 is worth reading backwards, because that is how the guarantee is usually proved. The event is the same as , which is the same as . Everything reduces to the rank argument in the previous subsection. The proof does not require a particular predictor family or parametric response law. Its sampling argument uses exchangeability of the held-out scores.
For classification, the same four steps apply with a different score, and step 4 becomes a set construction:
where:
- : a candidate class label in
- : the fitted probability the model assigns to label at input
- : the conformal quantile from the calibration scores, so is the probability threshold
For the score , classification keeps labels whose fitted probability is at or above . The calibration step chooses the threshold automatically, in such a way that the fraction of calibration points whose nonconformity score exceeds is at most . This uses held-out outcomes to calibrate set inclusion. It is different from Probability Calibration, which evaluates or adjusts probability reliability. Accurate class probabilities are useful, but are not required for this marginal set-coverage proof.
The threshold applies to each candidate label, so set size varies with the probability vector and the calibrated cutoff. Several labels may pass, or none may pass. The marginal guarantee controls overall inclusion under its sampling assumptions. For a proper nonempty subset of the class space, set size alone does not determine its conditional inclusion probability. Set size alone also does not establish an out-of-distribution interpretation.
Mathematical Properties
Several properties follow from the construction and are worth naming. Treat them as a checklist of what the formula does and does not give us.
- Coverage is finite-sample. Under the score-exchangeability condition, holds for every and , using the infinite-threshold branch when necessary. No asymptotic approximation is used.
- The guarantee is distribution-free over score distributions satisfying exchangeability. The predictor and score construction must be fixed before calibration; no correctly specified parametric response model is required.
- Monotonicity in . With the same calibration scores, decreasing cannot decrease or . The sets are nested, although the discrete index can stay unchanged over a range of levels.
- Invariance to monotone rescaling of scores. Replacing by any strictly increasing transform yields the same prediction sets, since the ranking is unchanged. The transform must be well-defined and the same for every calibration and candidate score. The small-calibration branch still returns the full response space; it does not require evaluating . Dividing by an input-dependent scale is a different score construction and can change the resulting sets.
- Width depends on the score distribution. With a fixed score and independent calibration samples growing in size, the empirical cutoff converges to its population score quantile at continuity and identifiability points. When the fitted score also changes, additional consistency assumptions are needed. Improving a predictor under one loss does not universally shrink every conformal cutoff.
- Ties can make deterministic inclusion conservative: may exceed . This removes the distinct-score upper slack bound; it does not by itself prove that an interval can be narrowed while keeping the same guarantee.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!