Hierarchical Methods

A hierarchical method builds a tree of clusters (dendrogram) and does not need k in advance. A distance matrix between all pairs of objects is the input.

  • Agglomerative (AGNES, bottom-up): each object starts as a cluster; the two closest clusters are merged at every step until one cluster remains.
  • Divisive (DIANA, top-down): all objects start in one cluster, which is split repeatedly.

Distance Between Clusters (Linkage)

  • Single linkage (nearest neighbour): the smallest distance between members of the two clusters; it can form long chains.
  • Complete linkage (farthest neighbour): the largest distance between members; it gives compact clusters.
  • Average linkage: the mean of all pairwise distances.
  • Centroid linkage: the distance between the cluster centres.

Cutting the dendrogram at a chosen distance gives a set of clusters.

Improved Methods

Basic methods cannot undo a merge and cost at least O(n²). Improved methods are:

  • BIRCH: builds a clustering feature (CF) tree in one scan; each CF is (N, linear sum, square sum), so clusters are summarised in small memory.
  • CURE: represents a cluster by several well-scattered points shrunk toward the centre, so it finds non-spherical clusters and resists outliers.
  • Chameleon: merges clusters using dynamic modelling of interconnectivity and closeness, so it adapts to the data.

Definition: Dendrogram. A tree diagram that shows the order in which clusters are merged (or split) and the distance at which each merge happens.

Table 4.2: Linkage methods

Linkage Distance used Behaviour
Single Minimum Long chains, finds elongated shapes
Complete Maximum Compact clusters
Average Mean of all pairs Compromise
Centroid Between centres Simple to compute

Example 4.2: Single and complete linkage

Problem: Cluster the points A(1,1), B(2,1), C(4,3), D(5,4) and E(8,8) by agglomerative clustering. Distances: AB 1, CD 1.414, BC 2.828, AC 3.606, BD 4.243, AD 5, DE 5, CE 6.403. Find the merge distances for single and complete linkage.

Solution:

  1. Both methods first merge AB at 1 and CD at 1.414.
  2. Single: the distance between {A,B} and {C,D} is the minimum, BC = 2.828, so they merge at 2.828; E joins {A,B,C,D} at the minimum DE = 5.
  3. Complete: the distance between {A,B} and {C,D} is the maximum, AD = 5, so they merge at 5; E joins at the maximum AE = 9.899.

Result: Single linkage merges at 1, 1.414, 2.828 and 5; complete linkage merges at 1, 1.414, 5 and 9.899.

from math import dist
P = {"A": (1, 1), "B": (2, 1), "C": (4, 3), "D": (5, 4), "E": (8, 8)}
def run(link):
    cl = [[k] for k in P]
    out = []
    def d(x, y):
        v = [dist(P[i], P[j]) for i in x for j in y]
        return min(v) if link == "single" else max(v)
    while len(cl) > 1:
        a, b = min(((i, j) for i in range(len(cl))
                    for j in range(i + 1, len(cl))),
                   key=lambda ij: d(cl[ij[0]], cl[ij[1]]))
        out.append(round(d(cl[a], cl[b]), 3))
        cl[a] += cl.pop(b)
    return out
print("Single  :", run("single"))
print("Complete:", run("complete"))

Output

Single  : [1.0, 1.414, 2.828, 5.0]
Complete: [1.0, 1.414, 5.0, 9.899]

Common mistakes

  • Forgetting that single linkage can chain unrelated clusters through noise points.
  • Expecting to undo a wrong merge later.
  • Using hierarchical methods on millions of objects without BIRCH-type summaries.
  • Cutting the dendrogram at an arbitrary height without checking the clusters.

Key takeaways

  • Agglomerative is bottom-up; divisive is top-down.
  • Linkage: single (min), complete (max), average, centroid.
  • BIRCH uses a CF tree; CURE uses scattered representative points; Chameleon uses dynamic modelling.
  • Merges cannot be undone.

Practice questions

  1. What is single linkage?
  2. What does BIRCH build?
  3. What is a dendrogram used for?

Answers to the practice questions

  1. Cluster distance equals the smallest distance between members.
  2. A clustering feature (CF) tree in a single scan.
  3. To show the merging order and to choose the number of clusters by cutting it.

Sources

  • Official BCA syllabus Data Warehousing and Mining, course code 25BCA406DS03, Unit IV