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 to True.

  • n_interactions (int | None) – The number of interactions to plot. If None, 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. If None, all interactions are plotted. Possible values are "positive" and "negative". Defaults to None.

  • 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 to 1.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 to 1.0 (no scaling). Values between 0.0 and 1.0 will 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). If None, the minimum and maximum interaction values are used. Defaults to None.

  • 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 to None.

  • 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 to None, which creates a graph with all nodes from the interaction values without any edges between them.

  • plot_original_nodes (bool) – If set to True, nodes are shown as white circles with the label inside, large first-order-effects appear as halos around the node. Set to False, only the explanation nodes are shown, their labels next to them. Defaults to False.

  • plot_explanation (bool) – Whether to plot the explanation or only the original graph. Defaults to True.

  • pos (dict | None) – The positions of the nodes in the graph. If None, the spring layout is used to position the nodes. Defaults to None.

  • 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 least NORMAL_NODE_SIZE apart. Defaults to False.

  • 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 to None.

  • 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 to 1e10.

  • center_image (Image | ndarray | None) – An optional image to be displayed in the center of the graph. If provided, the image displayed with size center_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 to None.

  • center_image_size (float) – The size of the center image. Defaults to 0.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 to None.

  • feature_image_patches_size (float) – The size of the feature image patches. Defaults to 0.2.

Return type:

tuple[Figure, Axes] | None

Returns:

The figure and axis of the plot if show is False. Otherwise, None.

References