Cluster Analysis (Basic)
What Is Clustering?
- Clustering (unsupervised): group objects so that objects in the same cluster are more similar to each other than to those in other clusters.
- No class labels are given; it is exploratory structure discovery.
- Criterion: maximize intra-cluster similarity, minimize inter-cluster similarity.
Applications
- Understanding (group similar documents, genes, customers), preprocessing for classification, outlier detection, compression.
Requirements of Clustering Algorithms
- Scalability (to large
and ). - Ability to deal with different types (numeric, binary, categorical, graphs).
- Handle noisy/incomplete data and arbitrary shapes.
- Determine the "right" number of clusters
. - Usable, interpretable, incremental.
Categories of Clustering Methods
| Type | Idea | Examples |
|---|---|---|
| Partitioning | iterate to refine | k-means, k-medoids |
| Hierarchical | build tree of nested clusters | AGNES, DIANA, BIRCH |
| Density-based | grow dense regions | DBSCAN, OPTICS |
| Grid-based | quantize space into grid | STING, CLIQUE |
| Model-based | fit statistical models | EM, COBWEB |
Partitional: k-Means
Algorithm (Lloyd's)
1. Choose k initial centroids (randomly / k-means++).
2. repeat:
a. Assignment: assign each point to nearest centroid (Euclidean).
b. Update: recompute each centroid = mean of its cluster.
3. until centroids converge (no/≤ change) or max iterations.Objective
Minimize within-cluster sum of squares (SSE / distortion):
Properties
- Converges to a local optimum (depends on initialization).
- k-means++ picks initial centroids spread out (probabilistically farthest) → better & faster convergence.
- Time:
(I iterations); scales well.
| Pros | Cons |
|---|---|
| simple, fast, scalable | must choose |
| works on numeric data | only spherical/convex clusters |
| sensitive to outliers & initialization | |
| assumes similar variance per cluster |
- Empty clusters, outliers pulled into means ⇒ variants (k-means with medoid init, trimming).
Partitional: k-Medoids (PAM)
- Uses actual data points as centers (medoids) instead of means — robust to outliers and noise.
- PAM (Partitioning Around Medoids) algorithm:
1. Select k initial medoids randomly. 2. assign each non-medoid to nearest medoid. 3. for each medoid m and each non-medoid o: swap(m,o); compute total cost change of reassignments; keep swap if it reduces cost; 4. repeat until no improving swap. - Cost = sum of dissimilarities to medoid (works with arbitrary distance, including non-Euclidean).
- CLARA: sample-based PAM for large data. CLARANS: randomized search.
| k-means | k-medoids |
|---|---|
| center = mean | center = medoid (real point) |
| sensitive to outliers | robust to outliers |
| only Euclidean | any dissimilarity |
| faster | slower (O(n²k)) |
Hierarchical Clustering
Builds a tree (dendrogram) of clusters — no need to pre-specify
Distance Between Clusters (Linkage)
| Linkage | Definition | Shape tendency |
|---|---|---|
| Single (MIN) | finds elongated/chaining clusters | |
| Complete (MAX) | compact, spherical; sensitive to outliers | |
| Average (UPGMA) | average pairwise distance | balanced compromise |
| Centroid | distance between cluster centroids | may be non-monotone (inversions) |
| Ward's | increase in SSE if merged | similar to k-means objective |
Agglomerative (AGNES) — bottom-up
start: each point = one cluster (n clusters);
repeat:
find the two closest clusters by chosen linkage;
merge them;
until one cluster remains (or k clusters);- Produces dendrogram; cut at height ⇒ number of clusters.
Divisive (DIANA) — top-down
start: all points in one cluster;
repeat:
split the cluster that increases the separation most
(typically along the longest diameter / using a criteria);
until each point alone (or k clusters);- Computationally heavier than agglomerative (must decide split).
Strengths / Weaknesses
- ✅ no
needed, gives full hierarchy, deterministic (given linkage). - ❌
or time, cannot undo merges (no correction), sensitive to noise & linkage choice (single → chaining).
| Method | Time | Shape | Outlier robust? | |
|---|---|---|---|---|
| k-means | spherical | yes | no | |
| k-medoids | any (distance) | yes | yes | |
| AGNES | depends on linkage | no | no | |
| DIANA | depends | no | no |
Choosing k
- Elbow method: plot SSE vs
; pick the "elbow" (diminishing returns). - Silhouette (see Ch.10), gap statistic, domain knowledge.
k-Means — Worked 2-D Example
Points:
- Iter 1 assignment (nearest):
, . - Iter 1 update:
, . - Iter 2 assignment: unchanged (still two tight groups). Converged.
- SSE =
. Clean separation.
If init were unlucky (both centroids in one cluster), assignment splits differently and SSE higher — illustrating local-optimum dependence (k-means++ fixes most cases).
BIRCH (Brief — Hierarchical, Scalable)
- Builds a CF-tree (Clustering Feature:
(n, LS, SS)per subcluster: count, linear sum, squared sum) incrementally — only keeps summaries, not all points. - Two phases: build CF-tree, then (optionally) refine with k-means on the leaf CFs. Handles very large / streaming data.
Linkage Effect — Worked
Three points A,B close (dist 1), C far from both (dist 10).
- Single linkage merges A,B first (min dist 1); C joins later at dist 10 ⇒ elongated chain.
- Complete linkage would delay merging any pair involving C (max dist 10) ⇒ more balanced/compact clusters, but may split natural chains.
- Average / Ward sit between; Ward minimizes SSE increase and behaves like k-means.
How Many Clusters? (Recap)
Elbow (SSE vs k), silhouette (Ch.10), gap statistic, or domain requirement. Hierarchical methods sidestep
Cluster Tendency (Is Clustering Even Valid?)
Before clustering, check the data actually has clusters:
- Hopkins statistic: samples random points vs random perturbations; values near 0.5 ⇒ no clustering structure (uniform), near 1 ⇒ clustered. Avoid forcing clusters on uniform noise.
k-Means Limitations (Recap)
- Assumes spherical, equal-variance clusters of similar size; fails on crescents, rings, varying density.
- Sensitive to initialization and outliers (mean pulled).
- Must choose
; scales with and dimensions. Mitigations: k-means++, outlier removal, then optionally DBSCAN/spectral for non-convex shapes (Ch.10).
AGNES vs DIANA Trade-offs
- AGNES (bottom-up) is straightforward and produces a full dendrogram; cannot undo merges (a bad early merge lingers).
- DIANA (top-down) can be more efficient for few final clusters but choosing the best split is harder. Both are
– ; BIRCH/CLIQUE make them scale.
k-Medoids (PAM) — Worked Sketch
Points {1,2,3,8,9,30},
Cutting the Dendrogram
- AGNES yields a dendrogram; cutting at height
produces clusters whose merges all occurred below . Different ⇒ different — explore several and validate (silhouette, Ch.10). - Cophenetic correlation: compares dendrogram distances to original distances to judge linkage quality.
Limitations Recap
k-means/k-medoids need
Summary
Clustering partitions unlabeled data by similarity. k-means iteratively assigns points to the nearest mean centroid, minimizing SSE — fast but assumes spherical clusters and is outlier-sensitive; k-means++ improves initialization. k-medoids (PAM) uses real points as centers, robust to outliers and usable with arbitrary distances, at higher cost. Hierarchical methods (AGNES bottom-up, DIANA top-down) build a dendrogram via linkage rules (single/complete/average/ward) without fixing