AI Strategy
ML Interpretability with PDP and ICE
Understand when and why interpretability matters in machine learning. Learn how Partial Dependence Plots (PDP) and Individual Conditional Expectation (ICE) plots reveal feature influence, variability, and model behavior for better storytelling and stakeholder trust.

Machine Learning Results: Interpretability in Post-Modeling
When interpretability is needed? How to solve it in storytelling with plots?
Introduction
Interpretability in post-modeling is crucial for understanding the dynamics between input features and output predictions in machine learning models. It helps identify the most important features, understand how these features affect predictions, and assess model sensitivity to certain features. This is particularly important in scenarios where model transparency is necessary for stakeholders to trust and act on the predictions.
Two powerful tools for achieving interpretability in post-modeling are Partial Dependence Plots (PDP) and Individual Conditional Expectation (ICE) plots. These techniques provide visual insights into the relationship between features and the model’s predictions.
PDPs show the average effect of a single feature on the predicted outcome, marginalizing over the effects of all other features. By plotting the predicted outcome against a range of values for a specific feature, PDPs help visualize how changes in that feature influence the model’s predictions. This is particularly useful for identifying the overall trend and direction of the feature’s impact on the outcome.
While PDPs provide an average effect, ICE plots delve deeper by showing the effect of a feature on the predicted outcome for individual data points. ICE plots display multiple lines, each representing the prediction for a single instance as the feature value changes. This allows for a detailed view of the variability in predictions and can highlight interactions and heterogeneity in the data that might be masked by PDPs.
Figure 1 — Partial Dependence Plot
Partial Dependence Plot (PDP):
- The PDP illustrates the relationship between the target variable and the first feature in the dataset, marginalizing over the effects of the other features.
- The x-axis represents the values of the first feature (Feature #0), and the y-axis represents the partial dependence (predicted effect) of the target variable on Feature #0.
Key Observations:
- The plot shows a clear upward trend, indicating that as the value of Feature #0 increases, the predicted value of the target variable also increases.
- There is a significant change in the partial dependence at around the value 0.2, which indicates that the model’s predictions are highly sensitive to changes in Feature #0 within this range.
- The plot flattens out after 0.6, indicating that beyond this point, changes in Feature #0 have a minimal effect on the target variable.
Deciles:
- The vertical tick marks along the x-axis represent the deciles of Feature #0, providing insight into the distribution of the feature values in the dataset.
- These deciles help understand where most of the data points lie and how the feature values are distributed.
The PDP provides valuable insights into how the feature affects the model’s predictions, helping to understand the model’s behavior and feature importance.
Here is the code used to generate the plot.
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_friedman1
from sklearn.ensemble import GradientBoostingRegressor
from sklearn.inspection import PartialDependenceDisplay
from sklearn.inspection import partial_dependence
# Generate synthetic data
X, y = make_friedman1()
# Train a Gradient Boosting Regressor
clf = GradientBoostingRegressor(n_estimators=10).fit(X, y)
# Define features and feature names
features, feature_names = [(0,)], [f"Features #{i}" for i in range(X.shape[1])]
# Define deciles for the feature
deciles = {0: np.linspace(0, 1, num=5)}
# Calculate partial dependence
pd_results = partial_dependence(clf, X, features=0, kind="average", grid_resolution=5)
# Create and plot Partial Dependence Display
display = PartialDependenceDisplay([pd_results], features=features, feature_names=feature_names, target_idx=0, deciles=deciles)
display.plot(pdp_lim={1: (-1.38, 0.66)})
# Show plot
plt.show()Individual Conditional Expectation ICE plots (Figure 2) are similar to PDPs, but they show the relationship between a feature and the predicted outcome for individual data points, rather than averaging over the entire dataset. This can reveal heterogeneity in the effect of the feature on the prediction.
Figure 2 — Individual Conditional Expectation Plot and Partial Depence Relation
The orange dashed line represents the partial dependence plot, which shows the average effect of the feature on the predicted outcome, marginalizing over the other features in the model.
The blue lines represent individual conditional expectation plots, which show the effect of the feature on the predicted outcome for individual data points. This provides insight into the variability of the model’s predictions for different instances.
Feature x0:
- Trend: The partial dependence (orange dashed line) suggests that the average predicted outcome decreases as
x0moves from negative to positive values, reaching a minimum aroundx0 = 0, and then increases slightly. - Variability: The ICE plots (blue lines) show a consistent pattern across different instances, with most lines following a similar trend as the partial dependence plot. This indicates that the effect of
x0on the predicted outcome is relatively uniform across different data points.
Feature x1:
- Trend: Similar to
x0, the partial dependence forx1indicates a decrease in the average predicted outcome asx1moves from negative to positive values, with a slight increase towards the end. - Variability: The ICE plots for
x1also show consistent patterns, suggesting that the effect ofx1on the predicted outcome is relatively uniform across different instances.
Interpretation of Key Points:
- Negative Influence: Both features
x0andx1appear to have a negative influence on the predicted outcome in the middle range, as indicated by the dip in the partial dependence plot. - Uniform Effect: The consistent pattern of ICE plots around the partial dependence line indicates that the effect of these features is similar across different data points, with some individual variability.
- Feature Importance: The partial dependence plot helps to understand the importance and influence of each feature on the model’s predictions. Both
x0andx1show significant influence, but the trends suggest a complex relationship that may be context-dependent.
Here is the code used to generate the plot.
from sklearn.datasets import make_hastie_10_2
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.inspection import PartialDependenceDisplay
X, y = make_hastie_10_2(random_state=0)
clf = GradientBoostingClassifier(n_estimators=100, learning_rate=1.0,
max_depth=1, random_state=0).fit(X, y)
features = [0, 1]
PartialDependenceDisplay.from_estimator(clf, X, features,
kind='individual')
PartialDependenceDisplay.from_estimator(clf, X, features,
kind='both')
PartialDependenceDisplay.from_estimator(clf, X, features,
kind='both', centered=True)The combination of Partial Dependence (PD) and Individual Conditional Expectation (ICE) plots provides a comprehensive understanding of how features x0 and x1 affect the predictions of the model. The uniform trends in ICE plots reinforce the insights gained from the PD plot, indicating consistent feature behavior across the dataset. This helps in interpreting the model's predictions and understanding the influence of specific features.
Conclusion:
When Interpretability is Needed?
- Stakeholders need to understand and trust the model’s decisions.
- Regulatory requirements mandate transparency in model predictions.
- The model is used in high-stakes decisions where understanding feature influence is critical.
How to Solve It in Storytelling with Plots?
Incorporating PDP and ICE plots in storytelling can effectively convey the interpretability of a model. These plots can illustrate:
- The overall trend and direction of feature influence (PDP).
- The variability and consistency in predictions for individual instances (ICE).
- Key insights into feature importance and model behavior.
By integrating these plots into presentations and reports, data scientists can provide clear and compelling narratives about how features impact model predictions, making the complex workings of machine learning models more accessible and understandable to non-technical stakeholders.
#I am happy to receive any feedback and claps about this article;
Please feel free to connect on Linkedin
#Please feel free to explore my portfolio on Github;
#Please follow me on medium to read my articles;
I write about #Machine Learning, #Data Science, #Energy, #Renewable Energy, #Artificial Intelligence, #Project Management, #Strategy, #Business Analytics, #Statistics and Probability


