Global vs Local Explanations
Welcome to Model Interpretability. A model that only spits out numbers is hard to trust and impossible to act on. This course teaches you to open the box and explain what a model is doing, in plain terms a colleague or a customer can follow.
Here is the situation we will use all the way through. A telecom has trained a model that scores each customer on how likely they are to leave (to "churn"). This morning it flagged Ravi, a customer who is 3 months in, pays $105 a month, and has called support 4 times. His score: 0.96, very likely to leave.
Two colleagues walk over with two very different questions:
- The product lead asks: "In general, what makes our customers leave?"
- Ravi's account manager asks: "Why did the model flag Ravi in particular?"
Those are not the same question, and they do not have the same answer. One is global (about the whole model), the other is local (about one prediction). Telling them apart, and answering each correctly, is the foundation everything else in this course builds on.
By the end you will be able to:
- Tell a global question (about the whole model) from a local one (about one prediction)
- Read a global feature-importance ranking, and say what it does and does not tell you
- Split a single prediction into per-feature pushes that add back to exactly that prediction
- Explain how the same feature can matter one way overall yet push the opposite way for one person
Prerequisites: you can fit and use a predictive model in R and read its output, and you know what a feature and a prediction are (any earlier Data Scientist lesson, for example The Bias-Variance Tradeoff).
The picture below is a preview of a local explanation: one customer's score, taken apart feature by feature. We will build up to reading it.
Two questions about one model
Every question you can ask a trained model falls into one of two buckets.
A global explanation describes the model as a whole, summarized over all the data it was trained on. "Which features does this churn model lean on the most?" is global. The answer is one story about the model, and it does not change from customer to customer.
A local explanation is about a single prediction. "Why did the model score Ravi at 0.96?" is local. The answer is specific to Ravi and his particular feature values, and it can look completely different for the next customer.
Here they are side by side, on our churn model:
| Global explanation | Local explanation | |
|---|---|---|
| The question | What has the model learned overall? | Why did it make THIS one prediction? |
| Scope | The whole model, across all 500 customers | One customer, one prediction |
| Example | Which features drive churn in general? | Why was Ravi scored 0.96? |
| Who asks | A data scientist auditing the model, a product lead | The customer, a support agent, a regulator |
The model we will explain
Before we explain a model, we need one in front of us. Each lesson here runs in a fresh R session, so we build the customer data right now (run this once). Each row is one customer; each column is something the company knows about them.
So about 38% of these customers left. Now we fit the model. To keep every explanation exact and easy to see, we use a deliberately simple, fully transparent model: a straight-line (linear) fit that predicts the 0/1 "churned" outcome from the six features. It gives each customer a churn score.
There it is: the model scores Ravi at 0.963. That single number is the thing a local explanation will take apart. First, though, let us zoom all the way out and ask the global question.
Global: what did it learn overall?
The global question is: across all 500 customers, which features does this model rely on the most? For a linear model, the answer lives in the size of each coefficient (each feature's slope). A big slope means the feature moves the prediction a lot; a slope near zero means the feature barely matters.
There is one catch. A slope is measured in the feature's own units. The monthly slope is "churn per extra dollar," while the support_calls slope is "churn per extra call." A dollar and a call are not comparable, so raw slopes cannot be ranked directly. We fix this by multiplying each slope by how much its feature actually varies across customers, its standard deviation. That puts every feature on a common "typical swing" scale:
\\( I_j = |\beta_j| \, s_j \\)
where \\( \beta_j \\) is the model's coefficient (slope) for feature \\( j \\), and \\( s_j \\) is the standard deviation of feature \\( j \\) across the 500 customers. \\( I_j \\) is that feature's global importance: the size of the push it typically applies.
Read top to bottom, that is the model's overall story: tenure matters most, then the monthly bill, then support calls; add-ons barely register. The chart shows the same ranking:
This ranking is genuinely useful. It tells you where the model's attention goes, which features are worth collecting well, and where to look first. But be careful about what it does not say.
What the ranking tells you
The global ranking above puts tenure at the top. What does that let you conclude?
Local: why THIS prediction?
Now the other question: why did the model score Ravi at 0.963, and not the average? A local explanation answers it by starting from a neutral baseline and then adding one signed push for each feature.
- The baseline, written \\( \phi_0 \\), is the model's average prediction across all customers. It is where you would start if you knew nothing about a particular person. For our model the baseline is the base churn rate, about 0.38.
- Each feature then contributes a push, written \\( \phi_j \\) for feature \\( j \\). A push can be positive (raises the score) or negative (lowers it).
Add the baseline and all the pushes and you land exactly on the prediction:
\\( \hat f(x) = \phi_0 + \sum_{j=1}^{p} \phi_j \\)
Here \\( \hat f(x) \\) is the model's prediction for this customer \\( x \\), \\( \phi_0 \\) is the baseline, \\( \phi_j \\) is feature \\( j \\)'s push, and \\( p \\) is the number of features (6 for us). That "everything sums back to the prediction" property is the whole point: it means the explanation leaves nothing out.
For our linear model each push has a simple, exact form:
\\( \phi_j = \beta_j \, (x_j - \bar x_j) \\)
In words: a feature's push is its slope \\( \beta_j \\) times how far this customer's value \\( x_j \\) sits from the average value \\( \bar x_j \\). A customer who is exactly average on a feature gets a push of zero from it; the further from average they are, the bigger the push. The widget on the cover was one of these breakdowns: a baseline, a stack of signed pushes, adding up to one prediction. Let us compute Ravi's for real.
Add up Ravi's pushes
Ravi is far from average in a few ways: he is very new (tenure 3 against a typical 30-ish), his bill is high, and he has called support more than most. Each of those becomes a push. Using the formula \\( \phi_j = \beta_j (x_j - \bar x_j) \\):
Read Ravi's story straight off the pushes: being new (tenure, +0.207), having made several support calls (+0.190), and a high monthly bill (+0.140) each shove his risk up hard. Being on a month-to-month plan (annual = 0) adds a bit more (+0.072). Nothing pulls him down much. Start at the 0.382 baseline, pile on those pushes, and you should land back on his 0.963 score.
Rebuild Ravi's score
baseline (0.382) and ravi_push (his six pushes) are already in memory from the last step. Reconstruct Ravi's prediction by starting at the baseline and adding all of his pushes. You should get back the exact 0.963 the model gave him.
Show answer
prediction <- baseline + sum(ravi_push)
round(prediction, 3)
#> [1] 0.963Global is not local
Here is the trap that catches people. It is tempting to read the global ranking, see tenure at the top, and conclude "so tenure is why the model flags people." That is wrong, and one more customer shows why.
Meet Meera: a 52-month loyal customer (long tenure), a $95 bill, but 9 support calls this year. The model flags her too, at 0.94. Let us break down her prediction the same way:
Look at what drives Meera versus what drives the model overall:
| Feature | Global rank | Ravi's push | Meera's push |
|---|---|---|---|
| tenure | 1st (strongest overall) | +0.207 (he is new) | -0.177 (she is loyal) |
| monthly bill | 2nd | +0.140 | +0.102 |
| support calls | 3rd | +0.190 | +0.577 (drives her flag) |
| annual contract | 4th | +0.072 | +0.072 |
For Meera, tenure, the model's number-one global feature, actually pushes her risk down: she is loyal, so it protects her. What flags her is support calls, which ranks only third globally but dominates her prediction. The global ranking and Meera's local explanation point at different features, and neither is wrong.
The same feature, two directions
Tenure is the model's number-one global feature, yet for Meera it pushed her churn score down. How can both be true at once?
Which explanation do you need?
Global and local are not competitors; they answer different questions. The skill is reaching for the right one. A quick guide:
| You want to... | Use | Why |
|---|---|---|
| Decide which features to keep or collect better | Global | It ranks features across the whole model |
| Audit what a model relies on before you ship it | Global | It describes the model's overall behaviour |
| Tell a customer why they were flagged | Local | It is about their one prediction |
| Write a loan-decline or adverse-action notice | Local | The law asks for the reasons behind that decision |
| Debug one surprising prediction | Local | You need that row's own drivers |
Often you want both: a global ranking to understand the model, then a local explanation whenever a single decision has to be justified. The rest of this course fills in the modern tools for each: permutation importance for global (Lesson 2), SHAP for exact local explanations on any model (Lesson 3), and partial dependence for the shape of a feature's effect (Lesson 4).
Match the question to the explanation
Ravi phones in and asks: "Why did your system flag ME as likely to leave?" Which explanation answers him?
References
- Molnar, Interpretable Machine Learning - the standard free reference; its global-versus-local split is the frame for this whole course.
- iml: Interpretable Machine Learning in R - one package that computes both global importance and local explanations for any model you fit.
- Lundberg and Lee (2017), A Unified Approach to Interpreting Model Predictions (SHAP) - the additive local breakdown you met here, made exact for any model; the subject of Lesson 3.
- Ribeiro, Singh and Guestrin (2016), Why Should I Trust You? (LIME) - the first widely used model-agnostic local explanation.
- Breiman (2001), Random Forests - introduces the variable-importance idea behind most global rankings.
Lesson complete
You now have the distinction that the rest of this course rests on. Global explanations describe the whole model over all its data; local explanations take apart one prediction. You read a feature-importance ranking (\\( I_j = |\beta_j| s_j \\)), broke Ravi's score into pushes that summed back exactly to 0.963 (\\( \hat f(x) = \phi_0 + \sum_j \phi_j \\)), and saw with Meera why the top global feature can be the wrong reason for a single flag.
You also saw a soft spot: our global ranking came from reading a linear model's coefficients, which only works because the model is a straight line. Lesson 2, Permutation and Drop-Column Importance, gives you a global-importance method that works for any model, a random forest, a boosted tree, a neural net, and shows the ways it can quietly mislead you.