Lecture 20 · room 202
HEMA · Università Cattolica del Sacro Cuore, Rome
Wednesday 9 December 2026
Lecture 19 · Lab: neural networks · Fri 4 Dec
| Time | Min | |
|---|---|---|
| 17:00 | Last time · questions | 10’ |
| 17:10 | The trade-off: accuracy against interpretability | 20’ |
| 17:30 | Global tools: importance, partial dependence | 30’ |
| 18:00 | Break | 10’ |
| 18:10 | Local tools: Shapley values, LIME | 25’ |
| 18:35 | Deciding where to stand | 15’ |
| 18:50 | Set 17 | 10’ |
“The model declined her loan. Why?” — and you must answer.
id > 5000 churn — because those were the ones onboarded during a bad quarterAccuracy without interpretability is a liability you have not priced yet.
\text{interpretable} \quad \longleftarrow\quad \text{linear} \;\;\; \text{tree} \;\;\; \text{GAM} \;\;\; \text{forest} \;\;\; \text{boosting} \;\;\; \text{network} \quad\longrightarrow\quad \text{flexible}
The thesis of Module 2, from lecture 18
Flexibility and interpretability are traded, not combined. Every model on the right of the line owes you an explanation it cannot give by itself. The tools of this lecture are how you extract one — approximately, and with care.
They need different tools, and a good explanation to a board is global; to a customer, local.
For a forest: how much does the impurity fall, summed over every split that uses this variable? For any model: permutation importance — shuffle one column, remeasure test error, see how much it worsens.
tenure matters, not howNote
Importance is the first thing a manager asks for and the last thing you should stop at. A variable can be important because the model uses it badly.
Fix one variable at a value x. Set it to x for every row, predict, average. Repeat across x. Plot.
\text{PD}_j(x) \;=\; \frac{1}{n}\sum_{i=1}^{n} \hat f(x,\; x_{i,-j})
monthly_charge reverses between contract types, the average shows nothing. ICE plots — one curve per row, not averaged — reveal that.library(iml); library(ranger)
rf <- ranger(churn ~ ., data = churn[tr, ], num.trees = 300, probability = TRUE)
pred <- Predictor$new(rf, data = churn[-tr, ], y = "churn", class = "yes")
imp <- FeatureImp$new(pred, loss = "logLoss"); plot(imp) # permutation importance
pdp <- FeatureEffect$new(pred, feature = "tenure_months", method = "pdp+ice")
plot(pdp) # average curve + one per customer
FeatureEffect$new(pred, feature = c("monthly_charge", "contract"), method = "pdp") |> plot()The last line: a two-way partial dependence. If the surface is not additive, the one-way plot was hiding something.
LIME: perturb the inputs around this customer, fit a small linear model to the model’s answers. Its coefficients are the explanation.
Shapley values: each variable’s average marginal contribution over all orderings. They sum exactly to this prediction minus the average one — an accounting identity, which is why regulators like them.
| LIME | Shapley (SHAP) | |
|---|---|---|
| Idea | local linear surrogate | fair attribution |
| Guarantee | none — depends on the neighbourhood | additive, consistent |
| Cost | cheap | expensive; TreeSHAP fixes that for trees |
| Use it for | a quick “what drove this” | the answer you put in the letter |
one <- churn[-tr, ][17, ] # a customer the model flagged
sh <- Shapley$new(pred, x.interest = one)
plot(sh) # contribution of each variable, this row
lime <- LocalModel$new(pred, x.interest = one, k = 5) # 5-variable local linear model
plot(lime)The Shapley plot reads: average churn probability 27%; this customer 71%; month-to-month contract +18 points, three support calls +12, fibre +9, tenure of 40 months −6… That is a sentence you can send.
Attention
The failure mode is explanation theatre: a SHAP plot next to a model nobody validated, to make an audience stop asking questions. The tools here are for finding out what the model does, not for making it look understood.
| Decision | Cost of a wrong prediction | Cost of no explanation | Stand |
|---|---|---|---|
| Which customers get the catalogue | low | none | far right: boosting, and move on |
| Whom to call first for retention | medium | low | forest + importance |
| Credit limit | high | high — regulated | left, or right with SHAP in every letter |
| Readmission risk flag on a chart | high | very high — a clinician acts on it | GAM or tree; a network only with PDPs a doctor signed off |
The deciding column is the third, not the second.
Everything else is for the appendix, and for you.
Interpretability · about 40 minutes · before Fri 11 Dec
Not graded. The test is a mirror, not an exam.
iml package vignetteStatistics & Big Data · HEMA, Università Cattolica del Sacro Cuore