Show the code of the figure
show(lambda: figures.day_shapes(story.shapes, story.truth, choice.PATTERNS))December 5, 2026
A planner at a distribution company must set, by Friday, the thresholds that flag unusual meters on one street of 124 households. Each threshold is learned from the meters of one group of similar daily patterns, so the planner first has to decide how many groups there are. The silhouette, a common index of the quality of a clustering, chooses five. One of the five groups holds four meters. A threshold learned from four meters cannot hold a false-alarm rate of one in ten, and no list of true groups exists to show whether five is right.
The street of this story is synthetic and built so that the answer is known: 120 households follow four daily patterns, 30 each, four meters follow no routine, and one vacant meter reads a constant and is removed. The answer is four. The silhouette, the Calinski-Harabasz index, the majority vote and the inertia elbow all miss it on this street, and only the Davies-Bouldin index finds it. Any clustering of load profiles meets the same question. The number of groups has to be chosen from the readings alone, and the common indices answer it differently.
This post shows a procedure that answers it without labels and states what each step can and cannot establish. The procedure follows the chapter Validating Clusters of the book Finding Structure in Time Series. Its representation and objective come from Clustering Profiles of Load and Demand, and its design check from Clustering Design and Verification. The procedure has three parts. A diversity-weighted Borda rank combines the indices. A minimum group size, taken from the decision, removes the groups that the decision cannot use. A check against structureless data shows whether the chosen partition is more than chance. The computations use the clustering module of the library milia, which is installed as pundamilia.
Figure 1 shows the 124 meters of the story. The four planted patterns peak at night, in the morning, in the middle of the day and in the evening, and their means are well apart. The four meters without a routine do not follow any of them: each has readings that move between a third of its peak and the peak with no daily shape. A clustering has no way to know that these four are not a pattern of their own. That is the source of the trouble in the sections that follow.
A partition of meters into groups assigns each meter a label. When true labels exist, the partition is scored against them by an external measure such as the adjusted Rand index, which counts the pairs of meters that the two groupings treat alike and corrects that count for chance.1 A utility almost never holds true labels for its customers. The partition then has to be judged from the readings alone, by internal indices that score how compact each group is and how far the groups lie apart, and by resampling checks that ask whether the groups reappear on another sample.
Each meter is described here by its mean day over a week of half-hourly readings, divided by its peak, so that a meter is a curve of 48 values between 0 and 1. The division removes the size of the load and keeps its timing, which is what the thresholds of the story depend on. The groups are found by -means for every candidate from 2 to 8. The question of the post is which of the seven partitions to keep.
Three internal indices are in common use. The silhouette of meter compares its mean distance to the other members of its group with its mean distance to the members of the nearest other group,2
and the silhouette of a partition is the mean of , near 1 when every meter sits well inside its group. The Calinski-Harabasz index is the ratio of the spread between the group centres to the spread within the groups, each divided by its degrees of freedom, and larger is better.3 The Davies-Bouldin index takes, for each group, the worst ratio of the summed spreads of two groups to the distance between their centres, and averages it over the groups, so smaller is better.4 Two further rules are common. The inertia elbow takes the at which the within-group sum of squares stops falling steeply. The majority vote takes the that most indices prefer.
An experimental comparison of 30 validity indices in many settings of different characteristics ends with guidance on the index that suits each application, not with a single best index.5 Load profiles are no exception: the indices can recommend different partitions of the same profiles, and the appropriate index depends on the characteristics of the data.6 Figure 2 shows what each rule chooses on the street of the story.
Five of the seven rules choose five groups and the elbow chooses six. Only the Davies-Bouldin index returns the planted four. The reason is the group of four meters without a routine. At five groups -means gives them a group of their own and leaves the four planted patterns intact, 30 meters each. At four groups the four strays join the 30 morning households, so the morning group is less compact. The silhouette rises from 0.691 at four groups to 0.724 at five, and the Calinski-Harabasz index from 273 to 367. Separating a few odd meters makes every group tighter, and the silhouette and the Calinski-Harabasz index reward it, while the Davies-Bouldin index worsens from 0.529 to 0.630.
The failure is not an accident of one index. Each index measures compactness and separation, and a group of four meters that resemble nothing else is both compact enough and far from the rest. The inertia falls with every added group by construction, so its elbow is a judgement of where the fall slows, and here it reads six. The majority vote counts the preferences of the indices and the two resampling checks of the next section, so it inherits their shared error.
Internal indices score one partition of one sample. A second line of evidence asks whether the groups would reappear if the meters were sampled again. The prediction strength of Tibshirani and Walther splits the meters into a training part and a test part and clusters each.7 For every group of the test part it takes the pairs of meters in that group and asks which share of them the centres of the training part also put together. The prediction strength is the smallest of these shares over the groups,
where is test group , its size, and means that the centres of the training part put meters and in the same group. The authors take the largest whose prediction strength is above a threshold, and report that a threshold of 0.8 to 0.9 works for well-separated groups. The stability of the least stable cluster, from Hennig, resamples the meters with replacement, reclusters them, and records for each original group its best Jaccard agreement with a group of the resample.8 The smallest mean agreement over the groups is the stability of the partition.
Neither check rescues the story. The prediction strength is 0.829 at four groups and 0.889 at five, both above the bar of 0.8, and the stability is 0.958 and 0.985. The four strays are as reproducible a group as any, because their curves are far from every pattern and fall together in every resample. The rule of Tibshirani and Walther, the largest above 0.8, also chooses five here. Reproducibility shows that a group is real in the sample. It cannot show that the group is useful for the decision.
The indices fail for different reasons, and errors with different causes need not point to the same wrong answer. That is the case for combining them. A Borda count, the voting rule in which each voter ranks the options and an option collects points by its position,9 treats each index as a voter and each as an option. Every index is oriented so that larger is better, so the Davies-Bouldin index enters with its sign reversed. The candidates are then ranked on each index from 1, the worst, to 7, the best. The score of a candidate is its weighted sum of ranks,
and the candidate with the largest score is proposed. The voters are the silhouette, the Calinski-Harabasz and Davies-Bouldin indices, the prediction strength, the stability, and the balance of the group sizes, which is the entropy of the sizes divided by and equals 1 when the groups are of equal size. The inertia and the Bayesian information criterion improve as grows whatever the data are, so they are not ranked: a voter that always prefers the largest would only push the count towards it. Equal scores go to the smaller .
A rank uses the order of the candidates on each index and not the size of the differences. The Calinski-Harabasz index runs from 77 to 367 on the story and the silhouette from 0.44 to 0.72, and a rank puts both on the same scale without a choice of normalisation. The price is that a near tie on one index counts as a full step.
Indices that measure nearly the same thing should not vote as if they were independent. The silhouette and the Calinski-Harabasz index both reward compact, separated groups, so with equal weights that view would count twice. Each weight is therefore set by the independence of its index. Let be the mean absolute Spearman correlation of index with the other indices across the seven candidates. Its weight is
so an index that repeats the others receives little weight, and the floor of 0.05 keeps every index in the count. The weights sum to one, so the score lies between 1 and 7. The equal-weight Borda count, with every , is the plain count.
On the story the weights are close to equal, from 0.140 for the prediction strength to 0.189 for the stability, because the six indices disagree about as much with one another. The weighted rank scores five groups 5.80 and four groups 5.37, so it also proposes five. The rank is a proposal, and on this street it makes the same mistake as most of its voters, because they share the cause of the mistake. The study of thirty streets below shows where the weights matter.
The decision of the story supplies what the indices lack. Each group sets a threshold that flags a meter whose readings are unusual for its group, with a false-alarm rate of . A conformal threshold does this without assuming a distribution.10 It ranks the scores of the meters of the group and takes the score of rank . That rank exists only if it is at most , which requires
A group of fewer than nine meters cannot hold the false-alarm rate. Candidates whose smallest group is below nine therefore leave the ranking before the score is read. The weights are still computed over all seven candidates, so the minimum changes which candidates may win and not how the indices are weighted. Figure 3 shows the scores and the smallest group of each candidate.
Five groups have the largest score, 5.80, and a smallest group of four meters, the four strays. Six to eight groups split off single meters. The minimum of nine removes all four candidates, and of the admissible three the rank chooses four groups, the planted number, with a smallest group of 30. The minimum did the work here that no index could. It did not come from the data, which cannot tell a small real pattern from a few odd meters, but from the decision the groups serve.
The constraint has a cost. A real minority pattern smaller than the minimum can no longer form a group of its own. Under the minimum, its meters join the nearest larger group, as the four strays join the morning group at four groups. For the thresholds of the story this is the right outcome: the strays are the meters the threshold of the morning group should flag. A minority that matters to another decision needs a minimum from that decision.
A rank says which candidate is best among those tried, and not whether any of them is real. Data with no groups at all still yield a best . The resampling checks have a further bias: their raw values fall as grows even when there is no structure. A partition of structureless data into two halves reappears often on a resample, and a partition into five pieces less often. Lange and colleagues make the same point for their stability measure, whose range depends on , and they normalise it by the stability of a predictor that assigns labels at random.11
The check used here follows that idea with a reference of structureless data. For each candidate the three resampling checks, the prediction strength, the stability of the least stable cluster and the agreement between the partitions of two subsamples, are computed on the meters. They are computed again on five draws of meters spread uniformly over the range of each half-hour. The excess of a check is its value on the data minus its mean on the reference,
the same comparison with a reference distribution that the gap statistic makes for the within-group dispersion.12 A candidate passes if every excess is positive. Figure 4 shows the three excesses for three to five groups of the story.
Every excess is positive and large, between 0.62 and 0.89, at three, four and five groups. The raw prediction strength of structureless data falls from 0.334 at three groups to 0.237 at four and 0.175 at five, close to , so the reference absorbs the fall that a raw threshold would read as weaker structure. The excess is largest at five groups, 0.793 on average against 0.738 at four. The group of four strays is real in the sense that matters for this check: it reappears far more often than chance would allow.
The check against chance therefore cannot choose between four and five. It shows that neither partition is an artefact of chance, and it says nothing about which of two real partitions serves the decision. That is why the rank and the minimum come first and the check comes last. Its role is to stop a partition of data that have no groups, which a rank alone would never do.
One street can be lucky. The study draws the street again with 30 seeds at a noise of 0.3, as in the story, and at a noise of 1.0, at which the four patterns overlap. On each street every rule chooses without a minimum and with a minimum of nine. Figure 5 counts the streets on which each rule recovers the planted four.
Without a minimum no rule is reliable at low noise. The silhouette, the Calinski-Harabasz index and the majority vote never recover four, because on every street the four strays form a fifth group. The equal-weight count recovers four on 13 streets, the weighted count on 11 and the Davies-Bouldin index on 10. With the minimum of nine every rule except the elbow recovers four on all 30 streets. The constraint does most of the work, and the choice of rule then hardly matters.
At high noise the picture changes, and the weights earn their place. Without a minimum the weighted Borda count recovers four on 27 streets, against 16 for the equal-weight count and 14 for the Calinski-Harabasz index; the silhouette, the Davies-Bouldin index and the majority vote recover none. With the minimum the weighted count, the silhouette and the Calinski-Harabasz index recover four on all 30, while the equal-weight count, the majority vote and the Davies-Bouldin index recover it on 23. When the patterns blur, the indices err in different directions. The diversity weights keep one family of indices from outvoting the rest. At this noise the weighted rank is the only rule that is near the truth both with and without the minimum. The elbow never recovers four, at either noise.
Metered households carry no planted answer, so the procedure can only be read for consistency. Two populations are used, each described by its peak-normalised mean day over 360 days. The first is 1,284 households of the Low Carbon London trial in 2013.13 The second is 997 households of the Spanish energy cooperative GoiEner from June 2021.14 The same sweep, rank with a minimum of nine and check against chance were run on both. Figure 6 sets the excess over chance beside the choice of the rank.
On both populations the weighted Borda rank chooses two groups, and the minimum of nine changes nothing, because the smallest groups hold dozens of households. For London the silhouette, the Calinski-Harabasz index and the majority vote agree on two, and the Davies-Bouldin index chooses three. For GoiEner the indices disagree most: the silhouette chooses four, the Davies-Bouldin index three and the Calinski-Harabasz index two. The silhouette is 0.271 at two groups for London and 0.245 at four for GoiEner, against 0.691 for the planted street. The groups of real households overlap far more.
The check against chance tells a different story from the rank. Every candidate from two to five groups beats structureless data on both populations, so none of them is an artefact. The excess is largest at three groups for London, 0.672 against 0.533 at two, and at five for GoiEner, 0.563 against 0.435 at two. The reason is the bias of the previous section. The rank reads the raw prediction strength and stability, which fall with even on structureless data: from 0.501 at two groups to 0.335 at three on the London reference. When the structure is weak, the rank therefore leans to the coarse partition, and the excess leans to a finer one.
The two readings support a clear decision. Two groups are supported by every view: the rank, the minimum and the check against chance. A finer partition, three groups for London or four to five for GoiEner, is more than chance but rests on weaker evidence. It needs support from outside the readings, such as a known change of behaviour or a group that a programme can name, before a threshold or a tariff rests on it. On the London prediction strength, 0.806 at two groups and 0.787 at three, only two groups clear the bar of 0.8.
The steps below apply to any clustering of load profiles, or of other series, when no true grouping exists.
On the street of the story these steps choose four groups. The minimum removes the five-group partition that every separation index preferred, the rank chooses four among the rest, and the check confirms that four is far from chance.
The question was how many groups a set of load profiles has when no true grouping exists. On a street of 120 households on four planted patterns and four meters without a routine, five of seven rules chose five groups. The fifth group was the four strays, which every separation index rewards and every resampling check finds reproducible. The diversity-weighted Borda rank combines the indices with weights that measure their independence, and on that street it also chose five, with a score of 5.80 against 5.37 for four.
The decision of the story, a conformal threshold at a false-alarm rate of 0.1, requires at least nine meters per group. With that minimum the rank chose the planted four. Over 30 streets at low noise the minimum lifted every rule but the elbow to 30 of 30 recoveries, from at most 13 without it. At high noise the weighted rank recovered four on 27 streets without the minimum and on 30 with it. That is the best of any rule at high noise, and it shows that the weights matter where the indices disagree. The check against chance confirmed that every partition tried was more than chance, but it could not separate a real partition that serves the decision from one that does not.
On 1,284 London households and 997 GoiEner households the rank chose two groups, while the excess over chance was largest at three and five. The rank leans to coarse partitions on weak structure, because raw reproducibility falls with even without structure. The data support two groups firmly and a finer partition only with evidence from outside the readings.
The planner of the story should therefore set four thresholds and not five. The four meters without a routine then fall in the morning group, where its threshold flags them. The number of groups was not found by an index. The indices proposed candidates, the decision removed those it could not use, and the check against chance confirmed that the rest were real.
The notebook is in the bayesian-modelling repository and runs from the first cell to the last in its uv environment. The populations of the story and of the study are drawn by functions of bayes.clustering.choice, and the sweep, the rank, the minimum size and the check against chance are those of milia.cluster. The sweeps and the study are computed on the first run and stored. The readings of the two metered populations are not shipped, so their stored scores are read instead; they were computed with the same functions. The figures are functions of bayes.plot.choice, and both modules have unit tests.
The articles of Tibshirani and Walther and of Lange and colleagues were read in full. The articles of Arbelaitz and colleagues, of Jain and colleagues and of Quesada and colleagues were read by abstract only. The other sources were not read and are cited for their subject or their standard definitions only. Every bibliographic record of a peer-reviewed source was verified on Crossref, except the paper of Lange and colleagues, which was checked against the proceedings of NeurIPS.
[1] L. Hubert and P. Arabie, “Comparing partitions,” Journal of Classification, vol. 2, no. 1, pp. 193–218, 1985, doi:10.1007/BF01908075.↩︎
[2] P. J. Rousseeuw, “Silhouettes: A graphical aid to the interpretation and validation of cluster analysis,” Journal of Computational and Applied Mathematics, vol. 20, pp. 53–65, 1987, doi:10.1016/0377-0427(87)90125-7.↩︎
[3] T. Caliński and J. Harabasz, “A dendrite method for cluster analysis,” Communications in Statistics, vol. 3, no. 1, pp. 1–27, 1974, doi:10.1080/03610927408827101.↩︎
[4] D. L. Davies and D. W. Bouldin, “A cluster separation measure,” IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. PAMI-1, no. 2, pp. 224–227, 1979, doi:10.1109/TPAMI.1979.4766909.↩︎
[5] O. Arbelaitz, I. Gurrutxaga, J. Muguerza, J. M. Pérez and I. Perona, “An extensive comparative study of cluster validity indices,” Pattern Recognition, vol. 46, no. 1, pp. 243–256, 2013, doi:10.1016/j.patcog.2012.07.021.↩︎
[6] M. Jain, M. Jain, T. AlSkaif and S. Dev, “Which internal validation indices to use while clustering electric load demand profiles?,” Sustainable Energy, Grids and Networks, vol. 32, art. 100849, 2022, doi:10.1016/j.segan.2022.100849.↩︎
[7] R. Tibshirani and G. Walther, “Cluster validation by prediction strength,” Journal of Computational and Graphical Statistics, vol. 14, no. 3, pp. 511–528, 2005, doi:10.1198/106186005X59243.↩︎
[8] C. Hennig, “Cluster-wise assessment of cluster stability,” Computational Statistics & Data Analysis, vol. 52, no. 1, pp. 258–271, 2007, doi:10.1016/j.csda.2006.11.025.↩︎
[9] P. Emerson, “The original Borda count and partial voting,” Social Choice and Welfare, vol. 40, no. 2, pp. 353–358, 2013, doi:10.1007/s00355-011-0603-9.↩︎
[10] V. Vovk, A. Gammerman and G. Shafer, Algorithmic Learning in a Random World, 2nd ed. Cham: Springer, 2022, doi:10.1007/978-3-031-06649-8.↩︎
[11] T. Lange, M. L. Braun, V. Roth and J. M. Buhmann, “Stability-based model selection,” in Advances in Neural Information Processing Systems 15, 2002, pp. 633–642, proceedings.↩︎
[12] R. Tibshirani, G. Walther and T. Hastie, “Estimating the number of clusters in a data set via the gap statistic,” Journal of the Royal Statistical Society: Series B, vol. 63, no. 2, pp. 411–423, 2001, doi:10.1111/1467-9868.00293.↩︎
[13] UK Power Networks, “SmartMeter energy consumption data in London households,” London Datastore, data.london.gov.uk. A dataset, not a peer-reviewed source.↩︎
[14] C. Quesada, L. Astigarraga, C. Merveille and C. E. Borges, “An electricity smart meter dataset of Spanish households: insights into consumption patterns,” Scientific Data, vol. 11, art. 59, 2024, doi:10.1038/s41597-023-02846-0.↩︎
@online{faustine2026,
author = {Faustine, Anthony},
title = {How {Many} {Groups:} {Choosing} {K} {Without} {Labels}},
date = {2026-12-05},
url = {https://sambaiga.github.io/pages/blog/posts/2026/12/2026-12-05-how-many-groups.html},
langid = {en}
}