Skip to main content

A package to extract the causal graph from continuous tabular data.

Project description

logo

License Python Platform Build Status codecov Documentation

causalexplain - A library to infer causal-effect relationships from tabular data

'causalexplain' is a library that implements methods to extract the causal graph, from tabular data, specifically the ReX method, and other compared methods like GES, PC, FCI, LiNGAM, CAM, and NOTEARS.

ReX is a causal discovery method that leverages machine learning (ML) models coupled with explainability techniques, specifically Shapley values, to identify and interpret significant causal relationships among variables. Comparative evaluations on synthetic datasets comprising tabular data reveal that ReX outperforms state-of-the-art causal discovery methods across diverse data generation processes, including non-linear and additive noise models. Moreover, ReX was tested on the Sachs single-cell protein-signaling dataset, achieving a precision of 0.952 and recovering key causal relationships with no incorrect edges. Taking together, these results showcase ReX’s effectiveness in accurately recovering true causal structures while minimizing false positive pre- dictions, its robustness across diverse datasets, and its applicability to real-world problems. By combining ML and explainability techniques with causal discovery, ReX bridges the gap between predictive modeling and causal inference, offering an effective tool for understanding complex causal structures.

ReX Schema

It is built using SKLearn estimators, so that it can be used in scikit-learn pipelines and (hyper)parameter search, while facilitating testing (including some API compliance), documentation, open source development, packaging, and continuous integration.

The datasets used in the examples can be generated using the generators module, which is also part of this library. But in case you want to reproduce results from the articles that we used as reference, you can find the datasets in the data folder.

Prerequisites without Docker

  • Operating System: Linux or macOS
  • Environment Manager: PyEnv or Conda
  • Programming Language: Python 3.10.12 or higher
  • Hardware: CPU

Installation

The project can be installed using pip:

$ pip install causalexplain

Data

The datasets used to reproduce the results presented in the manuscript are available under the data folder. The datasets were generated using the generators module.

Executing causalexplain

To run causalexplain on your data, you can use the causalexplain command:

$ python -m causalexplain
   ___                      _                 _       _       
  / __\__ _ _   _ ___  __ _| | _____  ___ __ | | __ _(_)_ __  
 / /  / _` | | | / __|/ _` | |/ _ \ \/ / '_ \| |/ _` | | '_ \ 
/ /__| (_| | |_| \__ \ (_| | |  __/>  <| |_) | | (_| | | | | |
\____/\__,_|\__,_|___/\__,_|_|\___/_/\_\ .__/|_|\__,_|_|_| |_|
                                       |_|                                        
usage: causalexplain [-h] -d DATASET [-m {rex,pc,fci,ges,lingam,cam,notears}] 
                   [-t TRUE_DAG] [-l LOAD_MODEL] [-T THRESHOLD] [-u UNION] 
                   [-i ITERATIONS] [-b BOOTSTRAP] [-r REGRESSOR] [-S SEED] 
                   [-s [SAVE_MODEL]] [-n] [-v] [-q] [-o OUTPUT]

that will present you with a menu to choose the dataset you want to use, the method you want to use to infer the causal graph, and the hyperparameters you want to use.

The minimum required to run causalexplain is a dataset file in CSV format, with the first row containing the names of the variables, and the rest of the rows containing the values of the variables. The method selected by default is ReX, but you can also choose between PC, FCI, GES, LiNGAM, CAM, NOTEARS. At the end of the execution, the edges of the plausible causal graph will be displayed along with the metrics obtained, if the true dag is provided (argument -t).

Example commands

The following command illustrates how to run causalexplain on the toy dataset using the ReX method:

$ python -m causalexplain -d /path/to/toy_dataset.csv -t /path/to/toy_dataset.dot

The same command can be used to run causalexplain on the toy dataset using the CAM method:

$ python -m causalexplain -d /path/to/toy_dataset.csv -m cam -t /path/to/toy_dataset.dot

For more information on command line options, run causalexplain -h or go to the Quickstart section in the documentation.

Additional Information

WIP

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

causalexplain-0.5.2.tar.gz (211.4 kB view details)

Uploaded Source

Built Distribution

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

causalexplain-0.5.2-py3-none-any.whl (253.5 kB view details)

Uploaded Python 3

File details

Details for the file causalexplain-0.5.2.tar.gz.

File metadata

  • Download URL: causalexplain-0.5.2.tar.gz
  • Upload date:
  • Size: 211.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for causalexplain-0.5.2.tar.gz
Algorithm Hash digest
SHA256 b16e75c1611595223b850e24141641381cae9e3ebda811d96456ade8979a1e01
MD5 cfd9f125673836e66b2457c6835cc109
BLAKE2b-256 24cb674535c12c20d9761039f0030c48357e90fa2d2232e76ef4602a8667aa37

See more details on using hashes here.

File details

Details for the file causalexplain-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: causalexplain-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 253.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.15

File hashes

Hashes for causalexplain-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 415d1e5d2e82a98a605cbd9165387c6c2ed53f5f204e789df95fcd86df0d8037
MD5 1ba9e931f4af1774b3964556b9502927
BLAKE2b-256 9de3dd81c3d5d25539f5743e242f2ad4b86f0b43c5516c5ced6af9378484fdfd

See more details on using hashes here.

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