A Python package for efficient causal SHAP computations
Project description
Fast Causal SHAP
Fast Causal SHAP is a Python package designed for efficient and interpretable SHAP value computation in causal inference tasks. It integrates seamlessly with various causal inference frameworks and enables feature attribution with awareness of causal dependencies.
Features
- Fast computation of SHAP values for causal models
- Support for multiple causal inference frameworks
Installation
Install the stable version via PyPI:
pip install fast-causal-shap
Or, for the latest development version:
pip install git+https://github.com/woonyee28/CausalSHAP.git
Usage
from fast_causal_shap.core import FastCausalSHAP
# Predict probabilities and assign to training data
predicted_probabilities = model.predict_proba(X_train)[:,1]
X_train['target'] = predicted_probabilities
# Initialize FastCausalInference
ci = FastCausalInference(data=X_train, model=model, target_variable='target')
# Load causal strengths (precomputed using R packages)
ci.load_causal_strengths(result_dir + 'Causal_Effect.json')
# Compute modified SHAP values for a single instance
x_instance = X_train.iloc[33]
print(ci.compute_modified_shap_proba(x_instance, is_classifier=True))
Format of the Causal_Effect.json:
[
{
"Pair": "Bacteroidia->Clostridia",
"Mean_Causal_Effect": 0.71292
},
{
"Pair": "Clostridia->Alphaproteobacteria",
"Mean_Causal_Effect": 0.37652
}, ......
]
Fast Causal SHAP supports integration with structural algorithms such as:
- Peter-Clarke (PC) Algorithm
- IDA Algorithm
- Fast Causal Inference (FCI) Algorithm You can find example R code for these integrations here: FastCausalSHAP R code examples
Citation
If you use Fast Causal SHAP in your research, please cite:
@inproceedings{ng2025causal,
title={Causal SHAP: Feature Attribution with Dependency Awareness through Causal Discovery},
author={Ng, Woon Yee and Wang, Li Rong and Liu, Siyuan and Fan, Xiuyi},
booktitle={Proceedings of the International Joint Conference on Neural Networks (IJCNN)},
year={2025},
organization={IEEE}
}
License
This project is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fast_causal_shap-0.1.3.tar.gz.
File metadata
- Download URL: fast_causal_shap-0.1.3.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c28cfec7c3f82e8009fbec89045c1ded9ffea6778cad598032733f7319b4568
|
|
| MD5 |
6716ecd7a2162fc2da10bf2dd3d6603e
|
|
| BLAKE2b-256 |
3e9a1ca7d6ab8ee3afcfa2ced1f326bc99a041cd51c16ad1f4dd26711feef7c5
|
Provenance
The following attestation bundles were made for fast_causal_shap-0.1.3.tar.gz:
Publisher:
python-publish.yml on woonyee28/FastCausalSHAP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_causal_shap-0.1.3.tar.gz -
Subject digest:
5c28cfec7c3f82e8009fbec89045c1ded9ffea6778cad598032733f7319b4568 - Sigstore transparency entry: 835008959
- Sigstore integration time:
-
Permalink:
woonyee28/FastCausalSHAP@c44ab0b651036139fcd816d1f1e6b8bc0dada90e -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/woonyee28
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c44ab0b651036139fcd816d1f1e6b8bc0dada90e -
Trigger Event:
release
-
Statement type:
File details
Details for the file fast_causal_shap-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fast_causal_shap-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0816b33cd082c8147991ca48056a6532dc31186fff440b5dbc2d9b84b8a63f1
|
|
| MD5 |
92c0caaf5a5b0ad89fe22749f25a63de
|
|
| BLAKE2b-256 |
9630d936dba59f6ecb3fa71335758dac6dc887ab5d02c04c615f656baa1435e3
|
Provenance
The following attestation bundles were made for fast_causal_shap-0.1.3-py3-none-any.whl:
Publisher:
python-publish.yml on woonyee28/FastCausalSHAP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fast_causal_shap-0.1.3-py3-none-any.whl -
Subject digest:
d0816b33cd082c8147991ca48056a6532dc31186fff440b5dbc2d9b84b8a63f1 - Sigstore transparency entry: 835008968
- Sigstore integration time:
-
Permalink:
woonyee28/FastCausalSHAP@c44ab0b651036139fcd816d1f1e6b8bc0dada90e -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/woonyee28
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@c44ab0b651036139fcd816d1f1e6b8bc0dada90e -
Trigger Event:
release
-
Statement type: