Global versus local explanations
Quick answer
A global explanation describes a model across a specified population; a local explanation describes one prediction relative to a stated reference. Neither automatically establishes why an outcome happened. Static examples tested locally with Python 3.13.5, scikit-learn 1.8.0 SciPy 1.17.0 and NumPy 2.3.5 where imported. ByteMind package execution is unverified.
Explain a single prediction
w=[2,-1]; r=[1,2]; x=[3,0]; b=5base=b+sum(a*c for a,c in zip(w,r))parts=[a*(c-d) for a,c,d in zip(w,x,r)]print(base,parts,base+sum(parts))Observed local output:
5 [4, 2] 11Relative to the reference, both changes increase the prediction.
How it works
Start with a question: are we auditing typical behavior, one unusual prediction, or model performance? For a linear regression f(x)=b+sum(w_jx_j), the coefficient w_j is the change in predicted output for a one-unit increase in x_j while holding other inputs fixed. For reference vector r, the local contributions w_j(x_j-r_j) add to f(x)-f(r). These signed terms are in output units. A global mean absolute contribution averages |w_j*(x_j-r_j)| over a specified dataset; it hides direction but captures typical magnitude. Coefficients depend on units, and correlated inputs make holding others fixed questionable. For logistic regression the analogous decomposition is in log-odds, not probability units. An explanation can faithfully describe a poor model, so report held-out performance and the scope of the explanation first. For an industrial sensor model, use a training-derived reference rather than a convenient test observation. Explain two contrasting rows and compare with the population summary.
Aggregate signed and absolute contributions
rows=[[4,2],[-2,-2],[0,0]]print([round(sum(v)/len(v),2) for v in zip(*rows)])print([round(sum(map(abs,v))/len(v),2) for v in zip(*rows)])Observed local output:
[0.67, 0.0][2.0, 1.33]The second feature has zero mean signed contribution but nonzero typical magnitude.
Common mistakes
Never infer causal effects or fairness from a large coefficient. Do not mix contributions on logit and probability scales or interpret a single example as a population average. A near-zero contribution may mean the feature is near its reference, not that the feature is useless.
Practice and next steps
For f(x)=5+2*x1-x2, reference [1,2], explain predictions at [3,0] and [0,4]. Compare their absolute contributions. Complete the knowledge check and staged exercise. Next: Permutation importance.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Global versus local explanations — knowledge check
Apply global versus local explanations to new scenarios.
Which is a local explanation?
What must linear contributions sum to?
A coefficient doubles after changing units. What follows?
A logit contribution of 2 means?
A perfectly faithful explanation of a bad model is?