shapiq icon indicating copy to clipboard operation
shapiq copied to clipboard

Add shap Plots to shapiq

Open mmschlk opened this issue 1 year ago • 1 comments

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:

image

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:

image

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:

image

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:

image

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:

image

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 each InteractionValues object as some plots require information about the feature names and the feature values.
  • We will not port 100% functionality from the shap plots to shapiq but the main ones.

Tasks:

mmschlk avatar Feb 03 '24 13:02 mmschlk

pairplot x, y: feature values, color: interaction values https://seaborn.pydata.org/generated/seaborn.pairplot.html

hbaniecki avatar Apr 11 '24 14:04 hbaniecki

comment on beeswarm: not clear how to indicate "feature value" for interactions

hbaniecki avatar Jun 03 '24 15:06 hbaniecki

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.

mmschlk avatar Jul 15 '24 14:07 mmschlk