Unit 14, lesson 85

Model Interpretation and Feature Importance

How permutation importance, partial dependence, individual conditional expectation curves and SHAP values describe a fitted model globally or locally, what each depends on, and why none measures a causal effect.

  • Video 85
  • Fairness and Interpretation

A model predicts how many minutes a job will take from two workload indices, and someone asks which index matters more. The question has several honest answers, depending on whether it is about the model’s formula, the model’s accuracy on data, the average prediction as one input is varied, or one particular prediction. This lesson builds each answer for one small constructed model, shows how correlated features and the choice of reference data change them, and separates all of them from the causal question of what would happen if a real workload changed.

Key terms

Interpretability

Definition Interpretability is the degree to which a person can understand how a model turns inputs into outputs, well enough to answer a stated question about its behavior. An explanation is a summary of a fitted model that answers such a question. A global explanation describes the model over a stated population or data set, and a global importance is a number per feature that summarizes how much the model’s predictions or its score depend on that feature there. A local explanation describes one prediction for one input, always relative to a stated reference such as an average prediction. Every explanation describes the fitted model and the data used to probe it. None of them by itself says what would happen in the world if a feature were changed, which is a causal question that needs an experiment or explicit causal assumptions.

In plain words Before choosing an explanation, say who needs it and what they want to know. A developer looking for a shortcut, a person asking about one decision and a manager asking whether to change a real process need different summaries, and the third question cannot be answered by any summary of a predictive model. An explanation can also describe an unreliable model faithfully, so it never replaces checking how well the model predicts on the population it is used for.

Example A constructed data set has two workload indices that always agree, with rows (0,0)(0, 0), (1,1)(1, 1), (2,2)(2, 2) and (3,3)(3, 3) and job durations of 0, 3, 6 and 9 minutes, so the duration is 3x13x_1. The fitted model

f(x)=2x1+x2f(\mathbf{x}) = 2x_1 + x_2

predicts all four durations exactly, and so do g(x)=3x2g(\mathbf{x}) = 3x_2 and every model β1x1+β2x2\beta_1 x_1 + \beta_2 x_2 with β1+β2=3\beta_1 + \beta_2 = 3. The coefficient 2 in ff says that its prediction rises by 2 minutes when x1x_1 rises by one unit while x2x_2 stays fixed. The data never vary one index while the other stays fixed, so, as with any collinear features, they cannot decide how to split the credit between the two, and they say nothing about the effect of changing a real workload. Units matter as well. Measuring the first index in units 100 times smaller multiplies its values by 100 and divides its coefficient by 100, to 0.02, without changing a single prediction.

Permutation importance

Definition Let ff be a fitted model, DD an evaluation data set and L(f,D)L(f, D) a loss of ff on DD, such as the mean squared error, with lower values better. The permutation importance of feature jj is the increase in loss when the column of feature jj in DD is replaced by a random permutation σ\sigma of itself, with the model and the other columns unchanged,

Ij=L(f,Dσ(j))−L(f,D),I_j = L\bigl(f, D_{\sigma}^{(j)}\bigr) - L(f, D),

usually averaged over several random permutations and reported with its spread. With a score where higher is better, the importance is the drop in score. It depends on the fitted model, the loss or score, the evaluation data and the permutations drawn. Computed on training data, it shows what the model uses to fit the training rows, overfit patterns included. Computed on held-out data, it shows the reliance that matters for predicting new data from the same distribution. Permuting a column breaks its association with the target and with the other features, so with correlated features the shuffled rows can be combinations that never occur in real data.

In plain words Shuffle one column and see how much worse the predictions become. A large increase means that this model, on these data, relies on that feature. It does not mean that the feature causes the outcome. When two features carry the same information, a model can rely on either one, so a feature with zero importance may still be strongly related to the target. Permuting a group of correlated features together asks how much the model relies on the group, which avoids splitting credit inside it.

Example With the mean squared error as the loss, ff has loss 0 on the four rows. Reversing the first column to 3, 2, 1, 0 and keeping the second gives predictions 6, 5, 4 and 3 against durations 0, 3, 6 and 9, so the errors are 6, 2, −2-2 and −6-6 and the loss is

36+4+4+364=20\frac{36 + 4 + 4 + 36}{4} = 20

squared minutes. Reversing the second column instead gives predictions 3, 4, 5 and 6, errors 3, 1, −1-1 and −3-3 and a loss of 5. The reversal is one chosen ordering. Averaged over all 24 orderings of four rows, the increases are 10 and 2.5. The model g=3x2g = 3x_2 makes the same predictions on the data but ignores x1x_1, so permuting x1x_1 never changes them and its importance is 0, while reversing x2x_2 raises the loss of gg by 45. Two models with identical predictions on the data get opposite importance rankings.

Partial dependence

Definition For a fitted model ff, a feature jj and evaluation rows x1,…,xn\mathbf{x}_1, \dots, \mathbf{x}_n, the partial dependence of ff on feature jj at the value vv is the average prediction after setting feature jj to vv in every row and keeping the other features of each row,

PD⁡j(v)=1n∑i=1nf(v,xi,−j),\operatorname{PD}_j(v) = \frac{1}{n} \sum_{i=1}^{n} f(v, \mathbf{x}_{i,-j}),

where xi,−j\mathbf{x}_{i,-j} holds the other features of row ii. Its population version averages over the marginal distribution of the other features, not over their distribution given Xj=vX_j = v. When the features are dependent, the average therefore includes combinations of vv with other values that rarely or never occur, and the curve need not equal the conditional mean prediction E[f(X)∣Xj=v]E[f(\mathbf{X}) \mid X_j = v].

In plain words Partial dependence asks what the model predicts on average if this one input is set to vv for every row and nothing else is changed. It summarizes the model’s formula, averaged over the data, and it can show a clean trend in regions where the model has never seen data. It is not an estimate of what would happen if the feature were changed in the world, and it is not the average outcome among cases that actually have that value.

Example For ff, setting x1=vx_1 = v in every row gives the predictions 2v+xi22v + x_{i2}, and the second column has mean 1.5, so

PD⁡1(v)=2v+1.5.\operatorname{PD}_1(v) = 2v + 1.5 .

At v=2v = 2 this is 5.5 minutes. The only observed row with x1=2x_1 = 2 has x2=2x_2 = 2 and prediction 6 minutes. The average of 5.5 also uses the pairs (2,0)(2, 0), (2,1)(2, 1) and (2,3)(2, 3), which lie off the line x1=x2x_1 = x_2 where all the data sit. For g=3x2g = 3x_2 the partial dependence on x1x_1 is flat at 4.5, although gg makes the same predictions as ff on every observed row.

Individual conditional expectation

Definition The individual conditional expectation curve, or ICE curve, of row ii for feature jj is the model’s prediction as feature jj varies while the other features of that row stay at their observed values,

ICE⁡i(v)=f(v,xi,−j).\operatorname{ICE}_i(v) = f(v, \mathbf{x}_{i,-j}).

The partial dependence curve is the average of the nn ICE curves. Because the curves are kept separate, differences in their shapes show where the effect of feature jj in the model depends on the values of other features, which is an interaction. ICE curves pass through the same constructed combinations as partial dependence, so they share its limits when features are dependent.

In plain words An ICE plot draws one line per row instead of one average line. Parallel lines mean that the model responds to the feature in the same way for every row, apart from a shift, and lines with different shapes mean that it responds differently. An average of opposite trends can be flat, so a flat partial dependence curve does not show that the model ignores the feature.

Example For ff the ICE curves of x1x_1 are 2v2v, 2v+12v + 1, 2v+22v + 2 and 2v+32v + 3, four parallel lines with slope 2 whose average is the partial dependence curve 2v+1.52v + 1.5. For contrast, take the constructed model h(x)=x1x2h(\mathbf{x}) = x_1 x_2 evaluated on two rows with x2=−1x_2 = -1 and x2=1x_2 = 1. The ICE curves of x1x_1 are −v-v and vv, and their average is 0 for every vv, although the prediction of hh changes with x1x_1 in each row.

SHAP values

Definition SHAP values, short for Shapley additive explanations, split one prediction f(x)f(\mathbf{x}) into a base value plus one contribution per feature. Let NN be the set of the MM features, and let a value function v(S)v(S) give the model’s expected prediction when only the features in a coalition S⊆NS \subseteq N are known, so that v(N)=f(x)v(N) = f(\mathbf{x}) and v(∅)v(\varnothing) is the base value. Write Δj(S)=v(S∪{j})−v(S)\Delta_j(S) = v(S \cup \{j\}) - v(S) for the gain when feature jj joins the coalition SS. The SHAP value of feature jj is its Shapley value

ϕj=∑S⊆N∖{j}wS Δj(S),wS=∣S∣! (M−∣S∣−1)!M!,\begin{aligned} \phi_j &= \sum_{S \subseteq N \setminus \{j\}} w_S \, \Delta_j(S), \\[0.4em] w_S &= \frac{\lvert S \rvert!\,(M - \lvert S \rvert - 1)!}{M!}, \end{aligned}

a weighted average of the gains, with weights that add to 1. It equals the average gain of feature jj over all M!M! orders in which the features can be added. The contributions add up exactly,

f(x)=v(∅)+∑j=1Mϕj.f(\mathbf{x}) = v(\varnothing) + \sum_{j=1}^{M} \phi_j .

With two features, each of the two orders has weight 1/21/2. The values depend on the model, the explained input, the background distribution that defines vv and the rule used for unknown features.

In plain words Add the features one at a time, starting from the base value, and record how much the expected prediction moves when feature jj arrives. Its SHAP value is that movement averaged over all orders. The contributions say how this model’s prediction for this input differs from a reference prediction, under a stated meaning of an unknown feature. A positive contribution is not advice to raise the feature, and it is not a causal effect.

Example Explain ff at x=(3,3)\mathbf{x} = (3, 3), where it predicts 9 minutes, using the four rows as background and filling each unknown feature with its values in the background rows. The base value is the average prediction 4.5. Knowing only x1=3x_1 = 3 gives the average of 6+xi26 + x_{i2}, which is 7.5. Knowing only x2=3x_2 = 3 gives the average of 2xi1+32x_{i1} + 3, which is 6, and knowing both gives 9. With the two features N={1,2}N = \{1, 2\},

ϕ1=12[v({1})−v(∅)]+12[v(N)−v({2})].\begin{aligned} \phi_1 &= \tfrac12 \bigl[v(\{1\}) - v(\varnothing)\bigr] \\[0.4em] &\quad + \tfrac12 \bigl[v(N) - v(\{2\})\bigr]. \end{aligned}

Feature 1 gains 7.5−4.5=37.5 - 4.5 = 3 when it comes first and 9−6=39 - 6 = 3 when it comes second, so ϕ1=3\phi_1 = 3. Feature 2 gains 1.5 in either order, so ϕ2=1.5\phi_2 = 1.5, and 4.5+3+1.5=94.5 + 3 + 1.5 = 9. For any linear model b+∑jβjxjb + \sum_j \beta_j x_j, this filling rule gives ϕj=βj(xj−xˉj)\phi_j = \beta_j (x_j - \bar{x}_j), with xˉj\bar{x}_j the background mean, here 2⋅1.5=32 \cdot 1.5 = 3 and 1⋅1.5=1.51 \cdot 1.5 = 1.5.

Background distribution

Definition The background distribution BB of an explanation is the reference distribution of inputs, usually a sample of rows, that the method uses in place of features it treats as unknown or replaced. It also fixes the base value. Under the marginal rule, also called interventional, the known features keep the values of x\mathbf{x} and the others come from background rows Z\mathbf{Z},

v(S)=EZ∼B[f(xS,ZSˉ)],v(S) = E_{\mathbf{Z} \sim B}\bigl[f(\mathbf{x}_S, \mathbf{Z}_{\bar{S}})\bigr],

where Sˉ\bar{S} is the set of features outside SS. Under the conditional rule, the unknown features follow their distribution given the known ones,

v(S)=EB[f(X)∣XS=xS],v(S) = E_B\bigl[f(\mathbf{X}) \mid \mathbf{X}_S = \mathbf{x}_S\bigr],

which in practice has to be estimated. Partial dependence and permutation importance also rely on a reference set, the evaluation rows. A different background generally gives a different base value and different contributions, and the choice should match the comparison the explanation is meant to make.

In plain words A local explanation always compares a prediction with something, and the background is that something. Explaining a prediction against all past jobs, against jobs of the same type or against one typical job gives different numbers, and each can be computed correctly. The marginal rule asks how the model’s formula responds when features are swapped in, even into combinations the data never show. The conditional rule asks how the expected prediction changes as feature values become known, so correlated features tend to share credit.

Example For ff at (3,3)(3, 3) with the four rows as background, the conditional rule notes that the two indices always agree, so knowing either one equals 3 implies the other does too, and v({1})=v({2})=9v(\{1\}) = v(\{2\}) = 9. Then ϕ1=12(9−4.5)+12(9−9)=2.25\phi_1 = \tfrac12 (9 - 4.5) + \tfrac12 (9 - 9) = 2.25, and likewise ϕ2=2.25\phi_2 = 2.25. The model g=3x2g = 3x_2 gets the same 2.25 and 2.25 under the conditional rule, because that rule only uses predictions on rows like the observed ones, while the marginal rule gives gg the contributions 0 and 4.5. Replacing the background by the single row (0,0)(0, 0) under the marginal rule changes the base value of ff to 0 and its contributions to 6 and 3. All of these add up to the same prediction 9, and they answer different questions.

Check yourself

  1. A constructed model is f(x)=1+2x1+3x2f(\mathbf{x}) = 1 + 2x_1 + 3x_2, the background means are 1 for x1x_1 and 2 for x2x_2, and the input to explain is (3,1)(3, 1). Under the marginal rule, find the base value, both SHAP values and the prediction, and check that they add up. Is the positive contribution of x1x_1 a reason to raise x1x_1?
Show the answer

For a linear model under the marginal rule, the base value is the prediction at the background means, 1+2⋅1+3⋅2=91 + 2 \cdot 1 + 3 \cdot 2 = 9, and only the background means matter. The contributions are

ϕ1=2 (3−1)=4,ϕ2=3 (1−2)=−3.\begin{aligned} \phi_1 &= 2\,(3 - 1) = 4, \\[0.4em] \phi_2 &= 3\,(1 - 2) = -3 . \end{aligned}

Their sum with the base value is 9+4−3=109 + 4 - 3 = 10, which matches the direct prediction 1+2⋅3+3⋅1=101 + 2 \cdot 3 + 3 \cdot 1 = 10.

The contribution 4 says that this model’s prediction for this input is 4 above the reference because x1x_1 is 3 rather than the background mean 1, under the marginal rule. It describes the model, not the world. Whether raising x1x_1 in a real process would change the outcome is a causal question, and the model’s coefficient can differ from the real effect when x1x_1 is correlated with other causes or when the data never varied it alone.

  1. A report on the workload model f=2x1+x2f = 2x_1 + x_2 says that the importances 20 and 5 from reversing each column show that index 1 is four times as important as index 2, and that cutting index 1 would shorten jobs the most. Find the reversal importances for g=3x2g = 3x_2, which fits the same data exactly, and for both models with the two columns reversed together. What is wrong with the report?
Show the answer

Reversing x1x_1 leaves the predictions of gg unchanged, so its importance is 0. Reversing x2x_2 gives predictions 9, 6, 3 and 0 against durations 0, 3, 6 and 9, errors 9, 3, −3-3 and −9-9, and a loss of

81+9+9+814=45.\frac{81 + 9 + 9 + 81}{4} = 45 .

Reversing both columns together keeps every row on the line x1=x2x_1 = x_2, so both models predict 9, 6, 3 and 0 and both get the importance 45.

The report treats a property of one fitted model as a property of the features. The two indices are identical in the data, so the split of credit between them is arbitrary, and ff and gg give opposite rankings with the same predictions. Reversing one column also creates rows the data never contain. The grouped importance of 45 is the same for both models and says that the predictions rely on the shared workload information. The causal claim is unsupported in any case. Permutation importance measures how much the predictions of this model degrade under a shuffle, and the data never varied one index alone, so neither the importances nor the coefficients show what cutting a real workload would do.

  1. Three people ask about the workload model. A developer suspects that the model uses a column recorded only after each job finished. A customer wants to know why their job received a 9-minute estimate. A manager wants to know whether reducing index 1 would shorten jobs. Which kind of explanation fits each request, and what must be stated with it?
Show the answer

The developer needs a global view of what the model relies on. Permutation importance on held-out data, repeated over several permutations and with correlated columns permuted as groups, shows whether the predictions depend heavily on the suspicious column. The check should be paired with a review of when each column becomes available, since importance cannot by itself prove a leak.

The customer needs a local explanation of one prediction, for example SHAP values. The report should state the base value, the background it comes from, such as recent jobs of the same kind, and the rule for unknown features, and it should say that the contributions describe the model’s estimate, not the causes of the job’s duration.

The manager is asking a causal question that no summary of a predictive model answers. Coefficients, importances, partial dependence and SHAP values all describe the fitted model on its data. Answering the manager needs evidence about interventions, such as a randomized trial of reduced workloads or a causal analysis with stated assumptions.

How this lesson connects