AI & Machine Learning Master Course — 165. Treatment heterogeneity and uplift
Smartyfy AI & Machine Learning Master Course
Course ID: smartyfy-ai-ml-master-200
Lesson 165: Treatment heterogeneity and uplift
Prerequisites: Lesson 164. Learning outcome: Evaluate treatment-effect variation while separating it from outcome prediction.
High outcome and high treatment benefit are different
Treatment heterogeneity means the causal effect varies across units or contexts. A model predicting who will have a high outcome after treatment is not necessarily predicting who benefits most from treatment. Someone may do well with or without the intervention, while another unit may have a lower absolute outcome but a larger incremental gain.
A conditional average treatment effect, or CATE, is E[Y(1)-Y(0)|X=x] for specified pretreatment features X. It averages individual effects within a feature-defined group. It is not generally the unobservable individual effect for one person, even when a model outputs one number per row.
The treatment, outcome, population, and timing still need precise definitions. Features used to choose a treatment must be available before that choice. Post-treatment engagement cannot serve as an ordinary baseline targeting variable without changing the question and identification strategy.
Start with prespecified subgroups
A simple approach estimates a treated-minus-control mean difference separately in a few prespecified strata of a randomized experiment. The comparison inherits the randomization design within those strata, but smaller groups have greater uncertainty. A large estimated difference in a tiny group may be noise.
Searching many subgroup definitions and reporting only the most favorable ones creates selection bias and exaggerated effect estimates. Separate discovery from confirmation. Methods using honest sample splitting or cross-fitting help separate model construction from evaluation, but still require adequate data and identification assumptions.
More flexible approaches model treatment interactions, fit separate outcome models for treatment arms, or use specialized causal forests. These methods estimate conditional averages under assumptions; they do not reveal every unit’s missing counterfactual. The lab below uses only two predefined strata and simple difference-in-means estimates, not a causal forest implementation.
CPU lab: learn a two-stratum treatment rule
The fictional population has a binary pretreatment feature X. When X=0, the untreated outcome is around 20 and treatment adds four. When X=1, the untreated outcome is around 40 and treatment subtracts two. Thus the high-outcome group has negative benefit from treatment.
Four hundred development units provide observed outcomes under a stratified randomized assignment. The code assigns exactly half of each stratum to treatment. Estimated effects are approximately [3.860722,-2.165028], close to the simulator’s predefined [4,-2] effects.
The rule treats a unit only when its estimated stratum effect is positive. It therefore treats X=0 and leaves X=1 untreated. A separate set of four hundred simulator units evaluates the frozen rule. No outcomes from those units enter the subgroup estimates or action selection rule.
Because the simulator exposes both potential outcomes, it can directly calculate policy value on the held-out units. The rule gains exactly two outcome units per unit relative to treating none, while treating everyone gains one. Those exact gains follow from the constant within-stratum effects and equally sized held-out strata. They are not estimates from a real logged-policy evaluation.
import numpy as np
rng=np.random.default_rng(165)
X=np.tile([0,1],400)
y0=20+20*X+rng.normal(0,1,len(X))
tau=np.where(X==0,4.,-2.);y1=y0+tau
# Randomize exactly half of each stratum in development; no final outcomes used.
train=np.arange(400);test=np.arange(400,800)
A=np.zeros(len(train),dtype=bool)
for g in [0,1]:
ids=np.flatnonzero(X[train]==g);A[rng.permutation(ids)[:len(ids)//2]]=True
y=np.where(A,y1[train],y0[train])
hat=np.array([y[(X[train]==g)&A].mean()-y[(X[train]==g)&~A].mean() for g in [0,1]])
policy=hat[X[test]]>0
value=np.mean(np.where(policy,y1[test],y0[test]))
print('Estimated stratum effects:',hat.round(6).tolist())
print('True stratum effects:',[4.,-2.])
print('Policy actions for X=0,1:',(hat>0).astype(int).tolist())
print('Simulator test value gain versus treat-none:',round(float(value-y0[test].mean()),6))
print('Treat-all gain versus treat-none:',round(float(np.mean(y1[test]-y0[test])),6))
assert np.array_equal(hat>0,[True,False])
assert np.isclose(value-y0[test].mean(),2)
Derive the policy-value comparison
For equal group proportions, treating everyone yields average gain 0.5 times four plus 0.5 times negative two, which equals one. Treating only the positive-benefit group yields 0.5 times four plus 0.5 times zero, which equals two.
An outcome-propensity shortcut can fail. Ranking units by their predicted treated outcome would favor the group whose treated outcome is around 38 over the group whose treated outcome is around 24. Yet treatment harms the first group by two and helps the second by four. The relevant quantity for incremental targeting is the contrast between treatment alternatives, not the treated outcome alone.
If treatment has a known cost in the same utility units, compare estimated incremental benefit with that cost. Budget limits, capacity, side effects, fairness requirements, and uncertainty can further change the decision rule. A positive estimated effect alone is not a universal instruction to act.
Evaluate heterogeneity without overstating precision
Evaluate a learned rule on data independent of its discovery. In a real randomized holdout, observed outcomes still reveal only the assigned treatment, so policy-value estimation must use the design appropriately, for example through justified inverse-probability or doubly robust estimators. The lab’s direct access to both outcomes is a simulator privilege.
Assess effect calibration by comparing predicted-effect groups with properly estimated group-level effects in independent data. Ordinary outcome RMSE does not directly measure CATE accuracy. Specialized ranking curves for uplift also depend on assignment, weighting, and denominator conventions.
Report uncertainty and the size of each subgroup, including groups with limited treatment overlap. Precise-looking scores can lack supporting comparisons. Variation across samples can reveal instability without replacing identification assumptions.
Consequential applications require domain review and safeguards. These fictional strata illustrate outcome prediction, effect estimation, and policy evaluation, not decisions about actual people.
Four practice questions with worked answers
Practice 1
Two equally common groups have effects 4 and -2. What is the population ATE?
Answer: Average the effects: (4 + -2)/2 = 1. This positive overall effect hides a negative effect in one group, illustrating why an average need not describe every subgroup.
Practice 2
What gain does treating only the effect-four group achieve relative to treating none?
Answer: Half the population gains four and half receives no treatment, so the average gain is 0.5 times 4 = 2. This exceeds the treat-all gain of one in the specified simulator.
Practice 3
Why is a predicted treated outcome of 38 insufficient to establish benefit?
Answer: Benefit compares that outcome with the same group’s untreated outcome. If the untreated level is 40, the effect is -2 despite a high absolute treated outcome.
Practice 4
If treatment costs three utility units per treated unit, what is the ideal rule under the stated constant effects and no other constraints?
Answer: Treat only the effect-four group, because its net gain is one per treated unit. Do not treat the effect-minus-two group. The population net gain is 0.5 times 1 = 0.5; this calculation assumes known effects and comparable utility units.
Five multiple-choice questions
Question 1
What does a CATE describe?
- A. The observed outcome of every individual after treatment.
- B. An average causal contrast conditional on specified pretreatment features.
- C. A guaranteed exact individual treatment effect for each row.
Correct: B. Conditioning defines a group-level average. It does not make both potential outcomes observable for an individual.
Question 2
Which stratum receives treatment under the fitted rule?
- A. X=0, whose estimated effect is positive.
- B. X=1, because its absolute baseline outcome is higher.
- C. Both strata, because the population average effect is positive.
Correct: A. The displayed rule uses estimated incremental benefit, which is positive only for X=0.
Question 3
Why can the lab directly compute held-out policy value?
- A. The simulator defines both potential outcomes for each held-out unit.
- B. Real randomized holdouts routinely observe both outcomes for every unit.
- C. The policy’s estimated effect score itself is the observed reward.
Correct: A. Direct counterfactual access is a synthetic convenience. Real evaluation must use the observed assignment and suitable estimators.
Question 4
What risk arises from searching many subgroups and reporting only the largest estimated effects?
- A. Searching subgroups makes confidence intervals valid without multiplicity adjustment.
- B. Randomization guarantees that every discovered subgroup difference is genuine heterogeneity.
- C. Selection can amplify random variation and exaggerate apparent heterogeneity.
Correct: C. The search selects favorable noise even when the original assignment was randomized. Independent confirmation is needed.
Question 5
What should a cost-aware rule compare under a simple common-utility model?
- A. Treated outcome alone against the overall population mean.
- B. Incremental treatment benefit against treatment cost.
- C. Baseline outcome risk alone against treatment cost.
Correct: B. Costs enter the treatment-versus-control utility difference. Absolute outcome levels alone do not identify incremental value.
Common pitfalls
Avoid confusing high outcomes with high benefit, treating CATE as known individual effect, selecting subgroups on final evaluation outcomes, or reporting simulator policy value as real experimental evidence.
Summary
Treatment heterogeneity concerns variation in causal contrasts. Estimate it with appropriate design and independent evaluation, then distinguish a learned effect model from the policy that uses it and the evidence supporting that policy’s value.