• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mmschlk / shapiq / 18449544308

12 Oct 2025 09:10PM UTC coverage: 93.266% (-0.6%) from 93.845%
18449544308

Pull #430

github

web-flow
Merge f917f7da5 into dede390c9
Pull Request #430: Enhance type safety and fix bugs across the codebase

278 of 326 new or added lines in 46 files covered. (85.28%)

12 existing lines in 9 files now uncovered.

4986 of 5346 relevant lines covered (93.27%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.75
/src/shapiq/plot/network.py
1
"""This module contains the network plots for the shapiq package."""
2

3
from __future__ import annotations
1✔
4

5
from typing import TYPE_CHECKING, Any
1✔
6

7
import matplotlib.pyplot as plt
1✔
8

9
if TYPE_CHECKING:
1✔
NEW
10
    from matplotlib.axes import Axes
×
NEW
11
    from matplotlib.figure import Figure
×
12

UNCOV
13
    from shapiq.interaction_values import InteractionValues
×
14

15

16
__all__ = ["network_plot"]
1✔
17

18

19
def network_plot(
1✔
20
    interaction_values: InteractionValues,
21
    *,
22
    feature_names: list[Any] | dict[int, Any] | None = None,
23
    show: bool = False,
24
    **kwargs: Any,
25
) -> tuple[Figure, Axes] | None:
26
    """Draws the interaction network plot[1]_.
27

28
    An interaction network is a graph where the nodes represent the features and the edges represent
29
    the interactions. The edge width is proportional to the interaction value. The color of the edge
30
    is red if the interaction value is positive and blue if the interaction value is negative. The
31
    network plot has been used to visualize local Shapley interaction values[1]_ and is a variation
32
    of the graph plots presented by Inglis et al. (2022)[2]_. Below is an example of an interaction
33
    network with an image in the center.
34

35
    .. image:: /_static/network_example.png
36
        :width: 400
37
        :align: center
38

39
    Args:
40
        interaction_values: The interaction values as an interaction object.
41

42
        feature_names: The feature names used for plotting. List/dict mapping index of the player as
43
            index/key to name. If no feature names are provided, the feature indices are used
44
            instead. Defaults to ``None``.
45

46
        show: Whether to show the plot. Defaults to ``False``. If ``False``, the figure and the axis
47
            containing the plot are returned, otherwise ``None``.
48

49
        **kwargs: Additional keyword arguments passed to the plotting function of
50
            :meth:`shapiq.plot.si_graph_plot.si_graph_plot`. See the documentation of that
51
            function for more details on the available keyword arguments.
52

53
    Returns:
54
        The figure and the axis containing the plot if ``show=False``.
55

56
    References:
57
        .. [1] Muschalik, M., Fumagalli, F., Hammer, B., & Hüllermeier, E. (2024). Beyond TreeSHAP: Efficient Computation of Any-Order Shapley Interactions for Tree Ensembles. Proceedings of the AAAI Conference on Artificial Intelligence, 38(13), 14388-14396. https://doi.org/10.1609/aaai.v38i13.29352
58

59
        .. [2] Inglis, A.; Parnell, A.; and Hurley, C. B. 2022. Visualizing Variable Importance and Variable Interaction Effects in Machine Learning Models. Journal of Computational and Graphical Statistics, 31(3): 766-778.
60

61
    """
62
    from . import si_graph_plot
1✔
63

64
    output = si_graph_plot(
1✔
65
        interaction_values=interaction_values,
66
        feature_names=feature_names,
67
        show=show,
68
        min_max_order=(1, 2),
69
        **kwargs,
70
    )
71
    # output is not None if show is False
72
    if output:
1✔
73
        fig, ax = output
1✔
74
        return fig, ax
1✔
75
    plt.show()
×
76
    return None
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc