Conformal score construction and quantiles
Implement a split-conformal rank threshold with explicit ties and the infinite-threshold boundary rather than an interpolated sample quantile.
On this page
The question for today
What you’ll understand
- Construct split-conformal sets from a fixed nonconformity score.
- Compute the corrected order-statistic index including k greater than n.
- Explain score design, ties, and marginal coverage without assuming probability calibration.
Split conformal prediction uses held-out labeled scores to construct a set of candidate outcomes. A finite-sample rank correction, rather than an arbitrary percentile interpolation, connects the construction to its coverage statement. Two implementation details matter especially with small calibration sets: include candidates whose score equals the threshold, and return an infinite threshold when the corrected index lies beyond the available scores. Silently clipping that index can invalidate the advertised error level.
Fix the score before using calibration labels
Start with a predictor and score function fixed without the calibration labels. Larger scores mean worse agreement between an input and a candidate outcome. For scalar regression, absolute residual is a simple score in outcome units; for finite-class classification, one minus the candidate-class probability is a dimensionless alternative. The classification probabilities need not themselves be calibrated for the rank argument. Their quality matters for whether the resulting sets are informative rather than merely valid and excessively large.
Use the same score calculation on calibration pairs and on every candidate outcome at prediction time. Fitting a score or choosing among many score definitions based on those calibration labels introduces adaptation not covered by the basic split procedure. Deduplicate and split at the unit that supports the intended exchangeability assumption before fitting. A set-valued prediction also needs an interface: an empty or very large set is possible for some constructions and should trigger a specified action rather than an undocumented conversion to a confident single label.
Use an order statistic with an explicit boundary
For n calibration scores and target error level alpha strictly between zero and one, compute k as the ceiling of (n+1)(1−alpha). If k is at most n, take the kth smallest score using one-based indexing. Otherwise set the threshold to positive infinity. This convention is equivalent to appending an infinite score before selecting the order statistic. At small alpha, a finite sample cannot support the requested nontrivial rank resolution, and the full-set answer expresses that limitation honestly.
Thresholding with less-than-or-equal includes ties and preserves the conservative lower coverage bound under exchangeability. With distinct exchangeable scores and k at most n, coverage is k/(n+1), averaged over calibration and the future point. Ties can make coverage larger, so do not claim a matching near-nominal upper bound without the needed assumptions or a specified randomized tie-breaking construction. Randomness used for ties must be independent and applied symmetrically; adding arbitrary noise after inspecting inconvenient cases is not an analyzed randomization scheme.
Separate score usefulness from rank validity
A constant or uninformative score can produce valid but uselessly large sets. Improve score design on separate development data, then recalibrate using untouched labels under the declared sampling assumptions. Record the score version, alpha, calibration IDs, index, threshold, and tie rule so the prediction set can be reproduced. Compare set sizes and error locations as well as overall coverage. A marginal coverage statement does not ensure that every input receives a useful set, nor that any particular realized calibration sample has exactly the target coverage.
The probability lab illustrates a different calculation: repeated errors at a supplied fixed rate. Reset, set p to 0.1 and n to 10, predict expected count one and zero-error probability 0.9¹⁰ ≈ 0.3487, then Step. Compare a fresh Reset with both p at 0.1 and n at 30 before Step: mean three and zero-error probability approximately 0.0424. It assumes independent Bernoulli errors and neither computes conformal scores nor proves coverage for a shared calibration set.
Work it through
A finite residual threshold and the full-set boundary
A fixed regression predictor has nine calibration absolute residuals, sorted as 0.1, 0.2, 0.2, 0.4, 0.5, 0.7, 0.9, 1.1, and 1.4 meters. Its new prediction is 10 meters. Construct the split-conformal interval at alpha = 0.1 and then alpha = 0.05.
For alpha = 0.1, k = ceil(10 × 0.9) = 9. The threshold is the ninth score, 1.4 meters, including candidates exactly on the boundary.
Absolute-residual inversion gives [10 − 1.4, 10 + 1.4] = [8.6, 11.4] meters. This is a prediction interval for a future outcome, not a confidence interval for a parameter.
For alpha = 0.05, k = ceil(10 × 0.95) = 10 > 9. The threshold is infinite and the interval is all real numbers. Reusing 1.4 would discard the required boundary convention.
The corrected rank, inclusive threshold, and infinite case are part of the algorithm, not optional numerical settings.
The living notebook
Explore the model
Interactive lab · probability
A supplied error rate is not a conformal quantile
Reset, set p = 0.1 and n = 10, predict mean 1 and zero-error probability ≈ 0.3487, then Step. Compare a fresh Reset with both p = 0.1 and n = 30 before Step: mean 3 and zero-error probability ≈ 0.0424. These exact independent-binomial masses do not calculate conformal ranks or model dependence through a shared calibration set.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forConformal rank validity and independent repeated-error counting have distinct assumptions.
Pause & reason
Check your understanding
Your turn
Try it yourself
Five sorted classification scores are 0.1, 0.2, 0.4, 0.4, 0.7. Use alpha = 0.4 and score s(x,y)=1−p_y. For a new probability vector (0.6, 0.3, 0.1), compute k, the threshold, and the set. Also give the threshold at alpha = 0.1.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Use one-based order statistics and include equality. At the smaller alpha, check whether the required index exists.
Compare with the solution
At alpha = 0.4, k = ceil(6 × 0.6) = 4, so q = 0.4. Candidate scores are 0.4, 0.7, and 0.9; only the first class is included, with equality retained. At alpha = 0.1, k = ceil(6 × 0.9) = 6 > 5, so q is infinite and all three classes are included. Tied calibration values do not justify changing the inclusive rule.
Keep the idea
Take it with you
- Choose and freeze the score before consuming calibration labels.
- Use the corrected order-statistic rank, including its infinite boundary.
- Inclusive ties give conservative marginal coverage; usefulness needs separate evaluation.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.