Sub topic 11
Testing with holdouts and A/B tests
This chapter assumes you know what segments and dynamic content are, and that you can read basic Python and simple statistics such as proportions and averages. It follows the chapter on decisioning and comes before the chapter on measuring incremental lift.
Why personalisation needs a test
A personalised message that gets clicks has not necessarily caused those clicks. Customers in a "high value" segment buy often anyway. If you compare them with everyone else, you measure who they are, not what your message did. A controlled test fixes this by randomly deciding who gets the treatment.
There are two designs you will use most:
- A/B test: customers are randomly split between two or more versions, for example
discount_bannerandnew_arrivals. It answers "which version works better?" - Holdout: a random group of eligible customers receives no personalisation, or only the generic default. It answers "does personalisation work at all?"
An A/B test compares versions of personalisation. A holdout compares personalisation against none. A mature programme runs both.
Designing a holdout
Follow these rules when you set one up.
- Randomise inside the eligible audience. Select the people who qualify for a segment first, then split them. Holding out random people from the whole customer base dilutes the result.
- Assign once and keep it. A customer who is in the holdout today must be there next week. Use a stable hash of the customer ID and a test name, not a fresh random draw per send.
- Keep the holdout the same size over time. A common range is 5 to 10 percent. Smaller holdouts save revenue but need longer runs to reach a clear result.
- Respect consent. Holdout customers still need valid consent for any message they do receive. They are simply not given the personalised treatment.
The function below assigns customers deterministically. It uses a hash, so the same customer always lands in the same group.
import hashlib
def assign_group(customer_id, test_name, holdout_share=0.1):
key = f"{test_name}:{customer_id}".encode("utf-8")
bucket = int(hashlib.sha256(key).hexdigest(), 16) % 10000 / 10000
return "holdout" if bucket < holdout_share else "treatment"
groups = [assign_group(i, "winback_2026") for i in range(1, 11)]
print(groups)Including the test name in the hash gives each test its own independent split. Without it, the same customers would be in every holdout.
How the flow works
Reading the result
Compare the same outcome in both groups over the same period. Here is a minimal comparison of conversion rates with a two-proportion z-test.
from math import sqrt, erf
def compare(conv_a, n_a, conv_b, n_b):
p_a, p_b = conv_a / n_a, conv_b / n_b
pooled = (conv_a + conv_b) / (n_a + n_b)
se = sqrt(pooled * (1 - pooled) * (1 / n_a + 1 / n_b))
z = (p_a - p_b) / se
p_value = 2 * (1 - 0.5 * (1 + erf(abs(z) / sqrt(2))))
return p_a, p_b, p_a - p_b, p_value
print(compare(conv_a=540, n_a=9000, conv_b=52, n_b=1000))Here a is treatment and b is holdout. The third value is the absolute lift in conversion rate. The last value is the p-value, the chance of seeing a gap this large if the two groups truly behaved the same. A small p-value, commonly below 0.05, suggests the gap is not noise. It does not tell you the gap is large enough to matter commercially.
Common errors
| Error | What goes wrong | Fix |
|---|---|---|
| Stopping when the result looks good | Repeated peeking inflates false positives | Fix the sample size or duration before launch |
| Re-randomising each send | Customers see mixed treatments and results blur | Assign once with a hash |
| Comparing segments with each other | Differences reflect the segment, not the content | Compare treatment and holdout within a segment |
| Testing many segments and keeping the winners | Some will look good by chance | Pre-register the segments, or correct for multiple comparisons |
| Changing the segment model mid-test | Treatment and holdout no longer match | Freeze definitions until the test ends |
Exercise
A team compares customers who received a personalised "lapsed" email with lapsed customers who were never emailed because they had no consent. The emailed group converts at a higher rate. Why is this not a valid holdout, and how would you fix it?
Show answer
The groups differ in more than the email. Customers who gave consent are likely more engaged, so the gap reflects consent status as well as the message. A valid holdout randomly withholds personalisation from customers who are all eligible and consented, using a stable hash on the customer ID. Customers without consent stay out of the test entirely.