Chapter 6
Clustering
What cluster analysis is and isn't, good clustering, similarity and dissimilarity for nominal, binary, numeric, ordinal and text data, k-means, and hierarchical clustering with single and complete link.
From: Data Mining - Clustering (intro), Topic 6b - Similarity, Topic 6c - k-means Algorithm, Clustering: Hierarchical 1, 2 (MIN) and 3 (MAX)
Cluster analysis (intro)
- Find groups where objects in a group are similar to each other and different from objects in other groups: intra-cluster distances minimised, inter-cluster distances maximised.
- Unsupervised learning: no predefined classes, no class label.
- Uses: a stand-alone tool for insight into data distribution, or a preprocessing step for regression, PCA, classification and association; reducing large data sets; compressing images (vector quantization).
- Not cluster analysis: supervised classification (has labels), simple segmentation (e.g. students by surname), results of a query (external specification), graph partitioning.
- Applications: biology (taxonomy), information retrieval (document clustering), land use, marketing (customer groups), city planning, earthquake studies, climate, economics.
| Type | Meaning |
|---|---|
| Partitional | Divide objects into non-overlapping subsets; each object is in exactly one cluster |
| Hierarchical | A set of nested clusters organised as a hierarchical tree |
- Good clustering: high intra-class similarity (cohesive) and low inter-class similarity (distinctive). Quality depends on the similarity measure, the implementation, and its ability to find hidden patterns.
- Requirements: scalability, different attribute types, clusters of arbitrary shape, minimal domain knowledge for parameters (e.g. number of clusters), noisy data, incremental clustering and insensitivity to input order, high dimensionality, constraint-based clustering, interpretability and usability.
- Clustering is descriptive analytics (what happened), as opposed to predictive analytics (future probabilities and trends).
Similarity and dissimilarity (6b)
- Similarity: how alike two objects are; higher when more alike; often in [0, 1].
- Dissimilarity (e.g. distance): how different; lower when more alike; minimum often 0, upper limit varies.
- Proximity refers to either. Deciding what is “similar enough” is often subjective.
- Data matrix: n objects × p attributes; two modes (rows and columns).
- Dissimilarity matrix: n × n, stores d(i, j) for all pairs; triangular, single mode.
| Data type | Measure |
|---|---|
| Nominal | Simple matching: d(i, j) = (p − m)/p, where m = matches and p = number of attributes. Or one binary attribute per state |
| Symmetric binary | d(i, j) = (r + s)/(q + r + s + t), e.g. gender |
| Asymmetric binary | d(i, j) = (r + s)/(q + r + s): t (both 0) is unimportant, e.g. medical tests |
| Jaccard coefficient | sim(i, j) = q/(q + r + s) = 1 − d(i, j) (asymmetric binary) |
| Numeric | Euclidean (most popular), Manhattan (city block), Minkowski with order h |
| Ordinal | Replace values by rank r, normalise z = (r − 1)/(M − 1) into [0, 1], then treat as numeric |
| Text / vectors | Cosine similarity: cos(d1, d2) = (d1 · d2)/(‖d1‖ ‖d2‖) |
- Binary contingency table: q = both 1, r = i is 1 and j is 0, s = i is 0 and j is 1, t = both 0; p = q + r + s + t.
- Distance properties: positive definiteness (d(i, j) > 0 if i ≠ j, d(i, i) = 0), symmetry (d(i, j) = d(j, i)), triangle inequality (d(i, j) ≤ d(i, k) + d(k, j)).
- Cosine is used for documents with thousands of term-frequency attributes, gene features, information retrieval and biological taxonomy. Slide example: 25 / (6.481 × 4.12) ≈ 0.94.
Major clustering approaches (6c)
| Approach | Idea | Methods |
|---|---|---|
| Partitioning | Build partitions and evaluate them, e.g. minimise sum of squared errors | k-means, k-medoids, CLARANS |
| Hierarchical | Hierarchical decomposition of the data | DIANA, AGNES, BIRCH, CHAMELEON |
| Density-based | Connectivity and density functions | DBSCAN, OPTICS, DenClue |
| Grid-based | Multiple-level granularity structure of cells | STING, WaveCluster, CLIQUE |
k-means (6c)
- Partition a database of n objects into k clusters, minimising the sum of squared distance. Heuristic methods: k-means (MacQueen '67, each cluster represented by its centre/mean) and k-medoids / PAM (Kaufman & Rousseeuw '87, each cluster represented by one of its objects).
The four steps
- Partition the objects into k non-empty subsets (or pick k initial centroids).
- Compute seed points as the centroids (mean points) of the current clusters.
- Assign each object to the cluster with the nearest seed point (e.g. Euclidean distance).
- Go back to step 2; stop when the assignment does not change.
- Slide example: 10 points, k = 2, starting centroids c1 = (3, 4), c2 = (7, 4). After iteration 1 the new centroids are (3, 6.25) and (6.83, 4).
- How many clusters? No truly optimal way; use heuristics, e.g. stop where adding a cluster no longer gives much better modelling (the marginal gain in explained variance drops).
- Increasing k always reduces SSE, but a good clustering with smaller k can beat a poor one with larger k.
- Variants differ in initial means, dissimilarity and how means are computed. k-modes handles categorical data (modes instead of means); k-prototype handles mixed data.
- Limitations: problems with clusters of differing sizes, densities and non-globular shapes; sensitive to outliers. k-medoids uses the most centrally located object (always a real data point) instead of the mean.
- Poor random initial centroids: run several times and keep the lowest SSE, or pick each new initial centroid farthest from those already chosen.
Hierarchical clustering (hierarchical 1–3)
- Produces nested clusters as a tree, visualised as a dendrogram that records the sequence of merges or splits. Cut the dendrogram at a level to get the clusters.
- Uses the distance matrix; does not need k as input but needs a termination condition.
- Agglomerative (AGNES): start with each point as its own cluster and merge the closest pair until one (or k) clusters remain. More popular.
- Divisive (DIANA): start with one all-inclusive cluster and split until each point is alone (or k clusters).
- AGNES (Kaufmann & Rousseeuw, 1990) uses the single-link method and merges nodes with the least dissimilarity.
- Key operation: computing the distance between two clusters and updating the matrix after each merge.
| Inter-cluster distance | Definition |
|---|---|
| MIN / single link | Distance between the two closest points in the different clusters; determined by one pair (one link) |
| MAX / complete link | Distance between the two most distant points; determined by all pairs. Computed with max, but the pair to merge is still the one with the minimum of these distances |
| Group average | Average distance over all pairs |
| Distance between centroids | Distance between cluster centres |
Slide example: 6 points
- First merges: {3, 6} and {2, 5} (the two shortest distances).
- Single link: dist({3,6}, {2,5}) = min(0.15, 0.25, 0.28, 0.39) = 0.15, so they merge next; then 4 joins (0.16), then 1 (0.22).
- Complete link: dist({3,6}, {2,5}) = max(…) = 0.39, so instead 4 joins {3,6} (0.22), then 1 joins {2,5} (0.34), and finally both groups merge (0.39).