Scaling, Internal Indices, an External Criterion and a Density Method
← Chapter 195
Capstone 33 · Technical Report
Technical Report

Scaling, Internal Indices, an External Criterion and a Density Method

Silhouette and stability both selected k = 2. A held-out response variable selected k = 4, which the answer key confirms at an adjusted Rand of 0.85 for k-means and 0.92 for Ward.

Data  5,693 loyalty accounts, 8 behavioral features
Methods  k-means, Ward, DBSCAN; silhouette, resampling stability, external validation
Headline  k = 4, of which 3 map to true segments; 55% of the base unclustered
Where this comes from
Chapter Chapter 195 · Clustering: Choosing k Honestly
Part Part XXXI · Capstone Projects: Machine Learning
Dataset capstone-clustering-choosing-k.xlsx
Notebook View the analysis

1. Sample and preparation

From 6,190 exported rows: a duplicated block of 190 removed on customer_id; 81 net-refund accounts with negative annual spend removed; 226 accounts with tenure_months = -1 (join date never migrated) removed. Analysis sample 5,693. Eight behavioral features; campaign_response, which records a campaign run the following quarter, was withheld from every clustering and used only for validation.

2. Scaling

Feature standard deviations span four orders of magnitude: annual_spend at 2,134.7 against discount_share at 0.248, a ratio of about 8,600. Under a Euclidean metric this makes the partition a function of spend alone.

Table 1. Between-cluster variance as a share of total, per feature, k = 4 on unstandardized data.
FeatureShare of its variance explained by k-means on raw units
annual_spend0.950
visits_per_year0.554
avg_basket0.402
categories_bought0.251
discount_share0.200
tenure_months0.142
returns_rate0.072
online_share0.068

The resulting clusters have mean annual spends of 442, 1,405, 5,017 and 7,875 dollars and are near-identical on every behavioral rate. All subsequent analysis uses z-standardized features. That choice is itself a weighting assumption, asserting equal importance per standard deviation, and a margin-weighted alternative would produce different boundaries with no test to adjudicate between them.

3. Internal criteria

Table 2. Silhouette on a 3,000-point subsample; stability is the mean adjusted Rand between the full solution and 25 refits on 80 percent subsamples.
kSilhouette, realSilhouette, uniform randomStability, realStability, random
20.36700.09500.9980.230
30.31470.08140.9970.162
40.32420.08580.9940.151
50.29320.08620.9870.198
60.27900.08550.9440.223
70.27390.08770.8230.226
100.18410.0925

Both criteria select k = 2. Both also demonstrate their own limitation. Applied to uniform random data of identical shape, silhouette still returns a maximum, at k = 2, because k-means partitions any input and silhouette merely compares partitions. What the comparison provides is a reference scale: 0.37 against 0.09 is strong evidence of structure, and that ratio is more informative than the location of either peak.

Stability separates real from structureless data decisively (0.99 against 0.15 to 0.23) and cannot separate k values within the real data, exceeding 0.98 for every k from 2 to 5. It is a test for the existence of structure, not for its cardinality.

Two panels: horizontal bars showing annual spend at 0.95 and online share at 0.07, and two silhouette curves, both with a maximum but at very different heights.
Figure 1. Left, the share of each feature's variance the raw-unit clusters account for. Right, silhouette against k for the real data and for uniform random data of the same shape.

4. External criterion

Table 3. Response to a campaign run after the observation window, never used in fitting. Base rate 0.185.
kMin cluster responseMax cluster responseSpreadChi-square pARI vs answer key
20.0550.2090.1543.6e-270.321
30.0540.2350.1812.7e-460.568
40.0530.4760.4237.7e-1790.848
50.0540.4880.4344.0e-1840.577
60.0540.4890.4351.5e-1810.471
80.0540.4950.4416.1e-1800.381

The marginal gain in separation is 0.027 for the third split, 0.242 for the fourth, and 0.011 for the fifth. The criterion selects k = 4 unambiguously, and the answer key confirms it: adjusted Rand against the true labels is 0.848 for k-means at k = 4 against 0.321 at k = 2.

Note that the chi-square p-values are uninformative here. Every partition from k = 2 upward is significant at any conventional level because n is large; the effect size is what distinguishes them. This is the standard distinction between detectable and useful, and at 5,693 accounts almost everything is detectable.

Two curves against number of segments, both turning at four.
Figure 2. The held-out campaign response spread and the agreement with the answer key, both against the number of segments. Only the first was available before the key was opened.

5. Ward and DBSCAN

Table 4. Adjusted Rand against the answer key.
kk-means ARIWard ARI
20.3210.316
30.5680.586
40.8480.924
50.5770.601
60.4710.527
70.4320.428

Ward linkage outperforms k-means at every k from 3 to 6. The true segments differ in size (978, 862, 752 within a base of 5,693) and in dispersion, and k-means implicitly favors clusters that are comparable in both.

DBSCAN at eps = 0.9, min_samples = 25 returns four dense regions and labels 55.4 percent of accounts as noise, against a true unstructured share of 54.5 percent. On the 2,538 accounts it was willing to classify it achieves an adjusted Rand of 0.963.

Table 5. DBSCAN labels against the answer key.
DBSCAN clusterBargain huntersGift occasionalsLoyal high spendersUnstructured middle
08550022
1065308
3001801
2000819
noise123996822,251

Cluster 2 consists entirely of unstructured-middle accounts: a dense region of a continuum rather than a group. Its response rate of 0.126 against a base rate of 0.185 is the diagnostic that identifies it without the answer key, and it is the same external criterion used to select k, applied per cluster.

DBSCAN is highly sensitive to eps: 0.7 yields two clusters and 91.9 percent noise, 1.5 yields one cluster and 1.0 percent noise. The parameter performs the same role as k and should be selected the same way.

Two panels: the value curves peaking at four, and a table of DBSCAN clusters against true segments.
Figure 3. Left, the external check and the answer key across k. Right, what DBSCAN found set against the true segments, including the dense patch of continuum it labeled as a cluster.

6. Limitations

The standardization choice is an unfalsifiable weighting assumption and the partition is conditional on it. Sensitivity of the recommended solution to alternative weightings (margin-weighted, rank-transformed) was not assessed and would be a reasonable addition.

The external criterion validates the partition against one outcome. Segments selected to separate price promotion response carry no guarantee of separating response to service or assortment interventions, and the validation should be repeated against any new intended use.

Cluster membership is estimated from a single twelve-month window with no measurement of transition rates. Any treatment plan that assumes persistence requires a second window.

Finally, the answer key exists only because the data were generated. On observational data none of the ARI figures in sections 4 and 5 are computable, and the external criterion is the entire basis for choosing k. That is the practical situation this analysis is designed to rehearse.

From Statistics, Data Science and AI: A Visual Handbook by John Fisher. Every statistic, table, and figure in this report is reproduced by the companion notebook.