Skip to content

Diogo TravassosData leadership · Analytics · Decision-making

Real public data

Customer segments with clustering

In one retailer's orders, none of 24 silhouette-picked clusterings predicted reorders better than a recency-and-value rule; 29 of 96 with 5 to 8 segments did, by 0.01 to 0.04 AUC.

Main limitation One wholesaler-heavy UK gift-ware retailer and two decision dates; the gains are a few hundredths of AUC.

k-means on recency, frequency and value, by number of segments (1 June 2011)

AUC for ordering again within 180 days, minus the rule's 0.73; 4,315 customers, 95% intervals

Silhouette pickOther counts and referencesRule−0.08−0.040+0.04+0.08AUC minus the rule'sk-means on recency, frequency and value, 2 segments (the silhouette pick): AUC 0.69 against the rule's 0.73, −0.04 (interval −0.05 to −0.02); stability (ARI) 0.972 segmentsk-means on recency, frequency and value, 3 segments: AUC 0.73 against the rule's 0.73, 0.00 (interval −0.01 to +0.02); stability (ARI) 0.943 segmentsk-means on recency, frequency and value, 4 segments: AUC 0.74 against the rule's 0.73, +0.01 (interval 0.00 to +0.02); stability (ARI) 0.954 segmentsk-means on recency, frequency and value, 5 segments: AUC 0.75 against the rule's 0.73, +0.02 (interval +0.01 to +0.04); stability (ARI) 0.865 segmentsk-means on recency, frequency and value, 6 segments: AUC 0.76 against the rule's 0.73, +0.03 (interval +0.02 to +0.04); stability (ARI) 0.706 segmentsk-means on recency, frequency and value, 7 segments: AUC 0.76 against the rule's 0.73, +0.04 (interval +0.02 to +0.05); stability (ARI) 0.807 segmentsk-means on recency, frequency and value, 8 segments: AUC 0.76 against the rule's 0.73, +0.03 (interval +0.02 to +0.04); stability (ARI) 0.818 segmentsA model trained for the outcome (logistic regression on all seven features): AUC 0.78, +0.06 (interval +0.05 to +0.07)Trained modelDays since the last order alone, nothing fitted: AUC 0.73, 0.00 (interval −0.01 to +0.01)Recency alone
Show the data
k-means on recency, frequency and value by number of segments
SegmentsAUCMinus the ruleIntervalStability (ARI)
2 (silhouette pick)0.689−0.038−0.052 to −0.0220.97
30.731+0.004−0.008 to +0.0180.94
40.737+0.011−0.002 to +0.0230.95
50.751+0.025+0.013 to +0.0370.86
60.757+0.030+0.019 to +0.0410.70
70.762+0.036+0.025 to +0.0460.80
80.758+0.032+0.021 to +0.0430.81
Trained model0.784+0.057+0.046 to +0.070
Recency alone0.729+0.003−0.010 to +0.014
The rule0.72700.99

Intervals resample customers with the segments held fixed. The trained model and recency alone have no segments, so no stability.

Download every score (JSON)

Clustering's usual default, the silhouette score, mostly split the 4,315 active customers into two groups: recent, frequent buyers and the rest. Those segments separated who ordered again in the six months after 1 June 2011, a period the clustering never saw, less well than the study's six-cell rule (AUC 0.69 against 0.73 for k-means on recency, frequency and value). With 5 to 8 segments, 29 of the 96 clusterings beat the rule with intervals above zero, all of them on recency and value: 13 on those two alone, 15 with frequency added and 1 with product mix as well, from k-means, the mixture and Ward; none from average linkage, raw values or product mix alone. k-means on recency, frequency and value beat it by 0.025 to 0.036, at lower stability; a model trained for the outcome beat it by 0.06.

Key figures
Default clusterings above the rule 0 of 24 at the segment count their silhouette picked, on 1 June 2011 (every interval below zero) and again on 1 December 2010, where every point estimate is below the rule and 3 intervals reach zero (k-means, percentile ranks: recency and value, 4 segments; k-means, logs and z-scores: recency, frequency, value and product mix, 4 segments; k-means, percentile ranks: recency, frequency, value and product mix, 3 segments)Above the rule at 5 to 8 segments 29 of 96 clusterings whose interval lies above zero, by +0.013 to +0.036 AUC over the rule's 0.73 (27 in December). k-means on recency, frequency and value: +0.025 to +0.036 (+0.018 to +0.036 in December); its stability falls from 0.97 at 2 segments to 0.70 to 0.86Stability (adjusted Rand index) 0.86 to above 0.99 k-means and the mixture on logs and z-scores at their silhouette pick, over 100 resamples; Ward 0.22 to 0.64, average linkage 0.08 to 0.49; the rule 0.99No segment to win back 17 of 24 default clusterings had no segment that was both quiet and at or above the median past-year revenue, so a team reading them would contact no one; the rule lists 330
Terms used on this page
Segment
A group of customers that a clustering algorithm puts together because their features are close.
The rule
The first part's hand-built cut: three value tiers (top 10%, next 20%, bottom 70% by past-year revenue) times quiet or recent, six cells in all.
Silhouette
A score of how well separated the segments are; picking the number of segments with the highest score is the usual default.
AUC
The chance that a customer who ordered again gets a higher score than one who did not: 0.5 is a coin toss, 1 is perfect. Here a customer's score is the share of its segment that ordered again, estimated on other customers.
Adjusted Rand index (ARI)
How far two segmentations of the same customers agree, corrected for chance: 1 is identical, 0 is no better than random.
Win-back list
The customers a team would contact: here, every member of a segment whose median customer has not ordered for over 90 days and spent at least the median past-year revenue.

One customer, four feature sets

A customer on the rule's list on 1 June 2011: last order about 25 weeks before, 5 to 9 orders and about £1,800 in the past year (next 20% by revenue), about 18 units a line at a median £1.60, 50 to 99 products, about 40% of the year's buying in September to November.

On recency and value alone, k-means puts this customer with 2,758 mostly quiet, small buyers (median 194 days since the last order, £382). Add how often they ordered and the same customer moves to a segment of 1,502 frequent buyers whose median last order was 24 days before. Neither segment is quiet and valuable, and none of the four segments in the table reaches a win-back list; the rule lists this customer because it reads recency and value separately.

The same customer's segment under k-means (logs and z-scores) at the silhouette pick, by feature set
FeaturesSegmentsThe customer's segmentOn a win-back list
Recency and value22,758 customers; medians 194 days since the last order, 1 order, £382 in the past yearNo
Recency, frequency, value21,502 customers; medians 24 days since the last order, 6 orders, £2,019 in the past yearNo
Recency, frequency, value, product mix41,394 customers; medians 26 days since the last order, 6 orders, £2,124 in the past yearNo
Product mix only41,865 customers; medians 51 days since the last order, 4 orders, £1,329 in the past yearNo

The customer was chosen by a rule set before any fit: the list customer closest to the list's median recency and value, among those whose win-back status changes between feature sets. No list customer's status changed (at the silhouette pick none of the four k-means fits has a win-back segment), so the closest one overall. Counts are shown in bands and the other features rounded, so the customer cannot be picked out of the public file, and the key is not shown.

Features, scaling and distance

Every clustering at its silhouette pick scored below the rule; the worst were the ones that left one giant segment.

All 24 clusterings at the segment count their silhouette picked, against the rule (1 June 2011)

AUC minus the rule's; 95% intervals

Rule−0.24−0.16−0.080Recency and valuek-means, logs and z-scores: recency and value, 2 segments (silhouette pick): AUC 0.68 against the rule's 0.73, −0.04 (interval −0.06 to −0.03); stability (ARI) 0.98k-means, logs and z-scoresk-means, raw values: recency and value, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.73k-means, raw valuesk-means, percentile ranks: recency and value, 2 segments (silhouette pick): AUC 0.71 against the rule's 0.73, −0.02 (interval −0.03 to 0.00); stability (ARI) 0.97k-means, percentile ranksGaussian mixture: recency and value, 2 segments (silhouette pick): AUC 0.66 against the rule's 0.73, −0.07 (interval −0.08 to −0.06); stability (ARI) 0.98Gaussian mixtureWard hierarchical: recency and value, 2 segments (silhouette pick): AUC 0.68 against the rule's 0.73, −0.05 (interval −0.06 to −0.03); stability (ARI) 0.64Ward hierarchicalAverage linkage, Manhattan: recency and value, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.19Average linkage, ManhattanRecency, frequency, valuek-means, logs and z-scores: recency, frequency and value, 2 segments (silhouette pick): AUC 0.69 against the rule's 0.73, −0.04 (interval −0.05 to −0.02); stability (ARI) 0.97k-means, logs and z-scoresk-means, raw values: recency, frequency and value, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.71k-means, raw valuesk-means, percentile ranks: recency, frequency and value, 2 segments (silhouette pick): AUC 0.70 against the rule's 0.73, −0.03 (interval −0.04 to −0.01); stability (ARI) 0.99k-means, percentile ranksGaussian mixture: recency, frequency and value, 2 segments (silhouette pick): AUC 0.66 against the rule's 0.73, −0.07 (interval −0.08 to −0.06); stability (ARI) 0.94Gaussian mixtureWard hierarchical: recency, frequency and value, 2 segments (silhouette pick): AUC 0.65 against the rule's 0.73, −0.08 (interval −0.10 to −0.06); stability (ARI) 0.52Ward hierarchicalAverage linkage, Manhattan: recency, frequency and value, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.08Average linkage, ManhattanRecency, frequency, value, product mixk-means, logs and z-scores: recency, frequency, value and product mix, 4 segments (silhouette pick): AUC 0.70 against the rule's 0.73, −0.02 (interval −0.04 to −0.01); stability (ARI) 0.93k-means, logs and z-scoresk-means, raw values: recency, frequency, value and product mix, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.75k-means, raw valuesk-means, percentile ranks: recency, frequency, value and product mix, 2 segments (silhouette pick): AUC 0.70 against the rule's 0.73, −0.03 (interval −0.04 to −0.01); stability (ARI) 0.98k-means, percentile ranksGaussian mixture: recency, frequency, value and product mix, 3 segments (silhouette pick): AUC 0.68 against the rule's 0.73, −0.05 (interval −0.06 to −0.03); stability (ARI) 1.00Gaussian mixtureWard hierarchical: recency, frequency, value and product mix, 2 segments (silhouette pick): AUC 0.66 against the rule's 0.73, −0.07 (interval −0.09 to −0.05); stability (ARI) 0.41Ward hierarchicalAverage linkage, Manhattan: recency, frequency, value and product mix, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.29Average linkage, ManhattanProduct mix onlyk-means, logs and z-scores: product mix only, 4 segments (silhouette pick): AUC 0.65 against the rule's 0.73, −0.08 (interval −0.09 to −0.06); stability (ARI) 0.86k-means, logs and z-scoresk-means, raw values: product mix only, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.67k-means, raw valuesk-means, percentile ranks: product mix only, 7 segments (silhouette pick): AUC 0.67 against the rule's 0.73, −0.05 (interval −0.07 to −0.04); stability (ARI) 0.81k-means, percentile ranksGaussian mixture: product mix only, 2 segments (silhouette pick): AUC 0.58 against the rule's 0.73, −0.14 (interval −0.17 to −0.12); stability (ARI) 0.97Gaussian mixtureWard hierarchical: product mix only, 2 segments (silhouette pick): AUC 0.57 against the rule's 0.73, −0.16 (interval −0.18 to −0.14); stability (ARI) 0.22Ward hierarchicalAverage linkage, Manhattan: product mix only, 2 segments (silhouette pick): AUC 0.49 against the rule's 0.73, −0.24 (interval −0.26 to −0.22); stability (ARI) 0.49Average linkage, ManhattanAUC minus the rule's
Show the data
Every clustering at the silhouette pick
ClusteringSegmentsAUCMinus the ruleStability (ARI)AUC, 1 December 2010
k-means, logs and z-scores: recency and value20.68−0.040.980.68 (2 segments)
k-means, raw values: recency and value20.49−0.240.730.49 (2 segments)
k-means, percentile ranks: recency and value20.71−0.020.970.73 (4 segments)
Gaussian mixture: recency and value20.66−0.070.980.64 (2 segments)
Ward hierarchical: recency and value20.68−0.050.640.63 (2 segments)
Average linkage, Manhattan: recency and value20.49−0.240.190.49 (2 segments)
k-means, logs and z-scores: recency, frequency and value20.69−0.040.970.69 (2 segments)
k-means, raw values: recency, frequency and value20.49−0.240.710.49 (2 segments)
k-means, percentile ranks: recency, frequency and value20.70−0.030.990.70 (2 segments)
Gaussian mixture: recency, frequency and value20.66−0.070.940.68 (2 segments)
Ward hierarchical: recency, frequency and value20.65−0.080.520.68 (2 segments)
Average linkage, Manhattan: recency, frequency and value20.49−0.240.080.50 (2 segments)
k-means, logs and z-scores: recency, frequency, value and product mix40.70−0.020.930.72 (4 segments)
k-means, raw values: recency, frequency, value and product mix20.49−0.240.750.49 (2 segments)
k-means, percentile ranks: recency, frequency, value and product mix20.70−0.030.980.72 (3 segments)
Gaussian mixture: recency, frequency, value and product mix30.68−0.051.000.69 (3 segments)
Ward hierarchical: recency, frequency, value and product mix20.66−0.070.410.70 (3 segments)
Average linkage, Manhattan: recency, frequency, value and product mix20.49−0.240.290.49 (2 segments)
k-means, logs and z-scores: product mix only40.65−0.080.860.62 (4 segments)
k-means, raw values: product mix only20.49−0.240.670.49 (2 segments)
k-means, percentile ranks: product mix only70.67−0.050.810.69 (8 segments)
Gaussian mixture: product mix only20.58−0.140.970.63 (2 segments)
Ward hierarchical: product mix only20.57−0.160.220.67 (4 segments)
Average linkage, Manhattan: product mix only20.49−0.240.490.49 (2 segments)

The rule's AUC is 0.73 on 1 June 2011 and 0.73 on 1 December 2010. Stability was measured at the June date only.

Download every score (JSON)

Stability across resamples

Refit on 100 resamples of the customers, k-means and the mixture mostly give the same segments; the hierarchical fits do not.

Each fit was rerun on 100 bootstrap resamples of the 4,315 customers, and every customer assigned to a segment of each refit. The adjusted Rand index compares those segments with the full-data ones. The rule, refit by setting its revenue cut points on each resample, scored 0.99; 97% of customers stayed in their cell in at least 90 of 100 resamples. For k-means on recency, frequency and value, 98% stayed in their segment at 2 segments and 64% at 7.

Mean adjusted Rand index over 100 resamples, recency, frequency and value, by number of segments; the rule: 0.99
Algorithm2345678
k-means, logs and z-scores0.970.940.950.860.700.800.81
Gaussian mixture0.940.780.880.810.860.930.93
Ward hierarchical0.520.420.500.490.480.490.47
Average linkage, Manhattan0.080.070.570.640.640.610.59

Who would get a contact

Read the usual way, the default segments either name no one to win back or name almost everyone.

A team turning segments into a contact list needs a rule; the one set in advance picks every segment whose median customer has not ordered for over 90 days and spent at least the median past-year revenue. At the silhouette pick, 17 of the 24 clusterings have no such segment: two segments split recent from quiet, and the quiet half is mostly small buyers. The lists that do appear come from product mix or from one giant segment, and they overlap the rule's list by under a tenth.

Across all 168 fits at this date, 94 gave a list and none met the first part's bar (at least 50% of the lost revenue with at most 35% of quiet customers). The best within the size cap, k-means, logs and z-scores: recency and value with 7 segments, listed 759 customers and held 49.6% of the lost revenue, against the rule's 38% with 330. That comparison was added after the results.

Win-back lists at the silhouette pick, logs and z-scores (1 June 2011): size, overlap with the rule's list (Jaccard), share of the lost revenue held, and share of the list not yet quiet
ClusteringSegmentsOn the listOverlapLost revenue heldNot yet quiet
k-means, logs and z-scores: recency and value2No segment qualifies
Gaussian mixture: recency and value2No segment qualifies
Ward hierarchical: recency and value2No segment qualifies
Average linkage, Manhattan: recency and value24,2980.08100%45%
k-means, logs and z-scores: recency, frequency and value2No segment qualifies
Gaussian mixture: recency, frequency and value2No segment qualifies
Ward hierarchical: recency, frequency and value2No segment qualifies
Average linkage, Manhattan: recency, frequency and value2No segment qualifies
k-means, logs and z-scores: recency, frequency, value and product mix4No segment qualifies
Gaussian mixture: recency, frequency, value and product mix3No segment qualifies
Ward hierarchical: recency, frequency, value and product mix2No segment qualifies
Average linkage, Manhattan: recency, frequency, value and product mix24,3050.08100%45%
k-means, logs and z-scores: product mix only4No segment qualifies
Gaussian mixture: product mix only22,8700.1076%43%
Ward hierarchical: product mix only23,0810.0970%45%
Average linkage, Manhattan: product mix only24,3050.08100%45%
The rule's list6 cells330138%0%

What I expected, and what happened

9 of 15 predictions held, 4 missed and 2 could not be tested.

The misses say the default clusterings did worse than I expected against the rule, the mixture was steadier than I expected on product mix, and average linkage was less lopsided. The two untestable ones failed for the reason the page is about: at the silhouette pick there was no win-back segment to compare.

The 15 predictions, written before any fit, scored on the point estimate
PredictionResultEstimateNote
k-means on recency, frequency and value, at the silhouette pick, lands within 0.03 of the rule's AUCMissed−0.038 (interval −0.052 to −0.022)below the band: the two segments separate less than the rule
No clustering at its silhouette pick beats the rule's AUC by more than 0.03Held−0.018
The trained model beats the rule by at least 0.04, and every clustering at its silhouette pickHeld+0.057 (interval +0.046 to +0.070)the interval stays above the band
Recency alone is no more than 0.02 below the rule's AUCHeld+0.003 (interval −0.010 to +0.014)
Every product-mix clustering at its silhouette pick is at least 0.05 below the rule's AUCHeld−0.054
k-means on recency, frequency and value: stability at least 0.80 at 2, 3 and 4 segmentsHeld0.94
The same at 8 segments is at least 0.10 below 3 segmentsHeld−0.13
At 4 segments the mixture is less stable than k-means on every feature setMissed+0.11on product mix alone the mixture was the more stable
k-means on raw values puts at least 90% of customers in one segment at 2 to 5 segmentsHeld92%close to a safe bet: on raw values the largest-variance feature, money, decides
Average linkage with Manhattan distance puts at least 90% in one segment at 4 segments, every feature setMissed68%on recency, frequency and value its largest segment held less than 90%
The silhouette picks 2 or 3 segments in at least 12 of the 16 logs-and-z-scores fitsHeld14
The k-means list on recency and value overlaps the rule's list by at least 0.4Untestablenoneno segment met the win-back rule, so there was no list to compare
The k-means list on product mix overlaps the rule's list by at most 0.2Untestablenoneno segment met the win-back rule, so there was no list to compare
No logs-and-z-scores clustering at its silhouette pick gives a list that meets the first part's barHeld0held, but only 5 of the 16 gave a list at all
On 1 December 2010, k-means on recency, frequency and value lands within 0.03 of the rule's AUCMissed−0.033 (interval −0.048 to −0.019)below the band, as in June

What a team should do with this

Limits

How this was checked

The protocol was committed unchanged before any clustering was fitted, and the months after each date were read only once the fitted segments were committed. The rule rebuilt here matches the first part exactly: the same customers, the same 330 on the list, and the same share of lost revenue.

Added after the results, none touching a fit, a prediction or its verdict: win-back lists under 11 customers are withheld like segments, the worked example's counts are shown in bands, and intervals against the rule for every clustering at 5 to 8 segments, on the same resamples. Each is labelled in the design (section 12).

Tests check each algorithm on constructed groups it must recover exactly, the features and scores on small constructed customers whose answers follow from their construction.

Use this at your company

To run the same comparison on your own customers, paste this prompt into an AI assistant along with your data.

This method comes from Diogo Travassos's study "Customer segments with clustering" (https://diogotravassos.dev/retail-win-back/customer-segments.html). If you can open links, read it first: it works the method through end to end, with its checks. The steps below stand on their own if you can't.

Help me segment my customers with clustering, and check whether the segments are stable and useful before a team acts on them.

Data: order lines with customer id, order id, order date, product code, quantity and unit price, cancellations included.

Steps:
1. Pick a decision date. Build features from the year before it only: days since the last order, number of orders, net revenue, and product mix (units per line, unit price, distinct products, share bought in the peak season).
2. Before fitting anything, write down the feature sets, the scalings, the algorithms, the range of segment counts, how the count will be chosen, the stability measure, the rule that turns segments into an action, and what you expect, with ranges.
3. Fit k-means and at least one alternative (a Gaussian mixture or hierarchical clustering) on each feature set, on logs and z-scores and on raw values, for 2 to 8 segments.
4. Stability: refit on 100 bootstrap resamples of the customers and report the adjusted Rand index against the full-data segments.
5. Usefulness: on the months after the date, which the clustering never saw, score each segmentation by how well its segment rates, estimated out of fold, separate who orders again (AUC). Compare with my current rule, with days since the last order alone, and with a model trained for that outcome.
6. Apply the action rule to every segmentation and compare each contact list with my current list.

Checks: withhold segments under 11 customers; never pick features or the segment count by the holdout outcome; label anything added after seeing results.

Report: for each choice, the segment sizes, the stability, the usefulness against my rule and the contact list it implies, and whether any segmentation should replace the rule.

In your report, say which study you followed and link it: https://diogotravassos.dev/retail-win-back/customer-segments.html

Method and checks

Set in advance

The question, the four feature sets, the three scalings, the four algorithms and their distances, 2 to 8 segments, choosing the count by the silhouette, the stability measure, the holdout split, the win-back rule, the worked example's selection and 15 predictions with their bands were written down before any clustering was fitted: DESIGN-segments.md and protocol-segments.json. Nothing in the protocol changed afterwards.

Data and features
  • The first part's cleaning, unchanged, and its population: customers with positive net revenue and an order in the 365 days before the date (4,315 on 1 June 2011, 4,225 on 1 December 2010).
  • Features from those 365 days only: days since the last order, distinct orders, net revenue, mean units per sale line, median unit price, distinct products, and the share of gross sales bought in September to November.
  • Outcome, from the 180 days after the date only: ordered again. 57% of customers did on 1 June 2011 and 48% on 1 December 2010.
Scalings, algorithms and the count
  • Logs and z-scores (log of one plus each feature except the autumn share, then standardized), raw values, and percentile ranks. k-means on all three; the others on logs and z-scores.
  • k-means with 10 starts; a Gaussian mixture with full covariance and 3 starts; Ward linkage; average linkage with Manhattan distance. 168 fits a date.
  • The count: the highest silhouette, ties to fewer segments.
Stability and usefulness
  • Stability: 100 bootstrap resamples; each refit assigns every customer (the hierarchical fits by the nearest segment centre); mean adjusted Rand index against the full-data segments, and the share of customers in their matched segment in at least 90 of the resamples.
  • Usefulness: 5 folds of customers; a customer's score is its segment's share that ordered again among the other folds. AUC over all customers, and over quiet customers only: there the rule scored 0.56 and recency alone 0.62.
  • Intervals: 1,000 paired resamples of customers, scores held fixed.
  • References: the rule's six cells; days since the last order alone; a logistic regression on all seven features, trained out of fold.
Added after the results

The comparison of the best list within the size cap against the rule's list, and the count of fits above the rule across all segment counts, are descriptions of declared fits added after the results; neither is scored.

Reproduce it

make segments rebuilds the features, fits and stability from the public download, and make segments-score scores the holdout period and renders this page. The packages are pinned with hashes in requirements-segments.lock. No key and no network beyond the data download.