liveBook · Manning

Clustering

As explained in Grokking Bayes

Clustering is the process of grouping data items so that items within a group are more similar to one another than to items in other groups.

Suppose waiting times seem to fall into short and long groups. Clustering describes those groups without requiring a group label for every observation. In a mixture model, each cluster has a center, a width, and a weight describing how prevalent it is. section 8.8

Group membership need not be an all-or-nothing decision. For a particular waiting time, evaluate how well it fits each cluster, multiply by that cluster’s mixture weight, and normalize across clusters. The result is a membership probability that can express uncertainty near the boundary. section 8.8

Choosing how many groups to allow

A two-cluster model separates short and long Old Faithful waiting times, but fixing the wrong number of clusters could split one group unnecessarily or merge distinct groups. A stick-breaking model instead generates mixture weights for additional components. In a practical ten-component version, two components receive substantial posterior weight and the others receive negligible weight; ten is an upper limit, not a claim that ten groups exist. section 8.9 section 8.10

Check the fitted model as well as its group assignments. A posterior predictive check compares simulated observations with the data. If trace plots show cluster parameters repeatedly swapping roles, label switching may be responsible: symmetric components have no inherent order. Ordering their centers can make the labels consistent across posterior draws. section 8.8 section 8.7

Figure 8.7 Top: the observed data. Bottom: the probability that a given datapoint belongs to either cluster. The cluster membership probabilities reflect the trend in the observe data.

Compare the observed waiting times with the plotted probabilities of belonging to either cluster; the probabilities show how group membership changes across the data range. section 8.8

The same approach can group customers by recency, frequency, and monetary behavior for analysis and targeting. Other cited uses include identifying bimodal gene expression and studying household consumption classes. section 8.11

How Grokking Bayes covers it

How deep it goes
Works through probabilistic membership and stick-breaking weights, then examines predictive fit, label switching, and practical truncation.
Examples
Uses short and long Old Faithful waiting times, a ten-component fit, and customer segmentation by recency, frequency, and monetary behavior.
What it assumes
Builds stick-breaking from a physical analogy while using mixture components and posterior samples to calculate membership.
What you can do after
Apply it via PyMC to infer cluster weights and membership probabilities, then inspect predictive fit and label switching.
How it connects
Connects Gaussian mixture models with posterior inference, posterior predictive checks, label switching, and the stick-breaking process.

Also explained in

Compare how 24 books explain clustering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Bayes. The section links point to the parts of the book it draws on.