k-means Clustering
Context: FIT1043_MOC Β· the flagship unsupervised (no-label) method Β· groups points by similarity Β· partitions data into clusters
Quick Revision
- π― Objective: group unlabelled points into clusters by similarity β iterate assign β move-centroid until stable.
- π¦ Core Components: = number of clusters | centroid = mean of a clusterβs points | two repeating steps.
- β‘ Key Constraint: the initial random centroids matter β poor initialisation gives volatile, different results; must be chosen up front.
π How It Works
1. Basics
- Clustering β grouping a set of data points into subgroups (clusters) based on similarity (unsupervised; e.g. T-shirt sizes S/M/L β ).
- β the number of clusters (chosen before running).
- Centroid β the mean (average) location of all points in a cluster.
2. The Two Iterative Steps
- 1. Cluster assignment β assign each point to its nearest centroid.
- 2. Move centroid β move each centroid to the mean of the points now assigned to it.
- Stop β repeat until no change (assignments/centroids stabilise).
3. Initialisation & Choosing
- Random init β pick random data points as starting centroids; highly volatile β poorly positioned seeds give poor/different clusterings.
- Choosing β a priori domain knowledge ( two kinds of people; bacteria types; T-shirt sizes); search (try several , evaluate quality); or run hierarchical clustering on a subset.
π Exam Execution Trace
Manual Execution Trace
k-means with :
| Step / State | Action | Result |
|---|---|---|
| 0 (Init) | pick 2 random centroids | seeds placed |
| 1 | cluster assignment | each point β nearest centroid |
| 2 | move centroid | centroids β mean of their points |
| 3 | reassign + move | some points switch clusters |
| 4 | repeat | no change β converged |
Final Extracted Output: stable clusters, each summarised by its centroid (the mean of its members).
β οΈ Common Mistakes
- π‘ Different seeds β different clusters β random initialisation is volatile; run multiple times or seed carefully.
- π‘ You must pick β k-means canβt discover the number of clusters; use domain knowledge or search over .
π§ Active Recall
State the two iterative steps of k-means and its stopping condition.
- Hint: Assign then re-centre.
Answer
- Short answer: (1) Cluster assignment β assign each point to the nearest centroid; (2) Move centroid β set each centroid to the mean of its assigned points; repeat until no change.
- Why: Centroid = mean β each pass lowers within-cluster distance until assignments stabilise.
Why does the initial choice of centroids matter, and how do you choose ?
- Hint: Volatile init + preset k.
Answer
- Short answer: Random seeds are volatile and can converge to poor clusterings; choose from domain knowledge, by searching over values, or via hierarchical clustering on a subset.
- Why: Seed sensitivity β k-means finds a local solution, so starting points shape the outcome.