Skip to content
StatsOtter A workspace for causal thinking
Method library WORKFLOW / 080
Research workflow/3 steps

Double machine learning in Python (econml)

01
The method workspace

Follow the analysis.

Select a node to explore the method

Method mapInput → 3 steps → output
START WITHInput data
ARRIVE ATResults
Read step 01
Inside the methodReasoning, equations & implementation
Step 1 of 3
01
Data prep

Build the data

Data preparation — shapes the raw inputs into what the estimator expects.

What happens here

Provide outcome, a (discrete) treatment, and effect-modifier features.

Reads fromNot specified Feeds into#2
Key code
# 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)

Reference / docs ↗

Discussion on this step (0)
StatsOtterDiscussion starter · Editorial note

Before using this step, make its assumptions and its output explicit. A useful peer note explains what you would check, what could go wrong, or what would change your interpretation.

Questions to explore
  1. Which assumption matters most here, and what evidence could challenge it?
  2. What would you check before passing this output to the next step?

Peer discussion

  • Bring your experience, a question, or a different perspective.
02
Data contract

Inputs & data

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
03
Read the evidence

Results & interpretation

1 figure Workflow discussion 0
01FigureDouble-ML CATE estimates across units from econml's LinearDML, centered on the average treatment effect.

Result figure rendered by StatsOtter from the package's documented example — unofficial community showcase; all credit to the original authors.

The estimate

\tau(x)=\mathbb E[Y(1)-Y(0)\mid X=x];\quad \tilde Y=\tilde T\,\theta(x)+\varepsilon\ \ (\text{double ML residuals})

Context & interpretation

⚠️ 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

Links: package · paper

Peer notes

Discuss the workflow (0)

  • No comments yet — start the conversation.
IN THE MARGINS

Peer discussion