Multi-treatment uplift modeling in Python. multilift provides S-Learner and T-Learner
meta-learners for both continuous and binary outcomes, Qini-based evaluation, and
hyperparameter tuning — built on scikit-learn and LightGBM.
Unlike libraries that assume a single treatment arm, multilift treats
multiple simultaneous treatments as the default case: fit once, then ask which
treatment (if any) to assign to each unit.
- Meta-learners — S-Learner and T-Learner, each in regressor and classifier form
- Pipelines —
UpliftRegressorPipeline/UpliftClassifierPipelinewrap preprocessing, fitting, prediction, policy assignment, evaluation, SHAP, and save/load behind one object - Policy assignment — pick the best treatment per unit, with optional global or per-treatment uplift thresholds
- Evaluation — Qini curves and AUC, binned uplift, inverse-propensity weighting,
and separate evaluators for randomized (
explore) and policy-assigned (exploit) data - Tuning — randomized search with Qini or top-decile scoring
pip install multiliftRequires Python 3.11 or newer.
from multilift.uplift import UpliftRegressorPipeline
# X: feature DataFrame
# t: treatment assignment per row, e.g. "control" / "treatment_A" / "treatment_B"
# y: continuous outcome
pipeline = UpliftRegressorPipeline(
"control", # control group name (first positional arg)
"treatment_A", # one or more treatment group names
"treatment_B",
model_type="S", # "S" for S-Learner, "T" for T-Learner
n_estimators=100,
learning_rate=0.1,
)
pipeline.fit(X_train, t_train, y_train)
# Per-unit uplift for every treatment
predictions = pipeline.predict(X_test)
# Recommended treatment per unit
policy_df = pipeline.policy(X_test)
# Qini AUC and the underlying curve
qini_auc, qini_df = pipeline.evaluate(X_test, t_test, y_test)
pipeline.plot(X_test, t_test, y_test, name="Qini Curve")
pipeline.plot_uplift_bins(X_test, t_test, y_test, n_bins=10)
pipeline.save("model.joblib", version="1.0.0")
loaded = UpliftRegressorPipeline.load("model.joblib")UpliftClassifierPipeline has the same interface; y must be binary (0/1).
from multilift.uplift import UpliftClassifierPipeline
pipeline = UpliftClassifierPipeline(
"control",
"treatment_A",
"treatment_B",
model_type="S",
n_estimators=100,
)
pipeline.fit(X_train, t_train, y_train)
policy_df = pipeline.policy(X_test)
qini_auc, qini_df = pipeline.evaluate(X_test, t_test, y_test)To evaluate one treatment against control and only act above a minimum uplift:
policy_df = pipeline.policy_single(
X_test,
treatment_idx=0, # which treatment to evaluate
threshold=0.05, # minimum uplift required to treat
)from multilift.uplift import TLearnerTuner
tuner = TLearnerTuner(
"control",
"treatment_A",
"treatment_B",
param_grid={
"n_estimators": [50, 100, 200],
"max_depth": [3, 5, 7],
"learning_rate": [0.05, 0.1],
},
)
results = tuner.tune(X_train, t_train, y_train, X_val, t_val, y_val)
best_pipeline = tuner.fit_best(X_train, t_train, y_train)SLearnerTuner is the equivalent for S-Learner models.
| Class | Description |
|---|---|
UpliftRegressorPipeline |
End-to-end uplift pipeline for continuous outcomes |
UpliftClassifierPipeline |
End-to-end uplift pipeline for binary outcomes |
| Class | Description |
|---|---|
SLearnerRegressor |
Single model with treatment as a feature |
TLearnerRegressor |
One model per treatment arm |
SLearnerClassifier |
S-Learner for binary outcomes |
TLearnerClassifier |
T-Learner for binary outcomes |
| Name | Description |
|---|---|
SLearnerTuner / TLearnerTuner |
Randomized-search hyperparameter tuning |
TunerResult |
Container for tuning results |
qini_scorer / top_decile_scorer |
Built-in scoring functions |
| Name | Description |
|---|---|
compute_qini / compute_qini_auc |
Qini curve and AUC |
compute_best_uplift |
Best uplift among treatments, per unit |
compute_binned_uplift |
Observed uplift by predicted-uplift bin |
compute_ipw |
Inverse-propensity weights |
plot_qini_curve / plot_uplift_bins |
Plotting helpers |
UpliftExploreEvaluator |
Evaluation on randomized data |
UpliftExploitEvaluator |
Evaluation on policy-assigned data |
| Name | Description |
|---|---|
multilift.preproc.OneHotPreprocessor |
One-hot encoder with fitted-state guard |
# Install Poetry, then:
make setup # poetry lock && poetry install --all-groups
make test # pytest
make lint # isort, black, ruff --fix
make docs # build Sphinx HTML into docs/_buildCoverage:
poetry run pytest --cov=multilift.uplift --cov-report=termUse a broad --cov target such as multilift.uplift. Narrow targets like
--cov=multilift.uplift.classifier trigger a TypeError from coverage's interaction with
numpy/pandas.
See CONTRIBUTING.md.
Apache License 2.0 — see LICENSE.