Machine learning models · Phase 3 · Lesson 21

Hierarchical clustering

Read a dendrogram and choose a hierarchy of clusters rather than one fixed partition.

This is one focused step in the 60-lesson course. Use the retrieval check before moving on.

Lesson goal

Read a dendrogram and choose a hierarchy of clusters rather than one fixed partition.

The core idea

Start with each item alone, or one group, and repeatedly merge or split according to a linkage rule. The history is the useful output.

Mental model

Picture it this way. Start with each item alone, or one group, and repeatedly merge or split according to a linkage rule. The history is the useful output. The important question is what assumption this picture makes, and whether that assumption fits the data.

Mathematical core

Agglomerative clustering uses a distance matrix and a linkage criterion such as single, complete, average or Ward linkage. Cutting the dendrogram gives a chosen number of groups.

Worked example

Cluster related products by their feature profiles. A dendrogram shows which products join early and which remain distinct until a high distance.

When to use it

It earns a place when

  • Use it when hierarchy matters, the dataset is modest and you want to inspect several possible group counts.
  • You can evaluate it against a credible baseline.
  • Its output fits the decision and data constraints.

Do not make it the default when

  • Do not apply it blindly to millions of rows or assume a dendrogram proves a natural taxonomy.
  • A simpler model has not been tested.
  • The data or target definition is still unclear.

Failure modes

Watch for this. The result depends heavily on the distance and linkage. Early merges cannot be undone in standard agglomerative methods.

When a result looks surprisingly good, inspect the split, target timing, error slices and data-generating process before celebrating.

Practice

Use this as a small experiment rather than a recipe to copy blindly. Change one thing, record the result and explain the change.

Do this. Try Ward and complete linkage on the same scaled data. Compare the dendrogram cut with a domain grouping you already trust.

Retrieval check

Answer from memory first. The buttons reveal feedback, but the durable step is explaining why.

1. What does a dendrogram show?

2. What is linkage?

3. Why can early agglomerative merges be risky?

Transfer prompt. Describe one real problem where this model or idea would be a sensible candidate. Name the target, the main risk and the metric you would inspect.

Primary source

scikit-learn User Guide. Use the source for the deeper treatment after you can explain the lesson's core idea without looking.