pycausalml
Classical and deep causal inference in one installable package. Trees, uplift, meta-learners, double machine learning, treatment policies, Bayesian quasi-experiments, and the neural models from PyDeepCausalML share one import.
pip install https://github.com/zia207/PyCausalML/releases/download/v0.2.0/pycausalml-0.2.0-py3-none-any.whl| Package | Release v0.2.0 · GitHub · Homepage |
| Docs | Tutorial · Glossary |
| Author | Zia U. Ahmed · Upatta Analytics |
What is it?
PyCausalML 0.2.0 extends PyDeepCausalML 0.2.0 and keeps every public estimator from that release (TARNet, DragonNet, NOTEARS, TCDF, and the rest). On top of those neural models it adds tree and forest estimators, uplift learners, meta-learners, double machine learning, treatment policies, and Bayesian quasi-experiments.
import pycausalml and import pydeepcausalml both work after installation. The deep-learning release on its own is still PyDeepCausalML v0.2.0.
Use it when you need to:
- Estimate conditional average treatment effects with honest trees, forests, meta-learners, or neural nets
- Score uplift on a binary outcome and choose who should be treated
- Estimate a constant effect with a confidence interval (double machine learning, neural DML)
- Run quasi-experiments: difference-in-differences, synthetic control, regression discontinuity, instrumental variables
- Put Bayesian uncertainty on a causal network, a structural model, or a quasi-experiment
- Discover causal graphs from static or time-series data
- Train neural models on CPU, CUDA, or Apple MPS with the same scikit-learn style API
Installation
Requires Python ≥ 3.9. PyTorch ≥ 2.0 is included because the deep models are part of this distribution.
Install release v0.2.0:
pip install https://github.com/zia207/PyCausalML/releases/download/v0.2.0/pycausalml-0.2.0-py3-none-any.whlFrom source:
git clone https://github.com/zia207/PyCausalML.git
cd PyCausalML
pip install -e ".[dev]"
pytestPlotting (matplotlib / seaborn) and the optional libraries:
pip install -e ".[plot]"
pip install -e ".[dowhy,econml,causallearn,uber,doubleml,causalpy,skgrf,shap,boost]"Main features
| Module | What it estimates |
|---|---|
pycausalml.tree_based_models |
Honest trees, doubly robust forests, survival and instrumental forests, boosted causal models |
pycausalml.uplift_learners |
Uplift trees and forests, interaction trees, uplift XGBoost, Qini curves |
pycausalml.meta_learners |
S, T, X, R, and DR learners, plus domain adaptation |
pycausalml.double_machine_learning |
Partially linear, linear, sparse, nonparametric, kernel, and interactive DML |
pycausalml.policy_learners |
Doubly robust policy learner, policy tree, and policy forest |
pycausalml.bayesian_causalML |
Bayesian DiD, RDD, ITS, IV, synthetic control, causal networks, structural models |
pydeepcausalml |
TARNet, CFRNet, DragonNet, GANITE, CausalVAE, NOTEARS, TCDF, and the rest of the neural catalog |
Optional backends in pycausalml.integrations wrap DoWhy, EconML, causal-learn, Uber CausalML, DoubleML, CausalPy, and skgrf when those libraries are installed.
Quickstart
Classical estimators share fit(X, treatment, y) and return NumPy arrays of conditional average treatment effects.
from pycausalml import DRLearner, PartiallyLinearDML, synthetic_data
from pycausalml.data import make_linear_treatment
data = synthetic_data(n=1000, p=6, sigma=0.8, mode=2, random_state=0)
dr = DRLearner(learner="gbr", n_estimators=40, random_state=0).fit(
data["X"], data["w"], data["y"]
)
print("CATE:", dr.predict(data["X"][:5]))
print("ATE:", dr.average_treatment_effect())
linear = make_linear_treatment(n=800, tau=2.0, random_state=0)
dml = PartiallyLinearDML(model_y="ridge", random_state=0).fit(
linear["X"], linear["w"], linear["y"]
)
print("DML effect:", dml.effect(), "95% CI:", dml.confidence_interval())Neural estimators use the same top-level import:
from pycausalml import DragonNet
from pydeepcausalml.datasets import make_confounded_data
df = make_confounded_data(n=2000, random_state=0)
X = df[["age", "education", "prior_income"]].values
est = DragonNet(epochs=50, random_state=0).fit(
X, df["treatment"].values, df["outcome"].values
)
print("ATE:", est.predict_ate(X))Choosing an estimator
| Question | Reach for |
|---|---|
| Honest tree or forest CATE, with a doubly robust score | CausalTree, CausalForest, DRLearner |
| Uplift on a binary outcome | UpliftRandomForest, UpliftXGBoost |
| Constant effect with a confidence interval | PartiallyLinearDML, NeuralDML |
| Who should be treated? | PolicyLearner, DRPolicyTree |
| Threshold, before/after, or a single treated unit | RegressionDiscontinuity, DifferenceInDifferences, SyntheticControl |
| Bayesian uncertainty for a network or a quasi-experiment | bayesian_causalML |
| Neural effect on i.i.d. data | TARNet, CFRNet, DragonNet |
| Which variables cause which? | NOTEARSLinear, DAGGNN, TCDF |
Documentation
The sidebar is the tutorial series for this package: tree-based models, meta-learners, uplift, double machine learning, deep causal learning, Bayesian causal ML, policy learners, and quasi-experiments.
Start here:
- Introduction to Causal Machine Learning
- Tree-Based Models
- Meta-Learners
- Uplift Learners
- Double Machine Learning
- Deep Causal Learning
- Bayesian Causal ML
- Policy Learners
- Quasi-Experiments
- Scientific Terminology Glossary
Source, issues, and the full README live on GitHub.
License
MIT — see LICENSE.