Songeun Kim

New Paradigms in Modern Statistics I

Algorithm

The general split conformal algorithm, starting from adaptive prediction sets for classification, with application examples.

A standard conformal prediction procedure starts from a supervised dataset, i.e., data with labels. We denote the calibration dataset by D={(Xi,Yi)}i=1n∈(X×Y)n\mathcal D = \{(X_i, Y_i)\}_{i=1}^{n} \in (\mathcal X \times \mathcal Y)^n, kept separate from the training data used to fit the model, and the new target test point by XnewX_{\text{new}}. Given a black-box model f^\hat f, we also start from some heuristic notion of uncertainty, which we call the score function. For example, the score can simply be the softmax score of a classification model, or the residual if we are doing regression.

For a target coverage level 1−α1-\alpha, the general conformal prediction algorithm is:1

  1. Compute the scores. S={s(Xi,Yi)}i=1nS = \{ s(X_i, Y_i) \}_{i=1}^{n}.
  2. Compute the quantile. q^=Quantile(S; ⌈(n+1)(1−α)⌉/n)\hat q = \mathrm{Quantile}\big(S;\ \lceil (n+1)(1-\alpha) \rceil / n\big).
  3. Return the prediction set. C(Xnew)={y∈Y:s(Xnew,y)≤q^}\mathcal C(X_{\text{new}}) = \{ y \in \mathcal Y : s(X_{\text{new}}, y) \le \hat q \}.

For example, consider the Adaptive Prediction Sets (APS) algorithm, which is best known for the discrete case, i.e., Y={1,…,K}\mathcal Y = \{1, \dots, K\}. Here, we set the score function as

s(x,y)=∑k=1Kπ^k(x) 1{π^k(x)≥π^y(x)},s(x, y) = \sum_{k=1}^{K} \hat\pi_k(x)\, \mathbf{1}\{\hat\pi_k(x) \ge \hat\pi_y(x)\},

where π^k(x)\hat\pi_k(x) is the softmax output of f^\hat f for class kk, and y∈Yy \in \mathcal Y denotes the true label of xx. In other words, the score function indicates how difficult it is, for a given input, to guess its label correctly.2 The full method is described below.

Classification example: APS

  1. Split the labeled data into three disjoint parts: a training set of size NN that fits the black box f^\hat f, a calibration set of size nn, and a validation set of size nvaln_{\text{val}} held out to check coverage.
  2. Pass every calibration and validation point through f^\hat f once and cache its score Si=s(Xi,Yi)S_i = s(X_i, Y_i). For APS, sort the softmax outputs and add them up from the top until you reach the true label.
  3. Collect the calibration scores S1,…,SnS_1, \dots, S_n and set q^\hat q to their ⌈(n+1)(1−α)⌉/n\lceil (n+1)(1-\alpha) \rceil / n empirical quantile.
  4. Run f^\hat f on the new input, sort its softmax outputs again, and keep the labels whose cumulative mass stays below q^\hat q: C(xnew)={y:s(xnew,y)≤q^}\mathcal C(x_{\text{new}}) = \{ y : s(x_{\text{new}}, y) \le \hat q \}.
traincalibrationvalidationNnnvalcacheS1S2⋯SnSn+1⋯Sn+nvaltrue labels(X1, Y1) = 0.88sorted softmax of X1true labels(X2, Y2) = 0.91sorted softmax of X2histogram of S1, …, Sn0.800.850.900.951.00q̂ = 0.961 − ααxnewf̂q̂catlynxfoxdogwolfowl𝒞(xnew) = {cat, lynx, fox}sorted softmaxcumulative massq̂ from step 3

Footnotes

  1. This is called split conformal prediction. An algorithm without an explicit calibration set is called full conformal prediction. ↩

  2. The score is defined this way in order to satisfy adaptiveness. ↩