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 / StateActionResult
0 (Init)pick 2 random centroidsseeds placed
1cluster assignmenteach point β†’ nearest centroid
2move centroidcentroids β†’ mean of their points
3reassign + movesome points switch clusters
4repeatno 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