Module 8: Unsupervised Learning

This module explores learning from unlabeled data. Clustering algorithms group similar examples together, while dimensionality reduction finds compact representations. These techniques enable data exploration, preprocessing, and discovery of hidden structure.

Learning Objectives

  • Distinguish between supervised and unsupervised learning.
  • Apply k-means clustering and understand its limitations.
  • Explain hierarchical clustering and interpret dendrograms.
  • Perform PCA for dimensionality reduction and visualization.
  • Evaluate clustering quality using silhouette scores and elbow method.
0 of 8 stages complete
1 · Watch

The module in two minutes

An animated overview of the module’s through-line. Watch it before the lecture — it is the map, not the territory.

Lecture shorts

Short lectures and code walkthroughs from the instructor that reinforce this module. Some open partway into a longer video — that chapter is the part matched to this module.

Principal Component Analysis — four short lectures (5:26)
From clustering to embeddings, parts 1–4 (to 4:37)
Code walkthrough: singular value decomposition 01
Code walkthrough: singular value decomposition 02
Code walkthrough: singular value decomposition 03

Visual shorts

Short silent animations, one idea each. Press play, or open one full screen. All visual shorts

Choosing k · full screen
DBSCAN · full screen
Agglomerative clustering · full screen
Gaussian mixture, fitted by EM · full screen
Scale before k-means · full screen
The first principal component · full screen
What a matrix does to a circle · full screen
A picture from its first k components · full screen
A matrix as a sum of rank-one layers · full screen
2 · Listen

Orientation audio

Learning without labels: what clustering can and cannot tell you.

3 · Read & play

The through-line

Every module so far had labels. This one takes them away and asks what structure the inputs carry on their own. Two answers: group the examples (clustering), or compress the dimensions (dimensionality reduction).

K-means is clustering at its most direct: place k centroids, assign each point to its nearest centroid, move each centroid to the mean of its points, repeat until nothing moves. You will implement the loop from scratch and watch it converge in a handful of iterations. Its catch is honest and unavoidable — you chose k. The elbow method (where does adding a cluster stop paying?) and the silhouette score (how much closer is each point to its own cluster than the next?) are evidence for that choice, not proofs.

K-means draws hard borders; Gaussian mixture models admit what the borders hide. Model the data as k overlapping normal distributions — each with its own mean, spread, and weight — and every point gets a probability of belonging to each component. Fitting is expectation-maximization, which is k-means with the certainty removed: the E-step softly assigns points to components, the M-step re-estimates each component from its weighted points, and the loop repeats to convergence. The normal distribution and maximum likelihood earn their place here — a mixture is the course’s first genuinely generative model: it can invent plausible new points, not just group the old ones.

PCA compresses instead of grouping: find the orthogonal directions along which the data varies most and keep the top few. Built from scratch, it is an eigendecomposition of the covariance matrix; used well, it turns hundreds of correlated columns into a handful of axes that preserve most of the variance — for visualization, denoising, or as features for the supervised models you already know. SVD is the same machinery in its general form, and t-SNE gives up global axes entirely to buy neighborhood-faithful 2-D pictures — good for looking, dangerous for measuring.

Hierarchical clustering removes the need to pick k up front: merge the closest pair of clusters repeatedly and read the dendrogram at whatever depth serves the question. DBSCAN removes it differently — grow clusters wherever points are dense and call the rest noise, so the number of clusters falls out instead of being chosen.

The caveat that governs all of it: with no labels there is no ground truth, so "the algorithm found four segments" means four was a defensible reading of the evidence — not a fact about the world. Unsupervised results are hypotheses.

Figure · K-means, by hand

Thirty-six unlabeled points. Place k centroids, then run the two-beat loop yourself: assign each point to its nearest centroid, move each centroid to the mean of its points. Repeat until nothing moves.

Convergence takes a handful of iterations, exactly as in the notebook — and the answer depends on where the centroids started, which is why real implementations run several inits and keep the best inertia. Note what the algorithm never tells you: whether k was right. You chose it; the elbow and silhouette are evidence for that choice, not proofs.

Figure · Hierarchical clustering, cut deeper

Three hundred points on a spiral. Each one is set by a single hidden number t, its position along the curve, but the curve wraps around itself, so no straight axis (PCA) can follow it. The page builds one Ward tree. Cut it at a depth, fit a short straight line to each cluster, and chain the cluster centres together. Go deeper until the chain recovers t.

Left: the clusters at this depth, each with its own line (a local PCA), and the chain that links their centres. A red link skips along the curve to the next arm. Right: the coordinate read off the chain against the true t. At shallow depths the pieces are longer than the gap between arms, so the chain takes shortcuts and the right panel scatters. Once every piece is shorter than that gap, the chain follows the spiral and the right panel becomes one rising curve. Past that, deeper cuts lower the error only by fitting lines to a few noisy points: compare the error with the noise floor.

Key concepts

  • Clustering: Group similar data points
  • K-Means: Partition into k clusters via centroids
  • PCA: Find directions of maximum variance
  • Eigenvalues: Amount of variance explained
  • Silhouette Score: Measure cluster quality
  • Gaussian Mixture Model: Soft clustering with overlapping normals
  • Expectation-Maximization: Alternate soft assignment and re-estimation
  • t-SNE: Neighborhood-faithful 2-D maps, for looking not measuring
4 · Code

The lecture notebook

Eight parts, from scratch before any framework — k-means through EM, then the sklearn tour. Run every cell; change things and rerun — the notebook is the lecture.

In Colab: File → Save a copy in Drive keeps your work.

5 · Practice

Exercise

Attempt the exercise before opening the solution — the attempt is where the learning happens.

6 · Check

Knowledge check

The quiz is self-graded and open-book. If a question surprises you, the corresponding lecture part is the fastest fix.

7 · Go deeper

Reference and discussion

8 · Done

Finish the module

Complete the stages above, then claim the finish here.