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.2.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.2-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fast_causal_shap-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 b51f2b1c60d278864b70dd7850d95361d639777ae37b326c0b9781f94f013d15
MD5 f968d7c66540c84019db6a4be38e6772
BLAKE2b-256 8f1eafa368ed724f19b87fb00b1aa309caf17ce88eb5b4912111b5c2ff2607ec

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for fast_causal_shap-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ed56a0241af7933736dfc3a930611eb8af692f9890a720e61c6b567bb4292f2b
MD5 8e705724939cd76aeedfe6d6d5078674
BLAKE2b-256 41dba67d1799b7c70fd127a9116e9c2d18005e06327bd468d5557cf2f0b24955

See more details on using hashes here.

Provenance

The following attestation bundles were made for fast_causal_shap-0.1.2-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