Skip to chapter content
navan✳THE BUILD LABMACHINE LEARNING / GUIDE
0/28 read
CHAPTER 25 / 28 · RESPONSIBLE SYSTEMS

What a prediction can explain.

Distinguish a model's internal reasons, feature effects, uncertainty, and causal claims.

BY NAVAN SAMILONG READTHEORY FIRST
01 / FROM THE BEGINNING

Start with the meaning.

A prediction can be accurate without being understandable, and an explanation can be understandable without being faithful. A linear model exposes coefficients, a small tree exposes paths, and a neighbor model can show similar cases. Each explains the fitted rule under its own representation. None automatically explains why the world produced the outcome. If a model predicts late delivery because a route is long, shortening the route may help, but the coefficient alone does not establish that intervention's effect.

Global interpretation asks how a model behaves across many cases. Local interpretation asks why one particular input received one particular prediction under the fitted model. A feature may be important overall but irrelevant to a specific case. Conversely, one unusual case may depend on a feature that usually matters little. Both views need a clearly defined reference population and representation.

02 / THE MODEL

How the idea works.

Permutation importance measures how much a chosen evaluation score worsens when one feature's values are shuffled across rows. It is calculated on held-out data, after the model has been fitted. If shuffling a feature changes predictions and hurts the score, the fitted model relies on information in that feature under the tested distribution. Correlated features complicate interpretation: shuffling one may have little effect because another carries similar information, or may create unrealistic combinations of values.

Partial dependence averages predictions while varying one feature over a range, holding the distribution of other observed features in a particular way. It can reveal modeled trends but may ask the model to predict impossible combinations, such as a very young age with decades of work history. Individual conditional expectation curves show per-case variation that an average can hide. These tools inspect model behavior; they do not prove intervention effects.

Uncertainty has several sources. A classifier may return a probability estimate whose calibration needs checking. A regression model may provide an interval from a separate method. A new input may lie far outside the training distribution, where any estimate is less supported. Explaining a result responsibly includes naming those limits. A seemingly precise prediction should not be presented as certain merely because it is a single number.

03 / PYTHON, EXPLAINED

Follow the code.

interpreting-models.py
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.inspection import permutation_importance
from sklearn.model_selection import train_test_split

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, random_state=0, stratify=y
)
model = RandomForestClassifier(random_state=0).fit(X_train, y_train)
result = permutation_importance(model, X_test, y_test, random_state=0)
print(result.importances_mean)

The data is split so the forest fits on training rows and interpretation uses held-out rows. permutation_importance measures the model's baseline score, then repeatedly shuffles one test feature column at a time and measures how much the score changes. importances_mean contains one average score decrease per feature. A larger positive value means this fitted model depended more on that feature for this test set and metric. It does not say that changing the flower's physical feature would cause its species to change.

The output can vary with random splits, model fits, and small sample size. If two columns carry nearly the same signal, either may appear less important when shuffled alone because the other remains. The result is therefore a diagnostic under stated conditions, not a permanent ranking of nature's causes.

04 / THE BOUNDARY

What the result does not say.

Interpretability should be matched to the decision. A person reviewing a low-stakes recommendation may need a short reason and an easy correction path. A high-stakes decision may require a documented feature set, error analysis, and appeal process. The model's technical explanation is only one part of that system.

A transparent baseline can be preferable to a complex model with a small score advantage. Complexity changes how failures are found and how behavior is communicated. Choosing it is a product and governance decision as well as a statistical one.

05 / KEEP THIS

One clear idea.

Interpretation describes the fitted model under a dataset; it is not automatically a causal story about the world.

THE CODE IN CONTEXT

The ML cookbook

Complete, explained Python workflows sit alongside this reading course.

Browse the cookbook
Finished reading?
Built with curiosity. By Navan Sami. ↗Machine learning with Python · From examples to trustworthy models.