CAB212 · Unit 5: Unsupervised learning
K-means clustering
8 practice questions
Key points
- Assign to nearest centroid, then recompute means
- Converges to a local minimum
- k-means++ and restarts help
- Elbow and silhouette choose k
K-means partitions data into k clusters by minimising the within-cluster sum of squares (inertia).
Algorithm: (1) choose k initial centroids; (2) assign each point to the nearest centroid; (3) update each centroid to the mean of its points; repeat until assignments stop changing.
Worked example: points 1,2,3,10,11,12 with initial centroids 1 and 10. Clusters {1,2,3} and {10,11,12}, new centroids 2 and 11, and nothing changes after that.
Properties: converges to a local minimum, so results depend on initialization (use k-means++ and several restarts). Assumes roughly spherical clusters of similar size; sensitive to outliers and scale. Complexity about O(n k d) per iteration.
Choosing k: elbow method (plot inertia against k and look for the bend) or the silhouette score (range -1 to 1; closer to 1 is better).
Exam pitfall: the number of clusters k must be given in advance; k-means does not discover it.
Try two questions
Points 1,2,3,10,11,12 with initial centroids 1 and 10: the final centroids are:
- 1 and 10
- 6.5 and 6.5
- 2 and 11
- 3 and 12
Show the answer
C. Clusters {1,2,3} and {10,11,12} have means 2 and 11.
In k-means, each centroid is updated to be the:
- Median of all points in the dataset
- Nearest data point to the old centroid
- Mean of the points assigned to it
- Randomly chosen point from its cluster
Show the answer
C. Hence the name k-means.