Skip to main content

Loading the visual lab…

#hierarchical-clusteringUnsupervised learning

Merge the points two at a time until only one is left: the dendrogram, the linkage criteria, and the cut height that decides the number of clusters.

What you'll play with

  1. Welcome to #hierarchical-clustering. On the left, 30 grey points on a plane: you can guess three blobs, but the machine does not know that yet — each point is its own cluster. On the right, an empty dendrogram: 30 leaves in a row, a height axis and, all the way up, a yellow cut plane. The idea fits in one sentence: merge the two closest clusters, again and again, until only one is left. Each merge draws a "U" whose height is the distance at which it happened.
  2. Trigger the first merge: /merge. The algorithm scans the distance matrix for the closest pair and welds them.
  3. Another one: /merge. Compare the height of the new U with the first one.
  4. Let it run to the end: /run. The 29 merges chain together, from pairs to groups, up to a single root.
  5. The yellow plane is above everything: a single cluster. Push it down: /cut 1.5, then count the branches it crosses.
  6. At 1.5 it works, but that is a bit lucky. Go the other way around: directly ask for three groups with /clusters 3. The plane places itself in the middle of the biggest gap between two merges.
  7. New terrain: /dataset chain. A line of points at regular intervals, and a small compact group next to it. Look at how average linkage cuts this at the current cut height.
  8. Switch to single linkage: /linkage single. The distance between two groups becomes the distance between their two closest points.
  9. Your turn: /linkage ward then /clusters 2 on the line; /dataset rings then /linkage single and /clusters 2 (the two rings recovered) versus /linkage complete (failure); /n 60 to densify; /seed 12 for other points; /undo to reverse a merge; /reset to start over. Next: #dbscan, which finds groups by density without fixing their number, and #k-means, the rival that must know k in advance.

Channel commands

  • /mergePerform the next merge: the two closest clusters weld together.
  • /runRun every remaining merge: the full tree, up to the root.
  • /undoUndo the last visible merge.
  • /linkage <single|complete|average|ward>Change the linkage criterion and recompute the whole tree (same number of visible merges).
  • /cut <height=0..4>Place the cut plane at this height: as many clusters as crossed branches.
  • /clusters <m=1..10>Pick the number of clusters: the plane lands in the middle of the right height gap.
  • /dataset <blobs|chain|rings>Change the dataset (same n, same seed) and recompute the tree.
  • /n <10..60>Change the number of points and recompute the tree.
  • /seed <1..99>Redraw the points with another seed (same dataset, same n).
  • /resetBack to the start: blobs, 30 points, average linkage, no merge, cut plane all the way up.

Glossary

Agglomerative hierarchical clustering
Unsupervised grouping method that starts with n one-point clusters and, at each step, merges the two closest clusters, until only one is left. You get an entire hierarchy of partitions instead of a single one.
Dendrogram
Tree that summarises every merge: the leaves are the points, each "U" links two clusters at the height of their merge. Cutting it at a given height yields a partition into clusters.
Linkage criterion
Rule that defines the distance between two clusters from the point-to-point distances: single, complete, average, Ward… It decides the merge order and therefore the shape of the tree.
Single linkage
Distance between two clusters = distance between their two closest points. Follows elongated shapes and rings, but suffers from the chaining effect.
Complete linkage
Distance between two clusters = distance between their two farthest points, that is, the diameter of the merged cluster. Produces compact, round clusters, but chops elongated shapes.
Average linkage
Distance between two clusters = mean of every point-to-point distance between the two groups. A compromise between single and complete, robust to outliers.
Ward's method
Criterion that merges the two clusters whose union increases the intra-cluster inertia the least (the sum of squared distances to the centroids). Favours compact clusters of comparable sizes; it is scikit-learn's default criterion.
Cut height
Distance threshold at which you slice the dendrogram: the crossed branches become the clusters. Cutting through the middle of the largest height jump gives the most robust partition; you can also target a specific number of clusters directly.
Chaining effect
The pitfall of single linkage: a line of close points acts as a bridge and, step by step, merges groups that have nothing to do with each other. The dendrogram flattens at the bottom and no clean gap is left to cut through.
Distance matrix
The n × n table of distances between every pair of points, the starting point of the algorithm. After each merge, the row of the new cluster follows from the old ones via the Lance-Williams formula.

Other channels in Unsupervised learning

  • #k-meansGrouping without labels: centroids that move, inertia that drops, the choice of k — and the shapes where k-means fails.
  • #pcaPrincipal component analysis: find the axes where data varies most, project, compress — and measure what is lost.
  • #hierarchical-clusteringMerge the points two at a time until only one is left: the dendrogram, the linkage criteria, and the cut height that decides the number of clusters.
  • #dbscanGroup by density: epsilon, MinPts, core, border and noise points — the algorithm that finds arbitrary shapes and ignores intruders.
  • #anomaly-detectionSpot what fits nothing: z-score / Mahalanobis, Isolation Forest, LOF — three ways to say 'this point is odd'.
  • #t-sne-umapMap the high dimensions: t-SNE and UMAP unfold 10-dimensional data into a readable 2D map — perplexity, neighbors, and reading pitfalls.