Sub topic 14
Keeping segments fresh: refresh, drift and activation
This chapter assumes you can read basic Python and know how RFM clusters (from the clustering chapter) and templates with fallbacks (from the dynamic content chapters) are built. A segment is a snapshot of customer behaviour. Customers change, so a segment that was accurate in March can be wrong by June. This chapter covers how to refresh segments, detect drift, and send segments to the channels that use them.
Why segments go stale
Two things go stale, and they need different fixes.
- Membership is who belongs to a segment. A customer who stopped buying last week is still labelled "loyal" until the next run.
- Definition is what the segment means. If the whole customer base shifts, for example after a price change or a new product line, the cluster centres no longer describe real groups.
Refreshing fixes membership. Detecting drift tells you when the definition needs rebuilding.
Choosing a refresh cadence
Match the cadence to how fast the underlying behaviour changes and how costly a wrong label is.
| Segment type | Typical cadence | Reason |
|---|---|---|
| Rule-based (for example, "bought in the last 30 days") | Daily or on each event | Cheap to compute, and labels change quickly |
| Predicted (churn or propensity scores) | Daily to weekly | Scores depend on recent activity, but scoring costs more |
| Clusters | Monthly or quarterly | Re-clustering can reshuffle groups, which breaks reporting |
Re-assigning customers to existing clusters is a different job from re-fitting the clusters. Assign often, using the saved scaler and model. Re-fit rarely, and version each fit so campaign results stay comparable.
Detecting drift
Drift means the data now looks different from the data the segments were built on. A common check is the Population Stability Index (PSI). It compares the distribution of a feature at fit time with its current distribution.
import numpy as np
def psi(expected, actual, bins=5):
edges = np.quantile(expected, np.linspace(0, 1, bins + 1))
edges[0], edges[-1] = -np.inf, np.inf
e = np.histogram(expected, edges)[0] / len(expected)
a = np.histogram(actual, edges)[0] / len(actual)
e = np.clip(e, 1e-4, None)
a = np.clip(a, 1e-4, None)
return float(np.sum((a - e) * np.log(a / e)))
rng = np.random.default_rng(0)
baseline = rng.normal(30, 10, 1000) # recency at fit time
current = rng.normal(40, 10, 1000) # recency today
print(round(psi(baseline, current), 2))A common rule of thumb reads PSI below 0.1 as stable, 0.1 to 0.25 as worth watching, and above 0.25 as a reason to investigate. These thresholds are conventions, not laws, so calibrate them on your own history.
Also watch segment sizes. If one segment grows from 10% to 35% of customers in a month, something has changed, either in the customers or in the data pipeline. For predictive segments, compare scores with actual outcomes once they are known.
Activation
Activation means delivering segment membership to the systems that use it: email, app, ad platforms and the website. Three habits prevent most problems.
- Send changes, not full lists, when you can. Syncing only customers who moved reduces load and lets you log each transition.
- Stamp every label with a version and a timestamp. Templates and reports can then say which segment definition was in use.
- Check consent at activation time. A customer may have withdrawn consent after the segment was computed. Filter again just before sending.
If a label is missing or too old, the content layer should fall back to a default module, as covered in the fallbacks chapter.
Exercise
A churn-risk segment is recomputed weekly. This month its PSI on the "days since last order" feature is 0.31, and the segment has doubled in size. Name two possible causes and one action to take before changing any campaigns.
Show answer
Possible causes are a real shift in customer behaviour (for example, a seasonal lull or a price change) and a data problem (for example, a broken order feed that makes customers look inactive). Before changing campaigns, check the data pipeline and recent order counts to confirm the shift is real. If it is real, re-fit or recalibrate the model and version it.