Meta-learners for uplift / heterogeneous treatment effect estimation.
The S-, T- and X-learners wrap an arbitrary TuiML regressor (for example DecisionTreeRegressor) and re-arrange the (X, treatment, y) data so that an ordinary supervised learner can estimate the conditional average treatment effect
where Y(1) and Y(0) are the potential outcomes under treatment and control.
Classes
S-learner: a single model on [X, treatment].
__init__( self, estimator: Optional[object] = None, )
Summary
The S-learner stacks the treatment indicator onto the covariates and fits one model f(X, t). The uplift is the difference between the two counterfactual predictions:
Overview
-
Append the treatment column to
X. -
Fit a single regressor on the augmented
[X, treatment]. -
Predict the uplift as
f(X, 1) - f(X, 0).
Theory
Parameters
estimator
fit/predict.
Attributes
model_
[X, treatment].
n_features_in_
X (without the treatment column).
n_treated_, n_control_
Notes
Complexity: one supervised fit plus 2 predictions per sample.
When to use: a strong default; the T- and X-learners beat it when the treatment groups are imbalanced or their response surfaces differ a lot.
References
>>> from tuiml.algorithms.causal import SLearner
>>> from tuiml.algorithms.trees import DecisionTreeRegressor
>>> import numpy as np
>>> rng = np.random.RandomState(0)
>>> X = rng.uniform(-1, 1, size=(300, 2))
>>> t = rng.randint(0, 2, size=300)
>>> y = 1.0 + X[:, 1] + t * (2.0 * X[:, 0]) + rng.normal(0, 0.1, size=300)
>>> model = SLearner(DecisionTreeRegressor(max_depth=4)).fit(X, t, y)
>>> model.predict_uplift(X).shape
(300,)
Methods
fit
(self, X, treatment, y) -> 'SLearner'
fit
(self, X, treatment, y) -> 'SLearner'
Fit a single model on the augmented [X, treatment].
Parameters
X
treatment
y
Returns
self
T-learner: two models, one per treatment group.
__init__( self, estimator: Optional[object] = None, )
Summary
The T-learner fits two regressors f_0 and f_1 on the control and treated samples separately. The uplift is their difference:
Overview
-
Split
(X, y)by the treatment indicator. - Fit f_0 on the control group and f_1 on the treated.
- Predict the uplift as f_1(X) - f_0(X).
Theory
Parameters
estimator
fit/predict.
Attributes
model_0_
model_1_
n_features_in_
X.
n_treated_, n_control_
Notes
Complexity: two supervised fits plus two predictions per sample.
When to use: the two group models are genuinely independent, which makes the T-learner the cleanest baseline when treatment groups are balanced and large.
References
>>> from tuiml.algorithms.causal import TLearner
>>> from tuiml.algorithms.trees import DecisionTreeRegressor
>>> import numpy as np
>>> rng = np.random.RandomState(0)
>>> X = rng.uniform(-1, 1, size=(300, 2))
>>> t = rng.randint(0, 2, size=300)
>>> y = 1.0 + X[:, 1] + t * (2.0 * X[:, 0]) + rng.normal(0, 0.1, size=300)
>>> model = TLearner(DecisionTreeRegressor(max_depth=4)).fit(X, t, y)
>>> model.predict_uplift(X).shape
(300,)
Methods
fit
(self, X, treatment, y) -> 'TLearner'
fit
(self, X, treatment, y) -> 'TLearner'
Fit separate models for the treated and control groups.
Parameters
X
treatment
y
Returns
self
X-learner: T-learner plus cross-group imputed-effect models.
__init__( self, estimator: Optional[object] = None, propensity_model: Optional[object] = None, )
Summary
Overview
- Fit the T-learner response models f_0 (control) and
- Impute the effect for each treated unit
-
Fit \tau_1 on
(X_1, D_1)and \tau_0 on
(X_0, D_0).
- Predict \hat{\tau}(x) = p(x)\,\tau_0(x) + (1 - p(x))\,\tau_1(x), where p(x) is the propensity score.
Theory
Parameters
estimator
propensity_model
None, a constant propensity equal to the overall treatment rate is used.
Attributes
model_0_
model_1_
tau_0_
tau_1_
propensity_model_
None when a constant propensity is used).
propensity_
n_features_in_
X.
n_treated_, n_control_
Notes
Complexity: four supervised fits plus four predictions per sample.
When to use: imbalanced treatment groups, or when the base learners for the two groups are not equally accurate.
References
>>> from tuiml.algorithms.causal import XLearner
>>> from tuiml.algorithms.trees import DecisionTreeRegressor
>>> import numpy as np
>>> rng = np.random.RandomState(0)
>>> X = rng.uniform(-1, 1, size=(300, 2))
>>> t = rng.randint(0, 2, size=300)
>>> y = 1.0 + X[:, 1] + t * (2.0 * X[:, 0]) + rng.normal(0, 0.1, size=300)
>>> model = XLearner(DecisionTreeRegressor(max_depth=4)).fit(X, t, y)
>>> model.predict_uplift(X).shape
(300,)
Methods
fit
(self, X, treatment, y) -> 'XLearner'
fit
(self, X, treatment, y) -> 'XLearner'
Fit the T-learner, the imputed-effect models, and the propensity.
Parameters
X
treatment
y
Returns
self