1. University MCA (AI/ML) Semester 2
  2. CAB212
  3. Unit 5

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

Question 1 · Tier 2, Understand

Points 1,2,3,10,11,12 with initial centroids 1 and 10: the final centroids are:

  1. 1 and 10
  2. 6.5 and 6.5
  3. 2 and 11
  4. 3 and 12
Show the answer

C. Clusters {1,2,3} and {10,11,12} have means 2 and 11.

Question 2 · Tier 1, Recall

In k-means, each centroid is updated to be the:

  1. Median of all points in the dataset
  2. Nearest data point to the old centroid
  3. Mean of the points assigned to it
  4. Randomly chosen point from its cluster
Show the answer

C. Hence the name k-means.