K-Means on 4,338 customers rolled up from the UCI Online Retail invoices. Log transform, standard scale, and k of 2, the silhouette peak from 2 through 8.
The same graph as the diagram below, on the customer table rolled up from the UCI Online Retail invoices. The invoice file is Online Retail.
Transcript
The question is which of these shoppers look alike, from how recently they bought, how often, and how much they spent. This is unsupervised. The groups describe the customers in the file. They do not predict a later purchase.
The Data Loader is the node that places a dataset on the canvas. It sits under Data Source. This run uses Online Retail Customers. The invoice file was rolled up first, so the canvas holds one row per customer.
Four thousand three hundred thirty-eight customers, and three columns. Recency is days from the last invoice to 10 December 2011. Frequency is the number of invoices. Monetary is the total spend. Customer id was the grouping key and is not a feature. Country stays out. Spend is heavy-tailed, and the three columns use different units, so a raw distance would be dominated by the largest bills.
A few customers spent far more than the rest. Power transform takes the log of each column, which pulls that tail in so one large bill does not set the distance. The method stays on log. A zero recency, a purchase on the last day in the file, stays valid. Drop a node and it wires to the one before it.
After the log, the columns are still different units: days, a count of invoices, and currency. K-Means uses Euclidean distance, so the column with the widest range would dominate. Normalization rescales all three. The method is standard: zero mean and unit variance. None of the columns is left out, because each one is part of the distance.
K-Means looks for a chosen number of groups. It places a center for each group, assigns every customer to the nearest center, then moves the centers and repeats. A check of k from 2 through 8, with this same log and scale and seed 42, put the highest silhouette at 2. Calinski-Harabasz was highest there as well, and Davies-Bouldin was lowest. Silhouette and Calinski-Harabasz keep falling as k grows. Davies-Bouldin does not: it moves around after 2, and none of those later values is lower than the score at 2. So 2 is the candidate. That peak is the best of the values that were tried. It is not proof that two is the true number of segments.
Clusters is set to 2. Initialization stays k-means++, which spreads the starting centers instead of planting them at random. Ten restarts keep the best of those starts. The seed on the bar is left blank, so this run uses 42, and the same file produces the same groups.
Two evaluation nodes close the chain. The plot draws the customers so the groups can be seen. The metrics node scores how separated those groups are. Silhouette runs from minus 1 to 1, and higher means a customer is closer to the others in the same group than to the next group. Calinski-Harabasz rises when the groups are tight inside and far apart. Davies-Bouldin goes the other way: lower means the groups resemble each other less.
The chain is on screen. Data loader, the log, the standard scale, K-Means, then the plot and the metrics.
Run. All 4,338 customers go through the chain. There is no hold-out to score against.
The plot is a two-component view of all 4,338 customers. The color is the group K-Means assigned. These two axes are a view of the customers, not recency against spend. How clean the split is comes from the scores.
Silhouette is 0.4340. It is positive, so a customer sits nearer the other people in the same group than the other group. It is also well short of 1, so the boundary between the groups is real but not a hard cut. Calinski-Harabasz is 4364.4870. Higher is a stronger split, and this was the highest of the k values that were checked, which is why 2 was kept. Davies-Bouldin is 0.8918. Lower is better, and this was the lowest of that same check. It is below 1, so the gap between the groups is wider than the spread inside them. Read together, the file divides into two broad groups. These scores describe all 4,338 customers.
Pipeline Stages
Data Loader
Power Transform
Normalization
K-Means
Plot
Metrics
Data Loader. Loads the Online Retail Customers dataset (4338 samples, 3 features). Source: UCI Machine Learning Repository, Online Retail (Chen, 2015). License: CC BY 4.0.
Power Transform. Log (log1p) of recency, frequency, and monetary value. A zero recency stays valid.
Normalization. Standard scaler. The three columns are different units.
K-Means. k=2, seed 42. The silhouette peak for k from 2 through 8.
Plot. A two-component view of the customers. Color is the group. The axes are not recency against spend.
This pipeline loads the customer table rolled up from the UCI Online Retail invoices, 4,338 customers, and runs K-Means. Recency is days from each customer's last invoice to 2011-12-10, the day after the last invoice in the file. Frequency is the number of distinct invoices. Monetary value is the sum of quantity times price. Power transform takes the log of each column, then a standard scaler puts the three columns on one scale. K-Means uses k=2 and seed 42.
Why This Pipeline Works
The invoice file is one row per product line, and spend is heavy-tailed, so the fit uses the customer table. A log keeps a zero recency valid and compresses large spend. The three columns are different units, so the standard scaler puts them on one scale before K-Means. k of 2 is the highest silhouette for k from 2 through 8 with that log, that scale, and seed 42. Calinski-Harabasz was highest there as well, and Davies-Bouldin was lowest. Silhouette and Calinski-Harabasz keep falling as k grows. Davies-Bouldin is not monotone after 2, and none of the later values is lower. That peak is a candidate, not proof that two is the true number of segments. Country stays out, and the customer id is the grouping key rather than a feature.
Expected Output
The published fit, computed on 2026-11-04 with scikit-learn 1.4.2, has 2 clusters on 4,338 customers. Silhouette is 0.4340. Calinski-Harabasz is 4364.4870. Davies-Bouldin is 0.8918. The groups hold 2,682 and 1,656 customers. The voice says those three scores. Silhouette is positive and well short of 1. Davies-Bouldin is below 1.