.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/approximators/plot_shapiq_approximator.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_approximators_plot_shapiq_approximator.py: SHAPIQ Approximator =================== General Monte Carlo approximator for any-order interactions using :class:`~shapiq.SHAPIQ` :footcite:t:`Muschalik.2024a`. .. GENERATED FROM PYTHON SOURCE LINES 8-27 .. code-block:: Python from __future__ import annotations import numpy as np import shapiq N_PLAYERS = 8 BUDGET = 200 feature_names = [f"x{i}" for i in range(N_PLAYERS)] weights = np.array([0.4, 0.3, 0.2, 0.1, 0.05, -0.1, -0.2, -0.3]) def game_fun(coalitions: np.ndarray) -> np.ndarray: coalitions = np.atleast_2d(coalitions) return (coalitions @ weights) + 0.5 * coalitions[:, 0] * coalitions[:, 1] .. GENERATED FROM PYTHON SOURCE LINES 28-30 Approximate k-SII values ------------------------ .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. code-block:: Python approximator = shapiq.SHAPIQ(n=N_PLAYERS, max_order=2, index="k-SII", random_state=42) iv = approximator.approximate(BUDGET, game_fun) print(iv) .. rst-class:: sphx-glr-script-out .. code-block:: none InteractionValues( index=k-SII, max_order=2, min_order=0, estimated=True, estimation_budget=200, n_players=8, baseline_value=0.0, Top 10 interactions: (0,): 0.37035788690476207 (0, 1): 0.36198048941798944 (1,): 0.26262475198412694 (2,): 0.19381919642857148 (1, 7): 0.17404877645502653 (0, 7): 0.10531671626984127 (2, 3): 0.10196312830687834 (3,): 0.09848883928571427 (6,): -0.2172036210317462 (7,): -0.24692981150793666 ) .. GENERATED FROM PYTHON SOURCE LINES 36-38 Force plot ---------- .. GENERATED FROM PYTHON SOURCE LINES 38-41 .. code-block:: Python iv.plot_force(feature_names=feature_names) .. image-sg:: /auto_examples/approximators/images/sphx_glr_plot_shapiq_approximator_001.png :alt: plot shapiq approximator :srcset: /auto_examples/approximators/images/sphx_glr_plot_shapiq_approximator_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 42-44 Network plot ------------ .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: Python iv.plot_network(feature_names=feature_names) .. image-sg:: /auto_examples/approximators/images/sphx_glr_plot_shapiq_approximator_002.png :alt: plot shapiq approximator :srcset: /auto_examples/approximators/images/sphx_glr_plot_shapiq_approximator_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 48-51 References ---------- .. footbibliography:: .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.415 seconds) .. _sphx_glr_download_auto_examples_approximators_plot_shapiq_approximator.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_shapiq_approximator.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_shapiq_approximator.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_shapiq_approximator.zip `