Notes

Partial Dependence Plot (PDP)

A trained model can feel like a black box: you change an input feature and the prediction changes, but it’s hard to see the pattern. A Partial Dependence Plot (PDP) is a way to “peek” at that pattern by showing how the model’s prediction shifts as one feature (or a pair of features) varies.

What a PDP shows

A PDP estimates the average effect of a feature on the model output. For a feature x, it works by:

  • Choosing a grid of values for x (e.g., interest rate from 2% to 20%).
  • For each grid value, replacing x with that value for every row in your dataset.
  • Running the model on these modified rows and averaging the predictions.

The resulting curve answers: “If everyone had this value of x, what would the model predict on average?” For classification, the y-axis is typically predicted probability; for regression, it’s the predicted target value.

Why it matters (and where it can mislead)

PDPs are a global explanation: they summarize model behavior across the dataset, which helps with sanity checks and stakeholder communication. But they can be misleading when features are strongly correlated. If “income” and “job level” move together, forcing income to extreme values while holding job level fixed creates unrealistic data, and the averaged effect can look wrong. PDPs also hide heterogeneity: different subgroups can have different responses even if the average looks smooth.

Practical examples and tooling

  • Credit scoring: plot partial dependence of “debt-to-income ratio” to see where predicted default risk rises sharply.
  • Churn prediction: visualize how “months since last login” affects churn probability.
  • House prices: check how “square footage” impacts predicted price and where returns diminish.
from sklearn.inspection import PartialDependenceDisplay
PartialDependenceDisplay.from_estimator(model, X, features=["debt_to_income"])

A Partial Dependence Plot (PDP) visualizes the average relationship between a selected feature (or feature pair) and a model’s predicted outcome, marginalizing over the distribution of other features. It provides a global, model-agnostic view of how predictions change as the feature varies (e.g., predicted risk vs. age). PDP matters because it helps validate learned patterns, detect nonlinearity and thresholds, and communicate model behavior for debugging and governance.

Imagine you’re adjusting one knob on a complex stereo system and watching how the sound changes, even though lots of other settings are also in play. A Partial Dependence Plot (PDP) does something similar for an AI model: it shows how changing one input (like “age” or “income”) tends to change the model’s prediction (like “risk of default” or “house price”).

It’s called “partial” because it averages out the effects of all the other inputs, so you can see the general trend. PDPs are used to sanity-check models and spot surprising relationships, like a prediction jumping sharply after a certain threshold.