A Python toolkit for heterogeneous treatment effects from observational data — double ML, doubly-robust, orthogonal forests, meta-learners.
Input · what goes in
Outcome Y, treatment T, effect-modifier features X, and controls W (arrays or DataFrames).
Show data format & exampleHide example
| Y | T | X1 | X2 |
|---|---|---|---|
| 1.0 | 1 | 0.5 | -0.3 |
| 0.2 | 0 | -0.8 | 0.1 |
| 1.7 | 1 | 0.9 | 1.2 |
| 0.0 | 0 | 0.1 | -0.6 |
Pipeline · the recipe
↑ Click any step in the diagram to read its logic, code, assumptions & discussion.
Build the data
Data preparation — shapes the raw inputs into what the estimator expects.
Provide outcome, a (discrete) treatment, and effect-modifier features.
# Install: pip install econml
import numpy as np
from econml.dml import LinearDML
from sklearn.ensemble import GradientBoostingRegressor
n = 1000
X = np.random.normal(size=(n, 5))
T = np.random.binomial(1, 0.5, size=n)
Y = (X[:, 0] > 0) * T + X[:, 1] + np.random.normal(size=n)
- No comments on this step yet — be the first.
Log in to comment on this step.
Fit a Linear Double-ML model
The core estimate — where the causal quantity itself is computed.
LinearDML partials out flexible ML models for Y and T (cross-fitted) and recovers the effect.
est = LinearDML(model_y=GradientBoostingRegressor(),
model_t=GradientBoostingRegressor(),
discrete_treatment=True)
est.fit(Y, T, X=X)
- No comments on this step yet — be the first.
Log in to comment on this step.
Read the average effect
Uncertainty quantification — standard errors, intervals, and aggregation.
const_marginal_ate averages the CATE over the sample.
print(est.const_marginal_ate(X))
- No comments on this step yet — be the first.
Log in to comment on this step.
Output · what you get
Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.
Result · the numbers
⚠️ Unofficial community showcase of econml (docs). Not affiliated with the authors — all credit to Microsoft Research / PyWhy (Lewis, Syrgkanis & collaborators); this summarizes public documentation.
What it does. econml brings the Athey–Imbens-style econometrics-meets-ML estimators to Python: it estimates conditional average treatment effects with machine-learning nuisance models while keeping valid inference on the causal parameter.
How it works. Estimators like LinearDML fit flexible models for the outcome and the treatment, partial both out (Neyman-orthogonal/double ML), and regress the residuals to recover the effect — optionally as a function of effect-modifiers X for a CATE. Cross-fitting removes overfitting bias.
Assumptions. Unconfoundedness given the controls and overlap; orthogonalization makes the estimate robust to first-stage ML error.
Packages the double-ML / heterogeneous-effects methods from the causal-ML agenda Imbens helped build; authored by the PyWhy/Microsoft team.
What you get — A CATE model you can evaluate at any X, and the average treatment effect implied by it.
Example output
0.5123847716

Discussion (0)
Log in to join the discussion.