Source-linked AI summary
Causal-learn: Causal Discovery in Python
Yujia Zheng, Biwei Huang, Wei Chen, Joseph Ramsey, Mingming Gong, Ruichu Cai, Shohei Shimizu, Peter Spirtes, Kun Zhang
TL;DR
Causal discovery seeks causal information from observational data when interventions are impractical, but existing tools may depend on Java or R. The paper describes causal-learn, a comprehensive open-source Python library with algorithms, modular components, APIs, and documentation. It concludes that the library supports causal analysis and development of causal discovery methods, while constraint-based methods may leave causal directions unresolved and Granger relations are not necessarily true causality.
Problem
Causal discovery addresses the need to reveal causal information from observational data when interventions or randomized experiments are costly or impractical.
Method
The paper presents causal-learn, a fully Python library combining representative causal discovery algorithms with modular tests, scores, graph utilities, APIs, and documentation.
Results
causal-learn provides a comprehensive toolset for applying causal analysis and developing novel or enhanced causal discovery algorithms.
Takeaways & Limitations
The library lowers barriers to integrating, modifying, extending, and contributing causal discovery implementations within Python-based workflows.
Takeaways & Limitations
Constraint-based methods may return non-unique causal structures with undirected edges, and Granger causality is not necessarily true causality.
Abstract
from arXiv · showhide
Causal discovery aims at revealing causal relations from observational data, which is a fundamental task in science and engineering. We describe $\textit{causal-learn}$, an open-source Python library for causal discovery. This library focuses on bringing a comprehensive collection of causal discovery methods to both practitioners and researchers. It provides easy-to-use APIs for non-specialists, modular building blocks for developers, detailed documentation for learners, and comprehensive methods for all. Different from previous packages in R or Java, $\textit{causal-learn}$ is fully developed in Python, which could be more in tune with the recent preference shift in programming languages within related communities. The library is available at https://github.com/py-why/causal-learn.
1 Introduction
Causal discovery reveals causal information from observational data when interventions are impractical. The paper presents causal-learn as a Python library addressing limitations of existing Java- and R-based tools.
- Motivation: Interventions and randomized experiments can be costly or logistically impractical, motivating causal discovery from observational data.Such analyses support research across genomics, ecology, neuroscience, and epidemiology.
- Background: Causal discovery methods include constraint-based, score-based, functional causal model-based, and latent-variable approaches.PC and FCI use conditional independence relationships, while functional causal models add distributional assumptions to distinguish causal directions.
- Problem: Existing tools such as TETRAD, pcalg, and bnlearn provide causal discovery methods but depend on Java or R.Wrappers remain dependent on those languages, complicating deployment and limiting direct extensibility for Python users.
- Contribution: causal-learn is an open-source Python library with extensive causal discovery algorithms, accessible APIs, and thorough documentation.It targets practitioners, researchers, non-specialists, and learners.
- Contribution: The library provides independent modules for independence tests, score functions, graph operations, and evaluation metrics.Its full Python implementation supports integration, modification, and extension without Java or R expertise.
2 Design
Causal-learn is designed as a modular, extensible Python platform covering major causal discovery categories and reusable analysis components. It supports varied data settings while documenting assumptions and practical boundaries.
- Design philosophy: Causal-learn aims to be an open-source, modular, extensible, and embeddable Python platform for learning causality from data.The paper introduces algorithms and functionalities with attention to use cases and suitable application scenarios.
- Search methods: The library officially implements representative causal discovery methods across all major categories and continues adding newer algorithms.Its coverage includes constraint-based, score-based, functional causal model, latent-variable, and time-series methods.
- Search methods: Constraint-based methods such as PC, FCI, and CD-NOD use conditional independence tests and accommodate multiple data assumptions.PC can use Fisher-Z, Chi/G-squared, or KCI tests for linear-Gaussian, discrete, or nonparametric settings.
- Search methods: Constraint-based methods generally cannot uniquely determine the complete causal graph, leaving some undirected edges in returned CPDAGs.This limitation reflects their recovery of equivalence classes rather than unique causal structures.
- Search methods: Score-based methods optimize score functions using strategies including GES, exact search, and permutation-based search.Available scores include BIC, BDeu, and Generalized Score for different data types and assumptions.
- Reusable components: Independent modules provide conditional independence tests, score functions, graph operations, examples, documentation, and benchmark datasets.Tests and scores can also be integrated into statistical analysis or model-selection pipelines.
3 Example
The example demonstrates causal discovery in Python through installation and a short PC-algorithm workflow. The returned causal graph is then visualized in Figure 1.
- Example workflow: The library can be installed with pip before running the causal discovery example.The example presents causal discovery in Python as a short workflow.
- Example workflow: The example applies the PC algorithm with default parameters to data.The operation is represented by the code statement cg = pc(data).
- Example workflow: The returned causal graph is drawn with draw_pydot_graph().This produces the visualization shown in Figure 1.
4 Conclusion
The conclusion presents causal-learn as a comprehensive Python toolset for applying causal analysis and developing causal discovery algorithms. Its infrastructure supports modifying, extending, tailoring, and contributing implementations.
- Conclusion: causal-learn provides a comprehensive toolset for causal discovery and causal analysis applications, including machine learning.The conclusion frames it as a platform for both applying existing techniques and developing new or enhanced algorithms.
- Conclusion: Its fully Python infrastructure enables users to modify, extend, tailor, and contribute causal discovery implementations.The library is described as actively developed by the team and open-source community.