shapiq.plot.stacked_bar_plotΒΆ
- shapiq.plot.stacked_bar_plot(interaction_values, *, feature_names=None, max_order=None, title=None, xlabel=None, ylabel=None, show=False)[source]ΒΆ
The stacked bar plot interaction scores.
This stacked bar plot can be used to visualize the amount of interaction between the features for a given instance. The interaction values are plotted as stacked bars with positive and negative parts stacked on top of each other. The colors represent the order of the interaction values. For a detailed explanation of this plot, we refer to Bordt and von Luxburg (2023) [Bor23stk].
An example of the plot is shown below.
- Parameters:
interaction_values (
InteractionValues) β n-SII values as InteractionValues objectfeature_names (
list[Any] |None) β The feature names used for plotting. If no feature names are provided, the feature indices are used instead. Defaults toNone.show (
bool) β Whether to show the plot. Defaults toFalse.
- Returns:
- A tuple containing the figure and
the axis of the plot.
- Return type:
Note
To change the figure size, font size, etc., use the [matplotlib parameters](https://matplotlib.org/stable/users/explain/customizing.html).
Example
>>> import numpy as np >>> from shapiq.plot import stacked_bar_plot >>> interaction_values = InteractionValues( ... values=np.array([1, -1.5, 1.75, 0.25, -0.5, 0.75,0.2]), ... index="SII", ... min_order=1, ... max_order=3, ... n_players=3, ... baseline_value=0 ... ) >>> feature_names = ["a", "b", "c"] >>> fig, axes = stacked_bar_plot( ... interaction_values=interaction_values, ... feature_names=feature_names, ... ) >>> plt.show()
References
[Bor23stk]Bordt, M., and von Luxburg, U. (2023). From Shapley Values to Generalized Additive Models and back. Proceedings of The 26th International Conference on Artificial Intelligence and Statistics, PMLR 206:709-745. url: https://proceedings.mlr.press/v206/bordt23a.html