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

  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.3.tar.gz (11.1 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.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

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

Hashes for fast_causal_shap-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5c28cfec7c3f82e8009fbec89045c1ded9ffea6778cad598032733f7319b4568
MD5 6716ecd7a2162fc2da10bf2dd3d6603e
BLAKE2b-256 3e9a1ca7d6ab8ee3afcfa2ced1f326bc99a041cd51c16ad1f4dd26711feef7c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_causal_shap-0.1.3.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.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_causal_shap-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d0816b33cd082c8147991ca48056a6532dc31186fff440b5dbc2d9b84b8a63f1
MD5 92c0caaf5a5b0ad89fe22749f25a63de
BLAKE2b-256 9630d936dba59f6ecb3fa71335758dac6dc887ab5d02c04c615f656baa1435e3

See more details on using hashes here.

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

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