Your intuitive guide to interpret SHAP's beeswarm plot
Deena Gergis
AI & Data Science Expert @ McKinsey ? Improving lives, one AI product at a time
The SHAP beeswarm plot is a powerful tool for interpreting machine learning models, but it can be a bit intimidating at first glance. The insights that you can drive from this plot is worth cracking its complexity, as it has become one of the standard steps after modeling.
So, why bother?
A SHAP beeswarm plot will help you:
So, dear reader, let's crack this plot's complexity together
Cracking the SHAP's beeswarm plot in 3 simple steps
To understand the SHAP's beeswarm plot, follow those simple 3 steps:
.
1. Review your model's target variable
End of the day, this plot represents the effect of input features on the final target variable prediction.
In our case, we trained a model on Stackoverflow's 2023 survey data to use the used languages and technologies used to predict if the role is a Data Scientist or a Data Engineer.
As the Data Scientist and Data Engineers are mutually exclusive in this set (i.e. you can be either one or another), I have decided to use only one target variable of both. And for some reason - AKA unconscious bias - I chose to model the target variable as the Data Scientist.
What does that mean:
.
.
2. Understand the SHAP's main axis
As with most plots of this world, the SHAP beeswarm plot also has an X and a Y axis.
I. X-axis: SHAP values:
Let's get started by how those values are calculated:
To intuitively explain those values, those values represent how did this input feature impact the final prediction. Those values have two components, the magnitude and the direction
领英推荐
.
II. Y-axis: Input features
That's a simple one. Your input features are now listed on the y-axis and sorted according to their importance.
.
.
3. Crack a single feature's beeswarm sub-plot
For each of the input features, you will find a subplot that is called a beeswarm color-coded by the input feature value. To understand this better, let's split them into two parts:
Let's put the pieces together to understand what's happening with our top feature: Scikit-learn:
You see that the red points (i.e. when Sklearn is used) have a positive SHAP values (i.e. prediction tends to be towards a Data Scientist)
.
Another example? Let's inspect Apache Kafka
You see that the red points (i.e. when Kafka is used) have a negative SHAP values (i.e. prediction tends to be towards a Data Engineer)
.
Yes, my dear reader, it is as simple as that :-)
.
Want to learn more?
Play around: A stand-alone notebook that I have developed for this illustration is now publicly available on Kaggle: https://www.kaggle.com/code/deenagergis/20231022-shap-beeswarm-illustration. Clone and play around!
Read more: For a more comprehensive explanation about the SHAP values, refer to Christoph Molnar's publicly available book https://christophm.github.io/interpretable-ml-book/shap.html
Head of Translational Bioinformatics at the Vall d'Hebron Hospital Institute of Research, ICREA Research Professor
1 周Nice work! Thank you!
Business & Systems consultant SAP | Data Science enthusiast | Process Optimization
3 个月thank you! :)
SWE @ AROMA Studios ??? | Flutter Enthusiast ???? | GDG Cairo Organizer
11 个月Deena Gergis kindly check indox please
Love this