Skip to main content

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_inference import FastCausalInference

# 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:

  1. Peter-Clarke (PC) Algorithm
  2. IDA Algorithm
  3. 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

fast_causal_shap-0.1.1.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fast_causal_shap-0.1.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file fast_causal_shap-0.1.1.tar.gz.

File metadata

  • Download URL: fast_causal_shap-0.1.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for fast_causal_shap-0.1.1.tar.gz
Algorithm Hash digest
SHA256 969cd3508d460872f9799db263d6806f88e0ce9939a494d2e16441c6d248b62a
MD5 8e989c850f83b0fd155fde28ad15f0fd
BLAKE2b-256 269b1943541854ca49fe7c51a1a448021fca52fb67f60180856dcac4627be721

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_causal_shap-0.1.1.tar.gz:

Publisher: python-publish.yml on woonyee28/FastCausalSHAP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fast_causal_shap-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_causal_shap-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac29830046a78b24deabc253953affbef330c10e3c671e4681c879816d4b621f
MD5 b87fde8bca3ab59055ad6900318c56c7
BLAKE2b-256 f67842a2353727bb6496a4932da0582e98ec4c144d628fddf6318ee257d8aa96

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_causal_shap-0.1.1-py3-none-any.whl:

Publisher: python-publish.yml on woonyee28/FastCausalSHAP

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page