While individual SHAP values, often visualized using force plots, provide explanations for single predictions, we frequently need a broader perspective on how features influence the model overall. SHAP offers powerful visualizations that aggregate information across many instances, helping us understand global feature importance and dependencies. Two fundamental plots for this purpose are the Summary Plot and the Dependence Plot.
SHAP Summary Plot
The SHAP Summary Plot offers a condensed view of both feature importance and the distribution of feature effects across the entire dataset (or a representative sample). It helps answer questions like: "Which features are most important overall?" and "Do high or low values of a feature tend to increase or decrease the model's prediction?"
Structure and Interpretation
A typical summary plot displays the following:
- Features: Each feature is listed vertically on the y-axis.
- Feature Importance: Features are ordered by their global importance, usually calculated as the mean absolute SHAP value across all instances. The most important feature is at the top.
- SHAP Value (Impact): The x-axis represents the SHAP value for a feature. Points to the right indicate a positive impact (pushing the prediction higher), while points to the left indicate a negative impact (pushing the prediction lower).
- Instance Representation: Each point on the plot corresponds to the SHAP value for a specific feature and a specific instance in the dataset.
- Feature Value Coloring: Points are colored based on the original value of the feature for that instance. Typically, a color scale (e.g., blue to red) indicates low to high feature values.
By observing the distribution and coloring of points for each feature, you can infer:
- Overall Importance: Features higher up the list have a larger average impact on the model's output magnitude.
- Impact Direction: The horizontal spread shows the range of impacts. If points for a feature are mostly on the right, it generally increases the prediction; if mostly on the left, it decreases it.
- Value Correlation: The color gradient reveals how the feature's value relates to its impact. For example, if high values (red points) are consistently on the right (positive SHAP values) and low values (blue points) are on the left (negative SHAP values), it suggests a positive correlation between the feature and the model's output. Overlapping colors might indicate more complex relationships or interactions.
A simplified example of a SHAP Summary Plot. 'Age' appears most important, with higher ages (reddish points) generally having positive SHAP values. 'Income' shows a similar trend but with less overall impact. 'Education' has the least impact, and the relationship between its value and impact is less clear from this view.
SHAP Dependence Plot
While the summary plot provides an overview, the SHAP Dependence Plot allows a more detailed look at the effect of a single feature across the dataset. It helps visualize the relationship between a feature's value and its corresponding SHAP value, revealing potential non-linearities and interaction effects.
Structure and Interpretation
A dependence plot typically shows:
- Feature Value: The x-axis represents the actual values of the chosen feature.
- SHAP Value (Impact): The y-axis represents the SHAP value for that feature for each instance.
- Instance Representation: Each point corresponds to an instance in the dataset.
- Interaction Coloring (Optional but Recommended): Points can be colored based on the value of a second feature. The SHAP library often automatically selects the feature that seems to have the strongest interaction effect with the primary feature being plotted.
Interpreting a dependence plot involves looking for:
- Main Effect Trend: The overall vertical trend of the points shows how the SHAP value (impact on prediction) changes as the feature's value increases. This can reveal linear or non-linear relationships.
- Vertical Dispersion: If the points show significant vertical spread for similar feature values on the x-axis, it suggests that other features are influencing the impact of the primary feature. This indicates interaction effects.
- Interaction Effects (with Coloring): When points are colored by a second feature, distinct patterns or separations in color along the vertical axis strongly suggest an interaction. For example, if high values of the interaction feature (e.g., red points) consistently have higher SHAP values than low values (e.g., blue points) for the same value of the primary feature on the x-axis, it indicates a positive interaction.
Example SHAP Dependence Plot for the 'Age' feature, with points colored by 'Income'. The upward trend indicates that higher age generally leads to a higher positive impact on the prediction. If, for a given age, the redder points (higher income) were consistently higher on the y-axis than the bluer points (lower income), it would suggest an interaction where the positive impact of age is amplified by higher income.
Combining Insights
Summary and dependence plots work together to provide a comprehensive understanding of feature effects. The summary plot identifies which features merit closer inspection, while dependence plots reveal the precise nature of their influence, including non-linearities and interactions. These visualizations move beyond single prediction explanations to characterize the model's behavior more globally, aiding in model validation, debugging, and communication of results. Generating these plots is typically straightforward using functions like shap.summary_plot()
and shap.dependence_plot()
available in the SHAP Python library, which we will cover in the implementation sections.