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

mmschlk / shapiq / 18499875864

14 Oct 2025 02:26PM UTC coverage: 92.799% (-0.7%) from 93.522%
18499875864

push

github

web-flow
Enhance type safety and fix bugs across the codebase (#430)

* First Pyright cleanup

* TypeChecked game

* fixed introduced bugs in game and interaction_values

* Pyright Save Sampling

* TypeSafe Approximator

* Typechecked Datasets

* Explainer folder typechecked

* GameTheory Typechecked

* Imputer Typechecked

* Plot Typechecked

* Added static typechecking to pre-commit

* Refactoring

* Add pyright change to CHANGELOG

* Activate code quality show diff

* changed uv sync in pre-commit hook

* made fixtures local import

* Introduced Generic TypeVar in Approximator, reducing ignores

* Introduced Generic Types for Explainer. Approximator, Imputer and ExactComputer can either exist or not, depending on dynamic Type

* Bug fix caused through refactoring

* updated overrides

* tightened CoalitionMatrix to accept only bool arrays

* Remove Python reinstallation step in CI workflow

Removed the step to reinstall Python on Windows due to issues with tkinter. The linked GitHub issue was solved. Doing this as a first try.

* Add Python reinstallation and Tkinter installation steps

Reinstall Python and install Tkinter for Windows tests. prior commit did not help

* Fix command for installing Tkinter in workflow

* Update Windows workflow to install Tkinter via Chocolatey

* Remove Tkinter installation step from Windows workflow and adjust matplotlib usage for headless environments

* adapted some pyright types

* removed generics from explainer again

* tightened index type check

* made n_players None at assignment again

* moved comments

---------

Co-authored-by: Maximilian <maximilian.muschalik@gmail.com>

304 of 360 new or added lines in 51 files covered. (84.44%)

12 existing lines in 9 files now uncovered.

4987 of 5374 relevant lines covered (92.8%)

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