Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 37 ยท Uplift and Heterogeneous Effects

Meta-Learners (S, T and X)

Estimate heterogeneous treatment effects with machine learning using S-, T- and X-learners. Build each from scikit-learn models and compare them against a known true effect.

A linear interaction can describe a simple pattern of heterogeneous effects. Real effects bend, switch on at thresholds and depend on many variables at once. Meta-learners are recipes that let any supervised machine learning model (a gradient-boosted tree, a random forest, a neural network) estimate the conditional average treatment effect tau(x). The word "meta" means the recipe is independent of the base model: you plug a regressor in.

All three learners below assume the usual: treatment is randomized, or unconfoundedness and overlap hold given X. They differ in how they combine models for treated and untreated outcomes.

The simulated data

The effect depends on x0 through a threshold, and on x1 linearly. The untreated outcome is curved in x1. We know the true tau, so we can score each learner by its root mean squared error (RMSE).

S-learner: one model

Fit a single model of Y on X and the treatment indicator T. To get the effect for a unit, predict twice, once with T=1 and once with T=0, and subtract.

tau_hat(x) = mu(x, 1) - mu(x, 0)

It is simple and uses all data in one model. Its weakness: a regularized model may decide T is a minor feature and mostly ignore it, shrinking the effect toward zero.

T-learner: two models

Fit one model on treated units and another on control units, then subtract their predictions.

tau_hat(x) = mu1(x) - mu0(x)

Each model can capture its own shape, so it handles strongly different outcome surfaces. The cost: each uses only part of the data, and the two models' errors do not cancel, which makes the difference noisy.

Python S-learner and T-learner against the truth

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Both learners beat the "everybody gets the average" baseline by a wide margin. Which of the two wins depends on the data: here the S-learner is more accurate because the effect is a simple function and it shares structure with the outcome, while the T-learner's two models each see only half the data. With a smaller or noisier effect, the S-learner's tendency to shrink toward zero shows up.

X-learner: borrow strength across groups

The X-learner (Kunzel and coauthors) handles unbalanced groups well. It has three steps:

  1. Fit outcome models mu1 (treated) and mu0 (control), as in the T-learner.
  2. Compute imputed individual effects: for treated units D1 = Y - mu0(X); for control units D0 = mu1(X) - Y. Each is a noisy estimate of that unit's own effect.
  3. Fit models tau1(x) on D1 and tau0(x) on D0, and combine: tau(x) = g(x) * tau0(x) + (1 - g(x)) * tau1(x), where g is a weight, often the propensity score e(x). If few units are treated, tau0 (learned from the many controls) gets more weight.
Python Adding an X-learner

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The X-learner usually improves on the T-learner because its last step fits smooth effect surfaces to the imputed effects, whereas subtracting two wiggly outcome models magnifies their noise.

Which one to use?

Learner Good when Watch out for
S Effects are small, data is limited, base model is flexible Treatment may be ignored (shrinks toward 0)
T Treatment and control outcome surfaces differ a lot Noisy; wastes data; no shared structure
X Treated and control groups are unbalanced More moving parts

More advanced options: R-learner and double machine learning (residualize the outcome and the treatment on X, then regress residual on residual, which is robust to errors in the nuisance models), causal forests (trees that split to maximize effect differences, with honest estimation and confidence intervals) and DR-learner (uses doubly robust scores).

Evaluating CATE models

You never see the true individual effect, so evaluation is indirect:

  • Calibration by groups. Sort units by predicted effect into quantile groups and check whether the observed treated-minus-control difference in each group increases in the same order (see uplift evaluation).
  • Held-out data. Always evaluate on data not used for fitting, otherwise noise looks like signal.
  • Simulation. Check methods on semi-synthetic data with a known effect, as above.
  • Business metric. Compare a policy that treats by predicted effect against treating everyone, using a randomized hold-out.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. How does an S-learner compute the CATE for a unit?

    The S-learner includes T as a feature of one model; the difference of its two predictions is the effect.
  2. 2. What is a typical weakness of the S-learner?

    If T seems a weak predictor, tree models may rarely split on it.
  3. 3. What are the imputed effects D1 and D0 in the X-learner?

    For treated units D1 = Y - mu0(X); for controls D0 = mu1(X) - Y.
  4. 4. Why evaluate CATE models on held-out data?

    Flexible models can memorize noise, so apparent heterogeneity must be confirmed on new data.

Summary

  • Meta-learners turn any regression model into a CATE estimator.
  • S-learner: one model with T as a feature. T-learner: separate models for treated and control. X-learner: imputes individual effects and models them, good for unbalanced groups.
  • Causal forests and double machine learning are stronger options for observational data.
  • Evaluate on held-out data using group calibration and policy value, not just fit.

Next: Uplift Modeling and Evaluation