Uplift Modeling in Python: Which Customers a Cyber Monday Discount Actually Moves, Checked Against a Known Truth

In a simulated retailer where the true effect of a 20% code is known for every customer, sending it to the 30% most likely buyers added 7,264 orders and $3,267 of gross profit. Sending it to the 30% a T-learner uplift model picked added 7,766 orders and $37,959. Sending it to everyone added 10,044 orders and lost $72,164. The Python, the break-even rule and how to check an uplift model without the truth.

Uplift modeling chart: change in gross profit from a 20% Cyber Monday code on a simulated 200,000-customer list. Sending it to everyone lost $72,164, a random 30% lost $21,590, the 30% likeliest buyers gained $3,267, the 30% picked by a T-learner uplift model gained $37,959, the T-learner profit rule gained $51,382 and the best possible list gained $60,629

Adobe expects Cyber Monday, today, to bring in $15.1 billion of US online spending, up 6.2% on last year, with discounts of up to 30% off list price during Cyber Week. Most of that discounting goes to a list built one way: the customers most likely to buy. Uplift modeling asks a different question, which customers buy because of the discount, and the answer is often a different list. I simulated a retailer whose 20% code has a known effect on every one of 200,000 customers, then graded the usual targeting rules against that truth.

Sending the code to the 30% most likely buyers added 7,264 orders and $3,267 of gross profit. Sending it to the 30% that a two-model uplift estimate picked added 7,766 orders and $37,959, more than eleven times as much, because the response list paid $133,924 of discount on orders that would have happened anyway. Sending the code to everyone added the most orders, 10,044, and lost $72,164. The code below runs in under ten seconds and prints every number in this piece.

What uplift modeling estimates

A purchase model estimates one probability per customer. Uplift modeling estimates the difference between two: the chance a customer buys if they get the code, minus the chance they buy if they do not. In causal inference this is the conditional average treatment effect for a customer with features x:

τ(x) = P(buy | x, code) − P(buy | x, no code)

Practitioners usually sort customers into four groups by those two probabilities. Persuadables buy only with the code. Sure things buy either way, so the code gives away margin. Lost causes buy neither way. Sleeping dogs buy less when contacted: the code teaches them to wait for a deal, or the email lands as one too many. A response model ranks sure things near the top, because they buy the most, and can rank sleeping dogs high too. Nothing in its target tells it the difference.

The most common estimate, the one Künzel, Sekhon, Bickel and Yu call the T-learner in their 2019 PNAS paper on metalearners, fits one model to the customers who got the code and another to those who did not, then takes the difference of the two predictions:

τ̂_T(x) = μ̂_1(x) − μ̂_0(x)

The S-learner fits a single model with the treatment flag as one more feature and reads the effect off by flipping the flag. Both need data where the code was assigned at random, or at least where the reasons it was assigned are recorded, so the two groups can be compared.

The break-even rule for a discount code

A code changes profit in two ways: it wins orders that would not have happened, and it cuts the margin on orders that would have happened anyway. For one customer with order value v, gross margin m and discount depth d, the change in expected gross profit from sending the code is

Δπ = v [ p_1 (m − d) − p_0 m ]

where p₁ and p₀ are the chances of buying with and without the code. The order value scales the size of the gain but not its sign. The code pays only when

p_1 / p_0 > m / (m − d)

At a 40% gross margin and a 20% code, the ratio is 0.40 / 0.20 = 2. The code has to at least double a customer's chance of buying to pay for itself. A 10% code needs a ratio of 1.33, and a 30% code, the depth Adobe expects at the Cyber Week peak, needs 4. In the simulated test below, the code lifted the buying rate from 6.83% to 11.93%, a ratio of 1.75. On average it does not pay, which is why sending it to everyone loses money and why the work is finding the customers who clear the bar.

The simulation: a randomized test with a known truth

The retailer ran a randomized test last holiday season: 120,000 customers, half of them sent a 20% code. Each customer has seven features: days since the last order, orders in the past year, average order value, email open rate, an abandoned cart in the last two weeks, the share of past orders bought on a deal, and years as a customer. How often a customer buys depends mostly on orders, recency, cart and email engagement. How much the code moves them depends mostly on the deal share and the cart, and it turns negative for frequent full-price buyers. Those are the sleeping dogs, 9.5% of this year's list.

The script fits three models on last year's test with scikit-learn's gradient boosting, scores this year's 200,000-customer Cyber Monday list, and charges each rule with the true change in orders and gross profit, which only a simulation can know. Then it grades the same scores the way a team without the truth would, on a fresh randomized holdout. It needs NumPy and scikit-learn (run here with Python 3.13, NumPy 2.5.3 and scikit-learn 1.9.1).

import numpy as np
from sklearn.ensemble import HistGradientBoostingClassifier

MARGIN, DISCOUNT = 0.40, 0.20      # gross margin and the code's depth, share of order value
BUDGET = 0.30                      # share of the list that gets the code


def simulate(n, rng):
    recency = rng.exponential(60, n).clip(1, 365)        # days since last order
    orders = rng.poisson(1.6, n)                          # orders in the last 12 months
    aov = rng.lognormal(np.log(85), 0.45, n)              # average order value, dollars
    opens = rng.beta(2, 5, n)                             # email open rate
    cart = rng.binomial(1, 0.15, n)                       # abandoned a cart in the last 14 days
    deal = rng.beta(1.4, 3.0, n)                          # share of past orders bought on a deal
    tenure = rng.uniform(0, 8, n)                         # years as a customer
    X = np.column_stack([recency, orders, aov, opens, cart, deal, tenure])

    base = (-4.1 + 0.9 * np.log1p(orders) - 0.008 * recency
            + 1.0 * cart + 2.0 * opens + 0.06 * tenure)
    loyal_full_price = (orders >= 3) & (deal < 0.2)
    lift = (0.2 + 2.0 * deal + 0.5 * cart * (deal > 0.3)
            - 0.3 * np.log1p(orders) - 0.8 * loyal_full_price)
    p0 = 1 / (1 + np.exp(-base))                          # P(buy) without the code
    p1 = 1 / (1 + np.exp(-(base + lift)))                 # P(buy) with the code
    return X, p0, p1, aov


def profit_effect(p0, p1, aov):
    """True change in expected gross profit from sending one customer the code."""
    return aov * (p1 * (MARGIN - DISCOUNT) - p0 * MARGIN)


def gbm():
    return HistGradientBoostingClassifier(max_iter=300, learning_rate=0.05,
                                          max_leaf_nodes=15, min_samples_leaf=200,
                                          random_state=0)


def qini_coefficient(score, treated, bought):
    """Area between the Qini curve and the random line, per customer (Radcliffe)."""
    order = np.argsort(-score)
    t, y = treated[order], bought[order]
    n_t, n_c = np.cumsum(t), np.cumsum(1 - t)
    y_t, y_c = np.cumsum(y * t), np.cumsum(y * (1 - t))
    gain = y_t - y_c * np.divide(n_t, n_c, out=np.zeros(len(t)), where=n_c > 0)
    random_line = gain[-1] * np.arange(1, len(t) + 1) / len(t)
    return (gain - random_line).mean() / len(t)


if __name__ == "__main__":
    rng = np.random.default_rng(2026)

    # Last year's randomized test: half the list got the code.
    X, p0, p1, aov = simulate(120_000, rng)
    w = rng.binomial(1, 0.5, len(X))
    y = rng.binomial(1, np.where(w == 1, p1, p0))
    print(f"test: {len(X):,} customers, bought {y[w==0].mean():.2%} without the code, "
          f"{y[w==1].mean():.2%} with it")

    # Two models: classic response targeting and a two-model (T-learner) uplift estimate.
    m_t = gbm().fit(X[w == 1], y[w == 1])
    m_c = gbm().fit(X[w == 0], y[w == 0])
    # S-learner: one model with the treatment flag as a feature.
    m_s = gbm().fit(np.column_stack([X, w]), y)

    # This year's Cyber Monday list, with the true effect known for every customer.
    Xn, q0, q1, aovn = simulate(200_000, rng)
    true_lift = q1 - q0
    true_profit = profit_effect(q0, q1, aovn)
    hat1, hat0 = m_t.predict_proba(Xn)[:, 1], m_c.predict_proba(Xn)[:, 1]
    s1 = m_s.predict_proba(np.column_stack([Xn, np.ones(len(Xn))]))[:, 1]
    s0 = m_s.predict_proba(np.column_stack([Xn, np.zeros(len(Xn))]))[:, 1]

    dogs = true_lift < 0
    anyway = q0 * aovn * DISCOUNT          # discount given on orders that happen anyway
    print(f"list: {len(Xn):,} customers, true lift {true_lift.mean():.4f}, "
          f"{dogs.mean():.1%} buy less with the code")

    k = int(BUDGET * len(Xn))
    rules = {
        "random 30%": rng.permutation(len(Xn)).astype(float),
        "likeliest buyers": hat1,
        "S-learner uplift": s1 - s0,
        "T-learner uplift": hat1 - hat0,
        "true uplift": true_lift,
    }
    print(f"\n{'rule (top 30%)':20s}{'extra orders':>13s}{'profit change':>15s}"
          f"{'sleeping dogs':>15s}{'paid on sure sales':>20s}")
    for name, score in rules.items():
        top = np.argsort(-score)[:k]
        print(f"{name:20s}{true_lift[top].sum():13,.0f}{true_profit[top].sum():15,.0f}"
              f"{dogs[top].mean():15.1%}{anyway[top].sum():20,.0f}")

    # A profit rule: send only when the estimated profit change is positive.
    est_profit = aovn * (hat1 * (MARGIN - DISCOUNT) - hat0 * MARGIN)
    send = est_profit > 0
    best = true_profit > 0
    print()
    for name, pick in {"profit rule": send, "best possible": best,
                       "send everyone": np.ones(len(Xn), bool)}.items():
        print(f"{name}: send to {pick.sum():,} ({pick.mean():.1%}), "
              f"extra orders {true_lift[pick].sum():,.0f}, profit change {true_profit[pick].sum():,.0f}, "
              f"paid on sure sales {anyway[pick].sum():,.0f}")

    # Without the truth: grade the scores on a fresh randomized holdout, as a team would.
    Xh, h0, h1, _ = simulate(200_000, rng)
    wh = rng.binomial(1, 0.5, len(Xh))
    yh = rng.binomial(1, np.where(wh == 1, h1, h0))
    t1, t0 = m_t.predict_proba(Xh)[:, 1], m_c.predict_proba(Xh)[:, 1]
    sh1 = m_s.predict_proba(np.column_stack([Xh, np.ones(len(Xh))]))[:, 1]
    sh0 = m_s.predict_proba(np.column_stack([Xh, np.zeros(len(Xh))]))[:, 1]
    print("\nQini coefficient on a randomized holdout (higher is better):")
    for name, score in {"likeliest buyers": t1, "S-learner uplift": sh1 - sh0,
                        "T-learner uplift": t1 - t0, "true uplift": h1 - h0}.items():
        print(f"  {name:18s}{qini_coefficient(score, wh, yh):.5f}")

The output:

test: 120,000 customers, bought 6.83% without the code, 11.93% with it
list: 200,000 customers, true lift 0.0502, 9.5% buy less with the code

rule (top 30%)       extra orders  profit change  sleeping dogs  paid on sure sales
random 30%                  3,018        -21,590           9.6%              78,608
likeliest buyers            7,264          3,267           2.6%             133,924
S-learner uplift            7,841         36,114           0.0%             111,908
T-learner uplift            7,766         37,959           0.0%             109,223
true uplift                 7,982         43,830           0.0%             106,223

profit rule: send to 69,497 (34.7%), extra orders 7,297, profit change 51,382, paid on sure sales 87,410
best possible: send to 69,745 (34.9%), extra orders 7,507, profit change 60,629, paid on sure sales 80,528
send everyone: send to 200,000 (100.0%), extra orders 10,044, profit change -72,164, paid on sure sales 260,915

Qini coefficient on a randomized holdout (higher is better):
  likeliest buyers  0.00720
  S-learner uplift  0.00871
  T-learner uplift  0.00850
  true uplift       0.00907

What the results say

The first row sends the code to the whole list, the next four to 60,000 customers each (30%), and the last two let estimated or true profit decide who gets it. Profit is the true change in expected gross profit across the whole list of 200,000.

RuleCustomers sent the codeExtra ordersGross profit changeDiscount paid on orders that would happen anyway
Send to everyone200,00010,044-$72,164$260,915
Random 30%60,0003,018-$21,590$78,608
30% likeliest buyers60,0007,264$3,267$133,924
30% by S-learner uplift60,0007,841$36,114$111,908
30% by T-learner uplift60,0007,766$37,959$109,223
T-learner profit rule69,497 (34.7%)7,297$51,382$87,410
Best possible list69,745 (34.9%)7,507$60,629$80,528

The response list is not bad at finding extra orders. It found 7,264, 94% as many as the T-learner list. Where it fails is cost: it hands $24,701 more discount to customers who were going to buy anyway, and 2.6% of its picks are sleeping dogs the code pushes away. On orders alone the two rules look close. On gross profit they are $3,267 against $37,959.

Ranking by uplift and stopping at a fixed 30% still leaves money on the table. The profit rule sends the code only where the estimated change in gross profit is positive, which is the break-even ratio above applied to each customer's two predicted probabilities. It chose 34.7% of the list, close to the 34.9% that the truth would choose, and captured $51,382 of the $60,629 available, 85%. The fixed-budget list ranked by the true uplift earns less than that, $43,830, because a ranking by extra orders is not quite a ranking by profit: a persuadable with a $40 basket ranks above a sure thing with a $300 one.

Checking uplift models without the truth: the Qini curve

A real team never sees the true column. What it can see is a randomized holdout: a fresh sample where the code was assigned at random. Rank the holdout by the model's score, walk down the ranking, and at each depth count the buyers who got the code minus the buyers who did not, scaled to the same group size. The resulting curve and the area under it are Nicholas Radcliffe's Qini measure, which his 2007 uplift modelling FAQ describes as a generalization of the Gini measure that does apply to uplift models. With N and Y the counts of customers and buyers among the top k by score, in the treated (T) and control (C) groups,

Q(k) = Y_T(k) − Y_C(k) N_T(k) / N_C(k)

The Qini coefficient in the script is the average gap between that curve and the straight line a random ranking would draw, per customer. On the holdout it put the likeliest-buyers list last at 0.00720 and the true uplift first at 0.00907, with the T-learner at 0.00850 and the S-learner at 0.00871 close together in between, which is the same story the hidden truth tells. The Qini scores extra orders, not profit, which is why the S-learner edges the T-learner here while the T-learner earns slightly more. A team that grades on Qini should also run the profit check with its own margin and discount.

Running this on your own Cyber Monday list

The method needs one thing most retailers already have and few use: a past campaign with a random holdout. If last year's Cyber Monday email went to everyone, there is nothing to learn the difference from, and no model can recover it. If it went to everyone except a random 5% or 10%, the data is there. Fit the two models on that test, score this year's list, apply the break-even rule with your own margin and code depth, and keep a fresh random holdout this year so next year's model has something to learn from.

The same two-model estimate chose whom to call in the readmission program evaluation, where ranking patients by estimated benefit instead of risk avoided 31% more readmissions with the same staff. The logic carries from hospital outreach to retail email unchanged. For a Kansas City retailer or consumer brand watching Cyber Week traffic, what to measure in AI shopping traffic covers the other half of the weekend, and the AI pilot difference-in-differences shows the same compare-against-a-control discipline for a rollout. More methods, code and program evaluations are in the causal inference research topic at Vector1 in Kansas City.

Where this breaks

The world here is one I wrote. Its true effects are smooth functions of seven clean features, the test was perfectly randomized, and nobody bought from a competitor because the code arrived late. If a real code moves customers less than the 5.02 points this one does on average, the test has to be much larger before an uplift model beats a coin. The results above come from one random seed; the gaps between rules held across seeds in the extended analysis, but the exact dollars move.

Gross profit here ignores everything after the sale: returns, the lifetime value of a customer won with a code, and the habit a code builds in the people who get it every year. Sleeping dogs are built into this simulation on purpose. In a real list they may be rarer, or they may be the customers who quietly unsubscribe, which a 7-day purchase window never sees. And an uplift model only knows the code it was trained on. A 30% code in 2026 is not the 20% code from 2025, and the model's estimates do not transfer to a new depth without a new test.

The paid edition

The paid edition on Substack goes further: twenty replications of the whole pipeline (the T-learner list beat the likeliest-buyers list in 20 of 20), the X-learner against the T-learner when only 10% of last year's list was held out, how large the randomized test has to be (a 10,000-customer test captured 14.3% of the available profit), the 10%, 20% and 30% code compared under a stated assumption, and a decile targeting table with a reusable uplift_report() that puts a bootstrap interval on the Qini coefficient. Subscribe free for new articles by email, or get a Team License for the whole marketing science team.

About the author

Brian Curry leads Vector1, a research, applied science and machine learning lab in Kansas City that runs on a proprietary agentic operating system he designed. The lab works across data science, machine learning, AI and agentic systems, causal modeling, and system design and architecture. Over the past decade, he has directed data science, machine learning, applied and agentic AI, advanced analytics, and data architecture initiatives across major enterprises from $4 billion to $125 billion. Vector1's work includes Gedanken Galaxy (patent pending) and the open-source Python libraries PyCausalSim, for causal discovery and simulation, and Papilon, a complex systems framework for Bayesian marketing mix modeling. He previously founded KC AI Lab, expanding the regional practitioner network to over 1,500 members. His open-source frameworks, benchmarks, and research are available at vector1.ai.

More on uplift modeling, program evaluation and causal machine learning is in the Causal Inference & Simulation research area.

Sources

Related research