shapiq
shapiq copied to clipboard
Add shap Plots to shapiq
Description
The InteractionValues
dataclass is the core data object containing the results and of approximators and explainers. For representing Shapley values (SVs) visually, the shap package already contains a plethora of very helpful illustration techniques. To ease new users into the package and increase the functionality of shapiq, we should also offer the most important plots for the SV or, if possible, even for Shapley interactions (SIs).
In shap
, there are two kinds of plots which should be integrated somewhat like the following:
-
One Explanation: Some plots illustrate one
shap.Explanation
at a time. This should be possible to recreate in our codebase with one InteractionValues object. -
Multiple Explanations: Other plots capture multiple
shap.Explanations
at a time. This should be possible with a list of InteractionValues objects.
Plot Descriptons
You can see the plots in the readme of the main shap repo.
Force Plot
The force plot shows how each feature attribution or interaction pulls and pushes the prediction from the empty prediction / baseline $\nu(\emptyset)$ towards the prediction with all features / grand coalition $\nu(N)$. This plot works only for a single explanation:
Waterfall Plot
The waterfall plot disentangles the attributions presented in the force plot but shows basically the same information. Notably, it prints only the top-X attributions. This plot works only for a single explanation:
Bar Plot
The bar plot shows the mean absolute value of the attribution/interactions wich can be used as a proxy for feature importance. This plot works only for multiple explanations:
Beeswarm Plot
This plot aggregates multiple local explanations into a global explanation. On the x-axis the Shap values are plotted for each feature. This can be easily extended to interactions:
Scatter Plot
This plot creates a scatter plot of two features and colors the points according to their attributions. This plot works only for multiple explanations:
How To:
For this we need to port the shap
plots to shapiq
and potentially extend the dataclass.
- We will need to add the feature values of
x_explain
to eachInteractionValues
object as some plots require information about the feature names and the feature values. - We will not port 100% functionality from the
shap
plots toshapiq
but the main ones.
Tasks:
- [ ] Add the waterfall plot like used in the original TreeSHAP-IQ implementation for SV and SI.
- [ ] Add the force plot like used in the original TreeSHAP-IQ implementation for SV and SI
- [ ] Add the bar plot for SV and SI. For SI, the plot can just treat every item as a feature.
- [ ] Add the beeswarm plot for SV and SI.
- [ ] Add the scatter plot for SV.
- [ ] Add tests with 100% coverage for these plots
pairplot x, y: feature values, color: interaction values https://seaborn.pydata.org/generated/seaborn.pairplot.html
comment on beeswarm: not clear how to indicate "feature value" for interactions
Removing beeswarm and scatter plot as it is not so clear what the "feature value" of a interaction should be for plotting. Waterfall still makes sense.