What is a Partial Dependence Plot?
A Partial Dependence Plot (PDP) is a model-agnostic visualization technique used to understand the relationship between a subset of input features and the predicted outcome of a fitted machine learning model. In simpler terms, PDPs help us see how changes in certain features (one at a time, or a small group together) affect the model’s predictions on average, while holding the influence of other features approximately constant.
By showing the average effect of a particular feature (or pair of features), PDPs can answer questions like:
- “As we increase feature X, does the predicted probability of a positive outcome also increase?”
- “Are there certain thresholds or ranges of feature X where the model’s predicted outcome changes dramatically?”
Unlike feature importance methods (which tell you how much a feature matters overall), PDPs reveal the shape of the relationship—e.g., linear, monotonic, U-shaped, or more complex patterns—between feature values and predicted response.
How PDPs Work
- Conceptual Foundation:
Consider a trained model $f$ that maps features $X = (X_1, X_2, \ldots, X_p)$ to predictions $\hat{y}$. Suppose you want to understand how $f$’s predictions change with different values of a single feature $X_j$. The partial dependence function $\bar{f}_j$ for feature $X_j$ is defined as the expected prediction of the model as $X_j$ varies over its range, while all other features are averaged out over their distribution in the data.Formally, for a single feature $X_j$:
$$
\bar{f}_j(x_j) = E_{X_{-j}}\left[ f(x_j, X_{-j}) \right]
$$
Here, $X_{-j}$ represents all other features except $X_j$, and the expectation (average) is taken over the joint distribution of $X_{-j}$ as observed in the dataset.For two features $X_j$ and $X_k$, the partial dependence function is:
$$
\bar{f}_{j,k}(x_j, x_k) = E_{X_{-j,k}}\left[ f(x_j, x_k, X_{-j,k}) \right]
$$ - Estimation from Data:
To estimate $\bar{f}_j(x_j)$ from the training dataset, you:- Select a grid of values for $x_j$ across the range observed for that feature.
- For each chosen value $x_j^{*}$ in the grid:
- Replace the $j$-th feature in every instance of the dataset (or a representative subset) with $x_j^{*}$.
- Use the trained model fff to predict the outcome for all these modified instances.
- Average all these predicted values to get a single number representing the model’s average prediction when $X_j = x_j^{*}$ and other features follow their original distribution.
Interpretation
- Monotonicity and Non-Linearities:
By looking at a PDP, you can determine if increasing a feature is always associated with an increase or decrease in the predicted outcome (a monotonic relationship), or if there are more complex patterns like plateaus, inflection points, or even dips and peaks. - Feature Thresholds:
Sometimes PDPs reveal thresholds or “sweet spots.” For example, the model might only boost predictions if a certain feature exceeds a certain critical value, beyond which the predictions remain stable or even decline. - Interaction Insights (via 2D PDPs):
With two features, a 2D PDP can show whether their joint effect on the prediction is additive or if complex interactions exist. If the surface is smoothly separable along one feature dimension, it suggests no strong interaction; if the shape changes depending on the value of the other feature, it indicates a feature interaction that affects predictions. - Magnitude and Vertical Scale:
The vertical axis of a PDP typically shows predicted response on the original scale (e.g., probability for classification, predicted value for regression). The absolute values may help you understand the baseline prediction and how much variation is introduced by changing this particular feature. - Caution in Interpretation:
PDPs show average effects. Even if the PDP suggests that increasing a feature leads to higher predictions on average, individual instances might not follow this pattern due to feature interactions not fully captured by averaging. Also, PDPs assume a certain level of independence. If the feature of interest is strongly correlated with other features, the results can be misleading.
Relationship to Other Explainability Tools
- Compared to Feature Importance:
- Feature Importance tells you if a feature matters, but not how it matters.
- Partial Dependence Plots show how predictions change as you vary the feature’s value, providing richer insights into the feature’s influence.
- Compared to Permutation Importance:
- Permutation Importance quantifies how predictive performance changes when the feature is randomized.
- PDPs highlight the structural relationship between feature values and predictions, allowing you to visualize patterns and shapes of effect, not just importance magnitude.
- Compared to Local Methods (LIME, SHAP):
- LIME and SHAP provide explanations for individual predictions (local interpretability).
- PDPs are global explanations, summarizing the model’s behavior across the entire dataset with respect to certain features. PDPs do not explain single predictions; they give a big-picture view.
- Compared to Accumulated Local Effects (ALE) Plots:
- ALE Plots are a refinement of PDPs designed to handle correlated features more gracefully and avoid some biases PDPs have in that scenario.
- While PDPs average over the joint distribution of other features (which can be problematic if the feature in focus rarely takes certain values independently of others), ALE tries to measure the isolated effect more robustly.
Handling Correlated Features and Limitations
- Correlation Issues:
PDPs assume that the distribution of other features remains fixed while you vary the feature of interest. If the feature of interest is strongly correlated with others, the hypothetical scenarios created by swapping feature values might be unrealistic (the model never saw such combinations during training). This can lead to misleading conclusions.In practice, ALE plots are often recommended when dealing with strongly correlated features. - Focus on 1D or 2D:
PDPs are most commonly used for one feature at a time or two features at a time. Higher-dimensional PDPs are theoretically possible but become hard to visualize and interpret. Therefore, PDPs help with low-dimensional interactions or understanding single features, not complex multi-way interactions. - Averaging Effects:
Because PDPs average predictions over the marginal distribution of the other features, they smooth out idiosyncratic behaviors that happen only in specific subregions of the input space. This is useful for understanding broad trends but can hide more subtle patterns.
Best Practices for Using PDPs
- Start Simple:
Begin by examining PDPs for a single important feature to get a feel for how the model responds to changes in that feature. - Check Both Train and Test Distributions:
Consider whether the feature values you examine with PDPs make sense. If you are plotting effects of feature values that barely appear in your training data, the PDP might be less reliable there. - Use with Complementary Tools:
Combine PDPs with other global methods (like permutation importance) and local methods (like SHAP) to get a more complete understanding. For instance, if PDP shows a certain trend, you might use SHAP to confirm that individual predictions also reflect that trend or identify exceptions. - Investigate Interactions via 2D PDPs:
If you suspect an interaction between two features is crucial, plot a 2D PDP. If the shape is not additive, it means how one feature affects predictions depends on the value of the other, a critical insight for model interpretation and potential model improvements. - Consider ALE Plots for Strongly Correlated Features:
If you know your features are strongly correlated, you may want to try ALE plots. ALE plots are often considered a better default due to their handling of correlation issues. You can still use PDPs, but interpret them with caution.
Example Scenario
Imagine a model that predicts house prices. If you create a PDP for the feature “House Size (in square feet)”:
- If the PDP line slopes upward, that suggests that as the house size increases, the predicted price increases as well—an intuitive result.
- If you notice a plateau after a certain size (e.g., beyond 4,000 sq ft, the price doesn’t go up much), that tells you that the model predicts diminishing returns on adding more square footage.
- If there’s a dip at small sizes, maybe the model learned that extremely small properties are usually not in desirable locations, lowering predicted price.
Such insights would be harder to glean from raw feature importance scores. The PDP shows you the nuanced relationship.
Conclusion
Partial Dependence Plots are a valuable tool in the model interpretability toolkit. They help you understand the average relationship between a feature (or pair of features) and the model’s predictions, providing insight into how changes in feature values affect the output. While PDPs come with assumptions and can be misleading in the presence of correlated features, they offer a clear, intuitive way to gain global understanding of a model’s behavior. Used in conjunction with other methods, PDPs can significantly enhance the interpretability and trustworthiness of complex machine learning models.