This repository contains the Python code behind the preprint [1].
The code uses various synthetic datasets and one real-world dataset. For the latter, a copy of the according data is contained in in the folder datasets/sachs so that all code should run without any further need of downloading data.
All code runs on CPUs, no GPU hardware is required to repeat the experiments.
This code was written for Python version 3.12.12. All required packages can be installed via pip:
pip install -r requirements.txt
If this fails, try using the exact Python version as above. If installing the packages still fails, installing each package in requirements.txt by itself should fix the issues.
All results will be stored in according subfolders in results, cf. results/results_README.md for a list of the according folders. Missing folders will be created upon a first call of the scripts below.
All experiments, except for the linear SCM experiment, use hydra for configuration. The configurations are saved in config.
There are four main scripts for performing the experiments from [1].
-
compute_shapley.pycomputes Shapley values and cc-Shapley values and stores a plot in the according subfolder of results. To compute and plot only cc-Shapley values usecompute_shapley_only_cc.py. -
plot_I_with_no_context.pyandplot_I_with_univariate_context.pyplot the importances$I_{\cdot}(\cdot)$ as given by Equation (5) of [1]. -
linear_experiment.pyruns the study on linear SCMs.
Examples for the execution of all scripts are given below.
To compute the Shapley values as shown in the article, run
# for Example 1.1
python compute_shapley
# for the non-linear example from Section 4
python compute_shapley data=diabetes
# for the real-world example from Section 4
python compute_shapley data=sachs_interventional
To plot the univariate importances of a feature as shown in the article, run, e.g.,
# for Example 1.1 and feature "G"
python plot_I_with_no_context.py data.univariate_kwargs=['G']
# for the non-linear example from Section 4 and feature "H"
python plot_I_with_no_context.py data=diabetes data.univariate_kwargs=['H']
# for the real world dataset and the proteins Jnk,PKC,P38
python plot_I_with_no_context.py data=sachs_interventional univariate_kwargs=['Jnk','PKC','P38']
To plot all heatmaps of I with univariate context for Example 1.1 and the non-linear example from Section 4 run
# for Example 1.1
python plot_I_with_univariate_context.py
# for the non-linear example from Section 4
python plot_I_with_univariate_context.py data=diabetes
Note: The script plot_I_with_no_context.py currently assumes, for simplicity, binary classification and is therefore not usable for the real world dataset from Sachs et al. considered in the article.
Figure 2 of the article is created by the following script:
python linear_experiment.py
The execution takes roughly one hour.
To run the robustness experiments from Sections E.3 and E.4 in the appendix of [1], run
# for the diabetes and bmi robustness experiment (Section E.3 - Figure 13)
scripts/run_robustness_diabetes_experiment.sh
python plot_cc_shapley_robustness_diabetes.py
# for the robustness experiment for the protein data (Section E.4 - Figure 15)
scripts/run_robustness_sachs_experiment.sh
The plot of the diabetes experiment will be stored as results/diabetes/cc_shapley_robustness_diabetes.png
whereas the results for the protein data will be stored in several seperate folders such as
results/sachs_interventional_without_PKC_P38., cf. results_README.md for a full list.
Copyright (c) 2026 Machine Learning and Uncertainty, working group 8.44, PTB Berlin
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
[1] Martin, Jörg, and Stefan Haufe. "cc-Shapley: Measuring Multivariate Feature Importance Needs Causal Context." arXiv preprint arXiv:2602.20396 (2026).