
Week 9: uncertainty and interpretation
| Loss | Best prediction at \(x\) | |
|---|---|---|
| Squared error, \((y - \hat y)^2\) | the conditional mean, \(\mathbb E[Y \mid X = x]\) | optimal model theorem |
| Absolute error, \(\lvert y - \hat y \rvert\) | the conditional median | stated |
| A miss costs \(c_{FN}\), a false alarm \(c_{FP}\) | predict \(1\) when \(p(x) > c^\star = \frac{c_{FP}}{c_{FP} + c_{FN}}\) | optimal threshold theorem |
Decision principle: choose the prediction \(\hat y\) that minimizes the expected loss given the inputs, \(\mathbb E[\ell(Y, \hat y) \mid X = x]\)
Squared loss gives the mean, absolute loss the median. Which loss makes the best prediction the 90th percentile?
Part 1: decisions and quantiles
Part 2: regression uncertainty and intervals
Part 3: classification uncertainty and calibration
Part 4: interpreting the model
Part 5: the model and the world
So far, competitors submit models that predict, and the winning model is chosen by best score on the evaluation dataset: an average over many people
Now the winning model is deployed. A new person arrives with inputs \(x_0\) and is told \(\hat f(x_0)\). How far off might that be?
You are that person. What should a “90% interval” for your outcome promise you?
That the interval, call it \(\hat C(x_0)\), covers outcomes of people with your inputs 90% of the time: \(P\big(Y \in \hat C(X) \mid X = x_0\big) \ge 0.9\), conditional coverage
Charge \(\tau\) for each unit of underprediction (\(y > \hat y\)) and \(1 - \tau\) for each unit of overprediction (\(y < \hat y\)). Move the prediction up from \(\hat y\) to \(\hat y + \delta\):

With \(F\) the distribution function of \(Y\) given \(X = x\), the expected change is about \[ \delta\,\big[(1 - \tau)F(\hat y) - \tau\,(1 - F(\hat y))\big] = \delta\,\big[F(\hat y) - \tau\big] \]
Keep moving up while \(F(\hat y) < \tau\); stop where \(F(\hat y) = \tau\): the \(\tau\)-quantile. For the 90th percentile, \(\tau = 0.9\)
Pinball loss: \[ \rho_\tau(y - \hat y) = (y - \hat y)\,\big(\tau - \mathbf 1\{y < \hat y\}\big) \] \(\tau\,(y - \hat y)\) for an underprediction, \((1 - \tau)(\hat y - y)\) for an overprediction. With \(\tau = \frac12\), half the absolute error

Quantile optimality theorem. If \(Y \mid X = x\) has a continuous distribution with a finite mean and \(0 < \tau < 1\), then the conditional \(\tau\)-quantile \(q_\tau(x)\) minimizes \(\mathbb E[\rho_\tau(Y - \hat y) \mid X = x]\) over \(\hat y\) (uniquely, unless the distribution function is flat at \(\tau\))
Squared loss gave the mean; half the absolute error, \(\tau = \frac12\), gives the median
Minimize the average pinball loss over a class: \(\hat q_\tau = \arg\min_{f \in \mathcal F} \frac1n \sum_i \rho_\tau\big(y_i - f(x_i)\big)\). Here \(\mathcal F\) is linear; 1,000 simulated points whose noise grows with \(x\)

Boosted trees with the pinball loss: each tree is built from the negative gradient \(\tau - \mathbf 1\{y_i < \hat f(x_i)\}\), which pushes the fit up where points lie above it

Boosting: each small tree approximates the negative gradient of the training loss
At a new \(x_0\), \(Y_0 = f^\star(x_0) + \varepsilon_0\)

Bias–variance at \(x_0\): \(\sigma^2 + \text{bias}^2 + \text{variance}\); no amount of data shrinks \(\sigma^2\)
A 90% interval from two quantile fits: \(\hat C(x) = [\hat q_{0.05}(x), \hat q_{0.95}(x)]\). The true quantiles would cover \(Y\) with probability \(0.9\) at every \(x\); estimated ones aim at that

We claim 90 percent intervals. With fresh data in hand, how do you check the claim, and what could the check miss?

Top: coverage in each range of \(x\), pink if more than 3 points from 90% (two standard errors). Overall: 88%, 89%, 87%. Widening never lowers coverage: check width too
For a \(1 - \alpha\) interval (\(\alpha = 0.1\) so far):
Impossibility of distribution-free conditional coverage. If a procedure covers with probability at least \(1 - \alpha\) given \(X = x\), in finite samples, for every distribution and almost every \(x\), then wherever the inputs are continuous its intervals have infinite expected length (Barber et al. 2021). Guarantees for groups (each range of \(x\), say), and results under assumptions or as \(n\) grows, remain possible
No free lunch theorem: no method does best on every distribution; a guarantee at every \(x\) needs an assumption about the distribution
\(\hat f(x) \pm d\), \(d\) the 90th percentile of absolute residuals; constant noise, 500 rows to fit

| Held-out rows | on other rows | on the held-out rows | narrowest interval |
|---|---|---|---|
| 500 | 90.1% | 89.9% | 89.1% |
| 100 | 90.0% | 89.3% | 87.5% |
Separate rows to fit, to tune and to hold out; or tune by cross-validation within the fitting rows
Optimism theorem: training error underestimates the risk

\(m = 500\), \(Q = 0.25\): 87% to 90%; for \(x\) in 6–8, 80% to 82%
Conformal coverage theorem (Romano et al. 2019). If the rows are independent draws from one distribution, \(P(Y \in \hat C(X)) \ge 0.9\) for any quantile fits (\(\le 0.9 + 1/(m + 1)\) for continuous scores), averaging over calibration sets; across sets of 500, coverage has a standard deviation of about 1.3 points
Asymptotic conditional coverage (Sesia and Candès 2020). If the rows are independent draws from one distribution, the scores have a density bounded away from zero near zero, and the quantile fits are consistent (their mean squared error at a new \(X\) tends to zero as the fitting and calibration sets grow), then \(\hat C(x)\) approaches \([q_{0.05}(x), q_{0.95}(x)]\), and its coverage given \(X = x\) tends to 90%, except on a set of \(x\) whose probability tends to zero
To check coverage near \(x\), or to estimate a quantile there, we use the rows near \(x\): a bin or a smoother. 2,000 fresh rows, 5 bins for each input:
| Inputs | 1 | 2 | 3 | 5 |
|---|---|---|---|---|
| Bins | 5 | 25 | 125 | 3,125 |
| Rows per bin | 400 | 80 | 16 | 0.6 |
| Standard error at 90%, points | 1.5 | 3.4 | 7.5 | – |
Curse of dimensionality: in ten dimensions, a cube holding 10% of the population spans 79% of each axis
| Method | Assumes | Can claim |
|---|---|---|
| Linear model, normal noise | linear mean, constant variance | 90% at every \(x\), if right |
| Mean and variance models | both right, normal noise | about 90% at every \(x\), if right |
| Quantile regression | the quantile model right | 90% at every \(x\) as \(n\) grows, if right |
| Split conformal (Lei et al. 2018) | independent rows | at least 90% marginally; one width |
| CQR (Romano et al. 2019) | independent rows | at least 90% marginally; widths from the fits; at every \(x\) as \(n\) grows, if the fits are consistent |
More in the note on the course page, “Prediction intervals and calibration”
A model gives \(\hat p = 0.2\) to 500 adults: their probability of having diabetes. What should be true of them?
About 100 of them should have diabetes. A score \(\hat p\) is calibrated if \[ P\big(Y = 1 \mid \hat p(X)\big) = \hat p(X) \]
The same idea as coverage: a stated probability should match a frequency. It conditions on the score, not on \(x\)
A probability is acted on: a risk told to a patient, a premium set from an expected cost, a threshold set from the costs of errors
Optimal threshold theorem: with costs \(c_{FP}\) and \(c_{FN}\), the rule that minimizes expected cost at \(x\) predicts \(1\) exactly when \(p(x) > c^\star = c_{FP}/(c_{FP} + c_{FN})\)
Diabetes (14% of the training adults). Two scores from nine measurements, fitted on 4,000 adults, checked on 3,000 others

A map from the old score to a new one, learned on half the tuning adults, checked on the other half: a logistic regression of the label on \(\mathrm{logit}\,\hat p\), giving \(\mathrm{logit}\,\tilde p = a + b\,\mathrm{logit}\,\hat p\)

For \(b > 0\) the map is increasing: the same ranking, new probabilities. \(b = 0.39\): two adults whose boosted log-odds differ by 1 differ by 0.39 after. Log loss on the other half: 0.375 to 0.329
One score for everyone. If it is too high for one group and too low for another, a shared threshold refers the first group for tests more often, and the second less often, than their risk warrants: the score discriminates, even with race and ethnicity left out of its inputs

White adults: average score 14.8%, 10.6% with diabetes
Fairness criteria conflict: with different base rates, no imperfect score is calibrated within groups and averages the same in each group among adults with diabetes, and among those without (Kleinberg et al. 2017)
Multicalibration (Hébert-Johnson et al. 2018): calibrated within every group of a collection named in advance, at every range of scores. Here: in each group and tenth of the scores (at least 100 adults), if the share with diabetes and the average score differ by more than 0.02, shift the scores by the gap; repeat; apply the shifts to new adults
Learned on the tuning adults, checked on the test adults. Gaps in standard errors: White 2.0 to 0.6, Black 1.8 to 0.2, Mexican American 0.7 to 2.4
Log loss 0.324 to 0.327: small cells fit noise. The shifts need each adult’s group

Options for the other inputs: hold them fixed (at medians, say: plotmo’s default); average over them (partial dependence, pdp); one curve for each unit (individual conditional expectation, ICE)
Unit \(i\)’s inputs with input \(j\) set to a value \(t\), the others left as they are: \[ \mathrm{ICE}_i(t) = \hat f(x_{i1}, \ldots, t, \ldots, x_{ip}), \qquad \mathrm{PDP}_j(t) = \frac1n \sum_{i=1}^n \hat f(x_{i1}, \ldots, t, \ldots, x_{ip}) \]
Compute on a grid of \(t\) values and plot the curve(s). Any model that predicts will do
ICE evaluates \(\hat f\) at a modified input, which may correspond to no plausible unit. It is the model’s prediction there, not what would have happened to unit \(i\): recomputing a unit with its own noise, as in the causality seminar, asks a different kind of question, which this course does not develop

The PDP: \(x_1\) set, \(x_2\) at each unit’s value, predictions averaged over 100 units
Sketch two curves, one for each of two units, that average to the black curve

Thin: one curve per unit (ICE), solid where \(\cos(\pi x_2/2) > 0\), dashed where it is negative, more opaque the larger \(|\cos(\pi x_2/2)|\). The forest fitted the interaction, PDP hides it, and ICE might show it
Split a prediction among the inputs, \(\hat f(\mathbf x_i) - v_i(\varnothing) = \phi_{i1} + \dots + \phi_{ip}\); \(v_i(S)\) predicts from the inputs in \(S\) only (usually: the others averaged over the data, as in partial dependence). For two inputs, adding \(x_1\) in either order (for \(p\), all \(p!\) orders): \[ \phi_{i1} = \tfrac12\Big[\big(v_i(\{1\}) - v_i(\varnothing)\big) + \big(v_i(\{1, 2\}) - v_i(\{2\})\big)\Big] \]
The forest, one unit with \(x_1 = -0.95\) and \(x_2 = -3.78\):
| \(v_i(\varnothing)\) | \(v_i(\{1\})\) | \(v_i(\{2\})\) | \(v_i(\{1, 2\}) = \hat f(\mathbf x_i)\) |
|---|---|---|---|
| 0.05 | -0.07 | 0.52 | 0.92 |
\(\phi_{i1} = \frac12\big[(-0.07 - 0.05) + (0.92 - 0.52)\big] = 0.14\)
\(\phi_{i2} = \frac12\big[(0.52 - 0.05) + (0.92 - (-0.07))\big] = 0.73\); together 0.87 \(= 0.92 - 0.05 = \hat f(\mathbf x_i) - v_i(\varnothing)\)

\(\phi_{i1}\) for 300 units, shaded as the ICE curves: the spread at each \(x_1\) shows the interaction. Ringed: the unit above
Black: the PDP minus the average prediction. With independent inputs, the Shapley values average to it
We now use the same NHANES adults to predict systolic blood pressure (mm Hg): a forest on nine inputs, fitted on the 4,000 training adults

A waterfall plot (SHAP: Lundberg and Lee 2017). It starts at the average prediction over the background adults, \(v_i(\varnothing)\), adds each input’s \(\phi_{ij}\), largest first, and ends at this adult’s prediction \(\hat f(\mathbf x_i)\)
The adult with the highest prediction of 200 tuning adults
Sum the RSS decrease of every split on \(x_j\) within a tree, then average over trees
Permute values of predictor \(x_j\). How much does the accuracy of the model decrease? \[\mathrm{PI}_j = \widehat{\mathrm{Err}}(\hat f, x_j \text{ permuted}) - \widehat{\mathrm{Err}}(\hat f)\]

● Shapley: mean \(|\phi_{ij}|\) over adults
Each has pros/cons, no satisfactory answer for dependence

Shuffling height keeps each adult’s weight and BMI: BMI no longer matches weight and height for 68% of them (0% before); 34 are under 155 cm and over 110 kg (4 before)
The forest’s predictions there rest on almost no data, and permutation importance averages over them (Hooker, Mentch and Zhou 2021)

Where the data’s density is below 0.01: 17% of the permuted points, 2% of the data

Refit without input \(j\), with the same settings; score on the same held-out adults (Lei et al. 2018): \[\mathrm{LOCO}_j = \widehat{\mathrm{Err}}\big(\hat f^{(-j)}\big) - \widehat{\mathrm{Err}}(\hat f)\]
No extrapolation from permuting; any method, at the cost of \(p\) refits
Weight, height and BMI together: 17.1. Each alone: -0.4, -0.5, -0.1; refitting the same forest moves its MSE by about 0.4 (sd, five refits). Any two give the third
\(v_i(S)\) must fill in the inputs not in \(S\) (Chen et al. 2020):
Example: \(\hat f(\mathbf x) = \beta_1 x_1\); inputs with mean \(0\), variance \(1\), correlation \(\rho\), and \(\mathbb E[X_1 \mid x_2] = \rho x_2\). Marginal: \(\phi_{i2} = 0\). Conditional: \(\phi_{i2} = \frac12 \rho \beta_1 x_{i2}\), and \(\phi_{i1} = \beta_1 x_{i1} - \phi_{i2}\)
Background: after Loftus, Bynum and Hansen (2024), Figure 5
A partial dependence plot for \(x_1\) leaves \(x_2\) and \(x_3\) at each unit’s value. In the world, they respond to \(x_1\). To let them respond, what do we need besides the fitted model?
A causal model for the inputs. An explanatory causal model (ECM; Loftus, Bynum and Hansen 2024) adds the prediction \(\hat Y = \hat f(X)\), with dashed arrows from the model’s inputs. Here \(x_3\) depends on \(y\), so \(y\) is in it too:
\(x_2 = x_1 + \varepsilon_2\), \(\ y = \tfrac12 x_1 + \tfrac32 \sin x_2 + \varepsilon\), \(\ x_3 = y + x_1 + \varepsilon_3\); \(\hat f\), a forest on \(x_1, x_2, x_3\)

In the ECM, set \(x_1 = t\) for every unit, predict, average, with \(x_2\) and \(x_3\)

NDDP falls: with \(x_3\) held fixed, a larger \(x_1\) means a smaller \(y\). TDP follows the effect of setting \(x_1\) (dashed). Grey: marginal Shapley values
Causal Shapley values (Heskes et al. 2020) put \(do(\cdot)\) in place of conditioning
Model-intervention corollary. In the adjustment theorem’s model, \(T = h(Z, \varepsilon_T)\) and \(Y = g(T, Z, \varepsilon_Y)\) with independent noises, let \(f^\star(t, z) = \mathbb E[Y \mid T = t, Z = z]\). If \(T\) takes finitely many values and \(P(T = t \mid Z) > 0\) with probability one, then \(\mathbb E_Z\big[f^\star(t, Z)\big] = \mathbb E[Y \mid do(T = t)]\)

In words: \(Z\) holds every common cause of \(T\) and \(Y\), and no consequence of \(T\). A population identity; the PDP \(\frac1n\sum_i \hat f(t, z_i)\) estimates it, even when \(\hat f = f^\star\): \[ \mathrm{PDP}_T(t) = \mathbb E[Y \mid do(T = t)] + \text{model error} + \text{sampling error} \]
Partial dependence (pink) against the effect of setting the plotted input (dashed), for forests on the inputs named

Adjustment theorem: \(Z\) holds every common cause of \(T\) and \(Y\), and no consequence of \(T\). Here the inputs are continuous with overlap; for \(x_2\), \(Z = \{x_1\}\), without \(x_3\)
The loss decides which number is the best prediction; two quantiles make an interval, and conformalizing them guarantees marginal coverage for independent rows, and coverage at every \(x\) as \(n\) grows if the quantile fits are consistent. Check coverage and calibration on data not used to fit or tune, across the range of the inputs and within groups: no method guarantees coverage at every \(x\) in finite samples without assumptions
Partial dependence, ICE, Shapley values and importance describe \(\hat f\). Under valid adjustment and accurate estimation, the PDP estimates the interventional mean; with a causal model for the inputs, the total dependence plot answers a different question
These slides state two conditions more simply than the sources do:
ST310 Machine Learning