shapiq.plot.si_graph_plotΒΆ
- shapiq.plot.si_graph_plot(interaction_values, *, show=False, n_interactions=None, draw_threshold=0.0, interaction_direction=None, min_max_order=(1, -1), size_factor=1.0, node_size_scaling=1.0, min_max_interactions=None, feature_names=None, graph=None, plot_original_nodes=False, plot_explanation=True, pos=None, circular_layout=True, random_seed=42, adjust_node_pos=False, spring_k=None, compactness=10000000000.0, center_image=None, center_image_size=0.4, feature_image_patches=None, feature_image_patches_size=0.2)[source]ΒΆ
Plots the interaction values as an explanation graph.
An explanation graph is an undirected graph where the nodes represent players and the edges represent interactions between the players. The size of the nodes and edges represent the strength of the interaction values. The color of the edges represents the sign of the interaction values (red for positive and blue for negative). The SI-graph plot is presented in Muschalik et al.[1].
- Parameters:
interaction_values (
InteractionValues) β The interaction values to plot.show (
bool) β Whether to show or return the plot. Defaults toTrue.n_interactions (
int|None) β The number of interactions to plot. IfNone, all interactions are plotted according to the draw_threshold.draw_threshold (
float) β The threshold to draw an edge (i.e. only draw explanations with an interaction value higher than this threshold).interaction_direction (
str|None) β The sign of the interaction values to plot. IfNone, all interactions are plotted. Possible values are"positive"and"negative". Defaults toNone.min_max_order (
tuple[int,int]) β Only show interactions of min <= size <= max. First order interactions are always shown. To use maximum order of interaction values, set max to -1. Defaults to(1, -1).size_factor (
float) β The factor to scale the explanations by (a higher value will make the interactions and main effects larger). Defaults to1.0.node_size_scaling (
float) β The scaling factor for the node sizes. This can be used to make the nodes larger or smaller depending on how the graph looks. Defaults to1.0(no scaling). Values between0.0and1.0will make the nodes smaller, higher values will make the nodes larger.min_max_interactions (
tuple[float,float] |None) β The minimum and maximum interaction values to use for scaling the interactions as a tuple(min, max). IfNone, the minimum and maximum interaction values are used. Defaults toNone.feature_names (
list|dict|None) β The feature names used for plotting. List/dict mapping index of the player as index/key to name. If no feature names are provided, the feature indices are used instead. Defaults toNone.graph (
list[tuple] |Graph|None) β The underlying graph structure as a list of edge tuples or a networkx graph. If a networkx graph is provided, the nodes are used as the players and the edges are used as the connections between the players. Defaults toNone, which creates a graph with all nodes from the interaction values without any edges between them.plot_original_nodes (
bool) β If set toTrue, nodes are shown as white circles with the label inside, large first-order-effects appear as halos around the node. Set toFalse, only the explanation nodes are shown, their labels next to them. Defaults toFalse.plot_explanation (
bool) β Whether to plot the explanation or only the original graph. Defaults toTrue.pos (
dict|None) β The positions of the nodes in the graph. IfNone, the spring layout is used to position the nodes. Defaults toNone.circular_layout (
bool) β plot the players in a circle according to their order.random_seed (
int) β The random seed to use for layout of the graph (if not circular).adjust_node_pos (
bool) β Whether to adjust the node positions such that the nodes are at leastNORMAL_NODE_SIZEapart. Defaults toFalse.spring_k (
float|None) β The spring constant for the spring layout. If None, the spring constant is calculated based on the number of nodes in the graph. Defaults toNone.compactness (
float) β A scaling factor for the underlying spring layout. A higher compactness value will move the interactions closer to the graph nodes. If your graph looks weird, try adjusting this value, e.g.[0.1, 1.0, 10.0, 100.0, 1000.0]. Defaults to1e10.center_image (
Image|ndarray|None) β An optional image to be displayed in the center of the graph. If provided, the image displayed with sizecenter_image_size. If the number of features is a perfect square, we assume a vision transformer style grid was used and overlay the image with a grid of feature image patches. Defaults toNone.center_image_size (
float) β The size of the center image. Defaults to0.4. Adjust this value to make the image larger or smaller in the center of the graph.feature_image_patches (
dict[int,Image] |list[Image] |None) β A dictionary/list containing the image patches to be displayed instead of the feature labels in the network. The keys/indices of the list are the feature indices and the values are the feature images. If explicit feature names are provided, they are displayed on top of the image. Defaults toNone.feature_image_patches_size (
float) β The size of the feature image patches. Defaults to0.2.
- Return type:
- Returns:
The figure and axis of the plot if
showisFalse. Otherwise,None.
References