← All notes · ML revision (DA5400)

L13: Introduction to Clustering — Partitioning Data & Motivation for K-Means

Source: https://www.youtube.com/watch?v=A3UNtCuMm7Y (≈17 min)

Timestamped outline

Time Topic
00:13 Recap: unsupervised representation learning (PCA, kernel PCA)
00:48 New paradigm: clustering
01:03 Motivation: why PCA alone misses structure
03:22 Problem statement: partition n points into K clusters
03:56 Example: many ways to put 5 points into 3 boxes (3^5)
06:12 Notation: cluster indicators z₁…zₙ
08:09 How good is a partition? Need an objective
10:04 Objective: sum of squared distances to cluster means
10:39 Defining the cluster mean μₖ with indicator functions
12:38 Worked example with K = 2
14:03 Goal: minimise the objective over all partitions
14:56 Why brute force fails: Kⁿ partitions, NP-hard
16:37 Way forward: a heuristic algorithm (K-means, next lecture)

1. Motivation

2. Problem statement

3. Notation: cluster indicators

4. The objective (goodness of a partition)

Intuition: a good cluster is homogeneous, meaning its points look alike. One way to measure this is how spread out the points are around the cluster's centre.

Objective:

$$ f(z_1,\dots,z_n) = \sum_{i=1}^{n} \lVert x_i - \mu_{z_i} \rVert_2^2 $$

Here μ_{zᵢ} is the mean of the cluster that xᵢ is assigned to.

Cluster mean, written with indicators:

$$ \mu_k = \frac{\sum_{i=1}^{n} \mathbb{1}(z_i = k)\, x_i}{\sum_{i=1}^{n} \mathbb{1}(z_i = k)} $$

So the objective is the total squared distance from each point to the mean of its own cluster. It is also called the within-cluster sum of squares, or the K-means objective.

5. Worked example (K = 2)

Points x₁…x₅ with z = (1, 2, 1, 1, 2):

$$ f = \lVert x_1-\mu_1\rVert^2 + \lVert x_2-\mu_2\rVert^2 + \lVert x_3-\mu_1\rVert^2 + \lVert x_4-\mu_1\rVert^2 + \lVert x_5-\mu_2\rVert^2 $$

6. The optimisation goal

$$ \min_{z_1,\dots,z_n \in \{1,\dots,K\}} \; \sum_{i=1}^{n} \lVert x_i - \mu_{z_i} \rVert^2 $$

Brute force: list every partition, compute f for each, and keep the smallest. There are only finitely many partitions, so this works in principle, but:

Way forward: we can't expect to find the exact optimum efficiently, so we use a popular heuristic algorithm, K-means (Lloyd's algorithm), which the next lecture covers.


Key takeaways

  1. Clustering is unsupervised learning that finds group structure, which PCA's linear subspace does not show.
  2. A partition is written as indicators zᵢ ∈ {1..K}.
  3. Partition quality is the sum of squared distances from points to their cluster means. Lower is better, because it means the clusters are more homogeneous.
  4. Exact minimisation is NP-hard (Kⁿ partitions), which is why we need a heuristic like K-means.

Quick self-check questions

  1. How many ways can 6 points be assigned to 4 clusters if empty clusters are allowed? (4⁶ = 4096)
  2. Why is Kⁿ only an upper bound on the number of useful partitions?
  3. If every point in a cluster is identical, what does that cluster add to the objective?
  4. Write μₖ using indicator notation, from memory.
  5. Why can't we just enumerate every partition when n = 1000?