Hierarchical Clustering and Density-Based Clustering
Prerequisite Knowledge
This lecture builds on the following concepts from earlier lectures. If any feel unfamiliar, review the linked notes before proceeding.
Previously Covered in This Subject
- Clustering fundamentals: types of clustering and types of clusters, including density-based clusters — covered in Lecture 13 (Clustering and K-Means)
- K-means: the algorithm, its SSE objective, and centroid versus medoid — covered in Lecture 14 (K-Means and Hierarchical Clustering)
- Hierarchical clustering and bisecting k-means overview — covered in Lecture 14 (K-Means and Hierarchical Clustering)
- Time complexity of k-means and finding the value of K — covered in Lecture 14 (K-Means and Hierarchical Clustering)
15.1 Hierarchical Clustering: Two Strategies, No K
Hook: What if you have no idea how many clusters your data should have? K-means refuses to run until you pick a K, and picking K badly silently ruins everything downstream. Hierarchical clustering asks a different question: instead of "how many groups?" it asks "how do the groups nest inside each other?" — and once you have that nesting, any number of groups is one cut away.
15.1.1 Why Build a Tree Instead of Picking K
K-means needs the value of K before it can run, and finding the right K is very hard. The lecture's point is blunt: the number of natural groups is usually not known in advance, and trial-and-error on K is expensive and subjective. Hierarchical clustering sidesteps this problem entirely: you never decide K up front. Instead you build a tree-like structure over the data, and then, based on the question you are trying to answer, you cut that tree at a certain level to get your clusters.
The same tree can serve many questions, because each cut produces a different clustering. Think of a family tree: one diagram records every branching, and whether you ask "who descends from my grandparents?" or "who descends from my great-grandparents?" is just a matter of how high you slice the tree. The tree itself does not change; the cut does. That is the entire payoff of the hierarchical idea: one structure, many clusterings, chosen by where you cut.
15.1.2 Agglomerative and Divisive Strategies
There are two strategies for building the hierarchy, and they are exact mirror images of each other.
In the agglomerative strategy, also called the bottom-up approach, every data point starts out behaving like its own cluster. Then you merge points based on similarity, and keep merging similar clusters until you end up with one big cluster holding everything. Merging is the only operation: nothing ever gets split. Each merge decision is made once, and a cluster, once formed, stays formed.
In the divisive strategy, also called the top-down approach, all the points start inside one big cluster, and you break that cluster into smaller parts based on similarity or dissimilarity, iteratively, until each point is its own cluster. Splitting is the only operation: nothing ever gets merged back.
| Agglomerative (bottom-up) | Divisive (top-down) | |
|---|---|---|
| Starting point | Every point is its own cluster | One cluster holds everything |
| Operation | Merge the two most similar clusters | Split a cluster into smaller parts |
| Stopping point | One cluster remains (the root) | Every point is a singleton |
| Analogy | Sand grains clumping into rocks | Breaking a rock into pebbles into grains |
Both strategies produce nested clusters arranged in a hierarchical tree, which is called a dendrogram — the subject of the next section. The nesting property is what matters: any cluster produced at any level of the tree is a union of clusters from lower levels, so the levels are not independent groupings but a single coherent hierarchy.
15.1.3 Algorithms That Follow the Two Strategies
One well-known algorithm that implements the agglomerative strategy is AGNES (AGglomerative NESting). In AGNES, each point is first treated as a cluster, and merging starts from there: at every step the two closest clusters are combined, and the process is recorded as a tree. AGNES is the reference implementation of the bottom-up idea.
On the divisive side, one algorithm with a primitive divisive hierarchical strategy is DIANA (DIvisive ANAlysis). DIANA begins with all objects in one cluster and repeatedly splits: at each step it finds the object or group that is most dissimilar to the rest and pulls it out into its own cluster, continuing until every object is alone. (The professor's spoken explanation of the name was hard to hear; the standard name in the literature is DIANA.) A second example of a top-down (divisive) algorithm is bisecting k-means, which gets its own treatment below — it takes the "split" idea literally by handing each chosen cluster to k-means with K equals two.
The pair AGNES and DIANA is a classic pairing in the literature precisely because they are symmetric: AGNES shows how merging builds a hierarchy, DIANA shows how splitting tears one down.
15.1.4 Why Hierarchical Clustering Matters in Practice
Real-world: hierarchical clustering is very meaningful because it resembles many taxonomies we follow in real life, for example in biological science. Living things are grouped into nested categories — species inside genera, genera inside families, families inside orders — and that nested structure is exactly the shape a dendrogram produces. Taxonomy is not an arbitrary constraint of the algorithm; it is the natural form of the domain. When your real-world clusters are naturally hierarchical, the tree-based model fits them better than flat K clusters, because a flat model is forced to pretend every group exists at the same level of granularity.
The same nested shape shows up everywhere: file systems are directories inside directories, an organization chart nests teams inside divisions, a phylogenetic tree nests evolutionary branches. Whenever the domain itself is a hierarchy, hierarchical clustering is the honest model.
Exam note: everything covered until the last class is part of the comprehensive syllabus, and this clustering unit belongs to it. The two strategies (agglomerative = merge up, divisive = split down) and the idea that "no K is needed because you cut the tree later" are exactly the kind of conceptual points an exam asks about.
Recap: hierarchical clustering replaces "guess K" with "build a nested tree, cut where your question needs." Bridge: next we look at the tree itself — the dendrogram — and learn how to read the entire merge history out of its junction heights.
15.2 The Dendrogram
Hook: A dendrogram looks like an upside-down family tree, but it is really a storage device: one picture records the entire merge history of a dataset — every pair that joined, and at what distance. That is why you can cut it anywhere and read off a clustering that was never explicitly computed.
15.2.1 What the Tree Shows
A dendrogram is the tree you get from hierarchical clustering. On the X axis you see all the points, laid out as leaves. On the Y axis you have distance. Each merge in the clustering shows up as a junction, and the height of that junction records the distance at which the two clusters were merged. So the dendrogram is not just a pretty picture: it encodes the entire merge history of the data, and it gives a lot of information.
The two axes play different roles. The X axis only decides the order in which the leaves are drawn — it is a naming axis, not a number axis, so moving a leaf sideways changes nothing about the clustering. The Y axis is the meaningful one: it is measured in distance units (the same units as the pairwise distances), and every vertical line's height is a real number — the distance between the two clusters at the moment they merged.
Visual intuition: imagine a thermometer lying horizontally at the bottom of the page, with the points resting on it. Each junction is a lowercase "V" or "U" reaching upward, and the taller the arch, the farther apart its two subtrees were when they joined. The bottom of the tree is the fine detail (small distances, small clusters); the top is the coarse structure (large distances, one big cluster). Reading the figure bottom-up tells the merge story in time order.
15.2.2 Reading an Example Dendrogram
In the example shown, the leaves are points one, three, two, five, six, and four. Reading the tree bottom-up: point one and point three were merged first, and the junction is low, because the distance between them is small. Then point two and point five were merged. Next, the cluster of two and five was merged with point four. Then the cluster of one and three was merged with that bigger cluster, and finally everything joined into one root.
The height of each junction reflects the distance at the merge: a taller junction means the clusters being joined were farther apart. This is the single most useful rule for reading a dendrogram:
Merge height = distance at which the merge happened. Tall junction → far-apart clusters; low junction → close clusters.
Worked reading (heights as merge distances): suppose the junctions of the example sit at heights 0.11, 0.14, 0.22, 0.24, and 0.39 from bottom to top.
- The junction for {1, 3} is the lowest (0.11) → points 1 and 3 are the closest pair in the dataset; they merged first.
- The junction for {2, 5} (0.14) is a little higher → they are the next-closest pair.
- The junction for {2, 5, 4} (0.22) is higher still → point 4 was farther from the {2, 5} cluster than 2 was from 5.
- The root junction (0.39) is the tallest → the two halves of the tree were the most dissimilar pair of groups in the data.
Sense-check: the order of the heights (0.11 < 0.14 < 0.22 < 0.24 < 0.39) is monotone — merges never go backward — which is what makes the picture readable as a timeline.
15.2.3 Cutting the Tree at Any Level
Because every merge is stored in the tree, you can cut the dendrogram at any level to get the desired results. A cut near the bottom gives many small clusters; a cut near the top gives a few big ones. This is the payoff of not fixing K: one tree, any number of clusterings, chosen by where you place the cut.
Mechanically, a cut is a horizontal line at a chosen height. Every junction below the line is "accepted," and the leaves that hang together beneath each accepted junction form one cluster; any junction above the line is ignored. In the worked example that follows, this is exactly how the final clusters were read off — a horizontal cut at a chosen height groups everything below each junction into one cluster. Note the cut's height itself has meaning: it is the largest merge distance you are willing to tolerate inside a cluster, so cutting at 0.2 means "no cluster may contain points that were merged at a distance above 0.2."
Pitfall: a dendrogram only guarantees a sensible reading if junction heights increase monotonically up the tree. Some linkage methods (centroid linkage, as we will see) can produce inversions, where a later merge has a smaller height than an earlier one, and then a horizontal cut can slice through a cluster or produce nonsensical groupings. If your dendrogram shows descending heights, the issue is in the linkage choice, not in your reading.
Recap: the dendrogram is the merge history of the data — points on the X axis, distance on the Y axis, junction height equal to merge distance — and any horizontal cut converts it into a clustering. Bridge: bisecting k-means builds a hierarchy by the opposite route, splitting top-down instead of merging bottom-up.
15.3 Bisecting K-Means (Divisive)
Hook: Divisive clustering needs a way to split a big cluster into two. The simplest splitter in existence is k-means with K equals two — and that is the entire recipe of bisecting k-means: keep handing clusters to 2-means until you have enough. The catch, as the lecture shows, is that what looks reasonable at every local step can still be wrong globally.
15.3.1 The Algorithm
Purpose: bisecting k-means turns top-down splitting into a repeated call to k-means, so it reuses a cheap, well-understood clustering algorithm as its engine. Instead of inventing a clever split rule, it lets k-means find the two natural halves of whatever cluster it is handed.
Inputs and outputs: the input is the full set of points, plus the number of clusters you eventually want (the stopping condition). The output is a binary tree of splits — each internal node is one k-means run, and the leaves are the final clusters.
Steps:
- Put all the points into one big cluster.
- Take the big cluster and pass it to k-means with K equals two, which splits it into two clusters.
- Choose one of the remaining clusters (the lecture's example works on whichever clusters remain) and pass it to k-means with K equals two.
- Repeat on whichever clusters remain until you have enough clusters (or until some stopping criterion is met).
The name says it all: you keep bisecting. Each split is one pass of k-means, and the tree of splits records how every cluster was carved out of the original one.
The method is not locked to k-means. Any clustering algorithm can play the role of the splitter — AGNES, or any other strategy you want. The generic idea is: take a big cluster, hand it to a clustering algorithm, and it breaks it into two parts. The K value of two in the example is a choice, not a requirement; you can pass K equals two or any other value you like, based on your requirement. Using K equals two is simply the smallest useful split and the most common default.
15.3.2 Walkthrough on the Example Data
Trace (from the lecture): the worked example starts with one cluster containing all the points.
- Passing all of them to k-means with K equals two returns one blue cluster and one red cluster.
- The blue cluster, on its own, is passed to k-means with K equals two, and it is broken down into a green cluster and a blue cluster.
- The blue part is passed again, and it splits into light green, blue, and dark green — note how the same color name keeps being reused at different depths, which is why the tree (not the color) is the real record.
- On the red side, the red cluster is passed once more and breaks into red and dark red.
This continues iteratively until you have all the small clusters you see at the end. Each split is one pass of k-means, and the tree of splits records how every cluster was carved out of the original one.
Sense-check: the process always ends with every point in exactly one leaf cluster; the number of leaves equals the number of clusters you stopped at, and each leaf can be traced up to the root through a chain of splits.
15.3.3 Complexity: Log n Runs of K-Means
The complexity of k-means itself, discussed earlier, is:
where is the number of iterations, is the number of clusters, is the number of points, and is the dimension of each point. The symbol is the iteration count — how many times k-means cycles through its two steps before the assignments stop changing. All four factors enter linearly: more iterations, more clusters, more points, or more dimensions each cost proportionally more work.
To get the complexity of bisecting k-means, ask how many times this inner algorithm runs. The number of runs equals the height of the tree you are building. If we assume the tree is balanced and binary, the height of the tree is — a balanced binary tree over leaves has exactly levels, since each level doubles the number of nodes — so k-means runs about times:
The reasoning: runs, each costing , multiply together. (Strictly, later runs operate on smaller subsets, so the real total is smaller than the product — but the professor's product form is the standard complexity statement, and it correctly captures the headline: an extra factor.) The tree does not have to be binary — you could have a ternary tree or an n-ary tree based on your requirement — and it might be skewed in one direction; both choices change the number of runs. A balanced tree gives the best case of runs; a badly skewed tree can make the number of runs approach instead. Either way, the result is costlier than running plain k-means once.
15.3.4 Limitation: The Greedy, Local-Factor Problem
Bisecting k-means follows a greedy strategy: once you have broken a bigger cluster into smaller clusters, you cannot merge two of those smaller clusters back together, even if they turn out to be very similar. The example in the lecture showed why this hurts.
Worked failure case: the points in the middle of the figure actually form a natural cluster — logically they belong together. But the algorithm split them, because at the moment it decided, it was only looking at the local data it was handed: the cluster passed to k-means, and the local optimum that k-means found inside it. The same thing happened on the right-hand side. Looking globally, those two middle points are a single natural cluster, and an ideal algorithm should return them as one cluster, but the greedy splitting cannot see that.
Pitfall — greedy splits cannot be undone: this is the structural weakness of every divisive strategy, not a bug in the example. At each split the algorithm commits to a boundary; no later step ever revisits that boundary, and points that land in different subtrees can never be reunited. The k-means engine only makes this worse, because k-means itself only guarantees a local optimum for the cluster it is given — so the split is "the best split of this cluster" but not "part of the best overall clustering." It cannot look at the global picture, only at local factors, so it never reaches the global optimum. This is one of the core limitations of the approach.
Exam takeaway: bisecting k-means is greedy and locally optimal — be ready to explain why two similar clusters that got separated can never be rejoined.
Recap: bisecting k-means = repeated 2-means splits, cost on a balanced binary tree, and greedy forever. Bridge: the agglomerative route has the same "commit forever" property from the opposite direction — merging is also never undone — and it rests on a single workhorse data structure, the proximity matrix.
15.4 The Agglomerative Algorithm and the Proximity Matrix
Hook: The agglomerative strategy has no centroids and no objective function to optimize — it runs entirely on one table of pairwise distances, called the proximity matrix. Every merge decision, for every linkage method in the next sections, comes down to how you read (and update) that table.
15.4.1 The Overall Procedure
The agglomerative algorithm is one of the most popular hierarchical clustering techniques, and the procedure is simple.
Purpose: turn the data into a nested hierarchy without choosing K, using only pairwise distances.
Inputs and outputs: input is the set of points; output is the complete merge sequence — equivalently, the dendrogram.
Steps:
- Build a proximity matrix: compute the distance from each cluster to every other cluster, for all the clusters. Initially the clusters are the individual points.
- Merge the two closest clusters, or the two most similar clusters, whatever your notion of similarity turns out to be.
- Update the proximity matrix, because two clusters are now one and the distances involving them have changed.
- Repeat these steps iteratively until only one big cluster remains.
That single cluster is the root of the dendrogram, and every intermediate merge is a junction in it. The whole algorithm is one loop with three moves: build, merge, update — then build again is unnecessary, since updates keep the table current.
The proximity matrix deserves its name: proximity means closeness, so the table stores "how close is every pair of clusters." Its cells are filled with the distance between the corresponding clusters, and the exact meaning of that distance is the only thing that varies between linkage methods. For two clusters and with sizes and :
where is a point in cluster , a point in cluster , and is the distance between them. Initially, clusters are single points, so the cell for and stores , the ordinary point-to-point distance.
Properties of the matrix (initial state): the matrix is symmetric — , because distance is symmetric — and the diagonal cells are the distance from a point to itself, which is zero. This halves the storage you actually need: only the cells above the diagonal hold information.
15.4.2 Worked Example: Nine Points
The lecture worked this on nine points.
Step one: treat all nine points as clusters — one, two, three, four, five, six, seven, eight, nine. These become the leaves on the X axis of the dendrogram.
Step two: find all pairwise distances and fill the proximity matrix. In the matrix, the X axis lists all the points and the Y axis lists all the points, so each cell holds the distance between one pair. For the pair the cell stores . The matrix is symmetric, and the diagonal cells are zero.
Step three: find the two most similar clusters. In this example the distance between one and two is the minimum among all of them, so clusters one and two are called similar and merged into a single cluster. The dendrogram shows a junction with a small height, because the merge happened at a small distance — height equals distance, as always.
Then iterate. The next closest pair turns out to be seven and eight, so they merge next. Notice the junction for seven and eight is taller than the one for one and two: their distance is larger, so their merge height is larger too. Next the closest remaining pair is five and six, and they merge. The process repeats until all the distances are consumed and the tree is complete. In the final picture, the left side of the screen showed the merging of the points and the right side showed the dendrogram growing in parallel — the same information in two views.
The example only names three merges, but the pattern is what matters: at every round you scan the table, take the smallest remaining entry, merge its two clusters, and add a junction whose height is exactly that entry's value. A fully numeric illustration of the same procedure (using the reference dataset's coordinates, so you can see real numbers): six points with Euclidean distances such that the smallest entries are and . The first merge is {3, 6} at height 0.11, the second is {2, 5} at height 0.14, and every later junction sits above them because the remaining entries are all larger. The dendrogram's shape is fully determined by the sorted order of the matrix entries.
15.4.3 Cutting the Example
Once the tree is built, you cut it at any level to decide the final clusters. In the example, a cut at a certain height gives: one cluster holding one and two, another cluster holding three and four (or however the merges fell), five and six together, and so on — each region below the cut line becomes one cluster.
This cut is the direct answer to the question you started with. If the business question asks for three groups, place the cut so that exactly three junctions fall below it; if it asks for seven groups, place the cut lower. The dendrogram's hierarchy is fixed, but the number of clusters is now a free choice made at the end — the whole point of avoiding K up front.
15.4.4 Updating the Proximity Matrix After a Merge
When two clusters merge, only a few cells of the proximity matrix need updating. Suppose C2 and C5 merge first in a diagrammed example. After the merge you have one cluster C2–C5 instead of two, so the cells involving C2 and C5 are updated to reflect the new cluster, while the rest of the matrix stays as it is: the distance between C3 and C4 does not change just because C2 and C5 merged.
The lecture stressed this point with the diagram: most cells are untouched, only the merged cluster's connections change. Concretely: in a matrix over current clusters, a merge removes two rows and two columns and adds one row and one column for the new cluster — so only cells are recomputed, out of total. The expensive part of each round is not the update but the search for the minimum entry, which is why the cost analysis in a later section focuses on the scanning.
Pitfall — a merge can be wrong in hindsight: every agglomerative merge is final. If round one merges two points that a better hierarchy would have kept apart, no later round can undo it — the error is baked into every level above. This is why the choice of linkage method (how you compute the cells after each update) matters more than any other detail of the algorithm.
Recap: agglomerative clustering = build the proximity matrix, repeatedly merge the closest pair, update only the merged cluster's cells — and the heights in the dendrogram are the merge distances. Bridge: "merge the two most similar clusters" is still vague, so the next sections define cluster similarity precisely — min, max, group average, centroid, and Ward's method.
15.5 Min Linkage
15.5.1 Definition
We keep saying "merge the two most similar clusters," so we need a precise definition of cluster similarity. The first strategy is min. Min says: the similarity between two clusters is defined by the two most similar points, one in each cluster. Concretely, the distance between clusters C1 and C2 is the minimum distance over all pairs of points with one point from C1 and one from C2:
where is any point in cluster , is any point in cluster , and is the ordinary distance between those two points. Find the pair of points, one in each cluster, whose distance is smallest; that distance becomes the inter-cluster distance, and that is what min means.
Two ways to picture it. Algebraically: scan every pair , collect all values, and keep the smallest one. Graphically: treat the points as nodes and each distance as an edge between them; then the min distance between two clusters is the shortest edge with one endpoint in each cluster. This graph view explains the alternative name used in the literature: min linkage is also called single link, because a single close pair is enough to link two clusters together.
Note the subtlety in direction: if your similarity is a distance (smaller = closer), you take the minimum; if you worked with similarities where bigger = closer, you would take the maximum. The names "min" and "max" come from the distance convention, and the lecture's exam questions follow that convention.
15.5.2 Worked Example
Worked example (real numbers): starting from a proximity matrix, you look for the minimum entry among all cluster pairs. In the reference data used for illustration:
- The smallest distance in the whole matrix is between points three and six, , so clusters {3} and {6} merge first — the dendrogram junction goes up to height 0.11.
- Next, scan the remaining entries: the smallest is between points five and two, , so {5} and {2} merge second, at height 0.14.
- After that, the merged clusters join in turn: the distance from {3, 6} to {4} is , which beats the distance to {2, 5}, so {4} attaches to the {3, 6} cluster next.
The merge order is the story of min: at every step, take the closest pair available — and once two clusters merge, the new cluster's distance to everyone else is again the minimum over all cross pairs, so the same rule keeps applying. (The spoken explanation mentioned a "p3 and p4" pair in passing; the diagram's exact labels were not fully audible. The canonical resolution from the distance matrix stands: is the smallest entry, then .)
Pitfall — one close pair speaks for the whole cluster: because a single pair decides the distance, min linkage is very sensitive to noise and outliers. One stray point sitting near another cluster acts as a "bridge" and drags the two clusters together, producing long chains instead of compact balls. This is the chaining behavior we examine with centroid linkage in section 15.8.
Recap: min linkage defines inter-cluster distance as the closest pair across the two clusters — the shortest edge in the graph view — and merges the pair with the smallest such distance. Bridge: max linkage is the mirror image: the two most dissimilar points decide.
15.6 Max Linkage
15.6.1 Definition
The second strategy is max. Max says: the similarity between two clusters is defined by the two least similar points, one in each cluster. Instead of the closest pair, take the most dissimilar pair. The distance between clusters C1 and C2 is the maximum distance over all pairs of points with one point from C1 and one from C2:
where again runs over every point in and over every point in . In the graph view, max linkage takes the longest edge with one endpoint in each cluster — the opposite of min's shortest edge. That is why the literature calls max linkage complete link: two clusters are only "completely linked" when every point in one is close enough to the other — the worst pair, the farthest two points, must also be acceptable. Under complete link, a group of points only becomes a cluster when all its points are pairwise linked — the points must form a clique.
15.6.2 Merging Still Picks the Most Similar Clusters
One point to note here: max only defines the similarity measure. When you merge, you still always merge the two most similar clusters — that is, at every step you pick the cluster pair whose max-distance is smallest. The formula defines how distance between clusters is measured; the merging rule stays the same.
This is a common point of confusion, so the lecture flagged it explicitly:
Q: Max uses the two most dissimilar points to define cluster distance — doesn't that mean max merges dissimilar things?
A: No. The max rule only changes the ruler, not the choice. At every step you still compare all candidate cluster pairs using the max-ruler and merge the pair whose ruler-reading is smallest. A cluster pair is merged not because its farthest points are far apart, but because, measured with the max ruler, it is the closest option on the table. Max-linkage clusters are not built by merging dissimilar things; they are built by merging the least dissimilar pairs as judged by their worst-case point pair.
15.6.3 How the Merge Order Differs from Min
Because the inter-cluster distance is measured differently, the merge order changes. In the example, under min the pairs three and six, then five and two merged early. Under max, the distances between the same points are recomputed as farthest pairs, and the picture shifts: in the lecture's figure, the distance between four and six turns out to be the maximum among the pairs under consideration, which keeps those clusters apart and pushes the merges elsewhere.
Worked example (why the order changes — real numbers): take the same reference data. Both min and max merge {3, 6} first, because that is a point pair with distance 0.11. But the second decision differs:
- Distance from {3, 6} to {4}: .
- Distance from {3, 6} to {2, 5}: .
- Distance from {3, 6} to {1}: .
The pair {3, 6}–{4} wins at 0.22, so under max, point 4 attaches to {3, 6} early — while under min, {2, 5} formed at 0.14 before {4} was attached at 0.15. Same points, same distances, different merge order, different dendrogram.
Step by step the strategy produces a different hierarchy, and the lecture emphasized that you can see how each strategy grows its own cluster shapes, with different clusters at the end.
Comparison — min vs max:
| Min (single link) | Max (complete link) | |
|---|---|---|
| Deciding pair | Closest pair across clusters | Farthest pair across clusters |
| Cluster shape it favors | Long chains, elongated, non-elliptical shapes | Compact, globular, clique-like clusters |
| Noise behavior | Sensitive — one outlier can bridge clusters (chaining) | Less susceptible — one odd point can't dominate |
| Weakness | Chaining across noise | Can break large clusters that are not tight balls |
When to pick which: prefer min when you expect elongated or non-elliptical natural clusters and your data is clean; prefer max when you expect tight, ball-shaped clusters or when your data is noisy. Neither is "correct" — the choice is about the shape you believe the truth has.
Recap: max linkage = farthest pair defines inter-cluster distance, but the merge rule still chooses the most similar (smallest max-distance) pair — a point the exam likes to test. Bridge: group average steps between the two extremes, letting every pair of points vote.
15.7 Group Average Linkage
15.7.1 Definition
The third strategy is group average. As the name suggests, you find all pairwise distances between the two clusters and take the average. The distance between C1 and C2 is the average of every distance between a point in C1 and a point in C2:
where is the number of points in cluster (its cardinality), the number of points in , and the double sum adds up for every ordered combination of one point from and one point from . The denominator is exactly the number of such pairs, so the formula reads: sum every cross-cluster distance, divide by the number of pairs, and that average is the inter-cluster distance used to decide the next merge.
(The professor's spoken explanation said "find all pair distance and divide by number of points in the cluster"; the standard form divides by the number of point pairs, — with clusters of size 2 and 3, that is 6 pairs, not 5 points. The formula above is the standard one and is what the exam will use.)
So we sum all over every pair, then divide by the number of pairs, and that average is the inter-cluster distance. Because every pair contributes one term to the sum, every point gets one vote — big clusters do not get extra weight per point, and small clusters are not drowned out.
15.7.2 A Middle Ground
Group average sits between the extremes of min and max: instead of letting one closest pair or one farthest pair speak for the whole clusters, it lets every point pair contribute. It is a reasonable, widely used default when you have no reason to prefer the extremes.
In the literature, the standard group-average method is known by its full name UPGMA — Unweighted Pair Group Method using Arithmetic averages. "Unweighted" means each point is weighted equally when the average is computed (a weighted variant, WPGMA, treats each cluster equally instead, which effectively gives fewer points more influence — used only when you have a reason to weight clusters, such as uneven sampling).
Worked example (real numbers): with the reference data, consider the cluster {3, 6, 4} (three points) against {1} (one point) and against {2, 5} (two points).
Since 0.26 is smaller than 0.28, clusters {3, 6, 4} and {2, 5} are the pair to merge at this round. Note how the answer uses all six cross distances — no single outlier pair can hijack the decision the way one close pair hijacks min.
Pitfall — averages hide outliers: group average is a compromise, so it inherits a diluted version of each extreme's weakness. A bridge point between clusters raises the average (unlike min, which would jump at it) but does not veto the merge the way max would. If your data has extreme outliers, the average can still be pulled toward them; if your clusters are strongly elongated, averaging the many "far" pairs can delay a merge that min would have made instantly.
Recap: group average = mean of all pairwise cross-cluster distances (UPGMA), the middle path between min and max, and a sensible default. Bridge: the next two methods stop measuring point pairs entirely — they summarize each cluster by one point: the centroid (centroid linkage) or the error (Ward's method).
15.8 Centroid Linkage
15.8.1 Definition
A fourth way to define inter-cluster distance is to use the centroids. Compute the centroid of each cluster, then take the distance between the centroids:
where is the centroid (mean point) of cluster and is the centroid of cluster . The centroid of a cluster is its average point: compute the mean of the x-coordinates and the mean of the y-coordinates across all points in the cluster, and that pair of means is . The notation means the Euclidean norm — the ordinary straight-line distance between the two center points.
With a third cluster C3 whose centroid sits somewhere else, you compare the centroid distances between all pairs and merge the two clusters whose centroids are closest. It is very easy to visualize: clusters are represented by their center points, and similarity is just center-to-center distance. Instead of comparing every point pair (min, max, group average), centroid linkage compares one pair of numbers per cluster pair — cheap to compute and easy to draw.
15.8.2 The Convexity Assumption
Q: The centroid is arbitrary, isn't it?
A: No, it is not arbitrary — but a centroid-based strategy does have a fundamental issue: it assumes your natural clusters are circular or convex in nature. If I use a centroid-based strategy, I am assuming the natural clusters are convex, and in real life you might not have convex clusters. Real-world clusters can be curved, elongated, or shaped like crescents, and then the centroid no longer represents the cluster well — the mean of a crescent lands in the empty space where no data lives. Centroid linkage looks very lucrative and easy to visualize, but it might not give you natural clusters so quickly.
The professor's answer separates two questions. Arbitrary? No — the centroid is a well-defined, reproducible summary (the mean), not a random choice. Safe? Not necessarily — a centroid is only a faithful summary when the cluster is blob-shaped. If the cluster is convex (roughly circular or elliptical), the centroid sits inside the data and the center-to-center distance is a fair measure of how far apart the clusters are. If the cluster is concave — crescent-shaped, ring-shaped, S-shaped — the centroid can fall where no points exist, and two clusters with similar centers can still be entirely separate in space.
Visual intuition: picture two crescent moons facing each other, their tips almost touching. Both centroids lie in the gap between the moons — almost on top of each other — so centroid linkage thinks the two clusters are close, while visually they are two distinct shapes. A distance that uses the closest points (min) would see the tiny gap at the tips; a centroid distance sees only the two empty-air centers.
Pitfall — inversions: centroid linkage is the one standard method that can produce inversions in the dendrogram: a later merge at a smaller height than an earlier one. This happens because the new centroid after a merge is a weighted compromise of the two old ones, and the compromise can land closer to some third cluster than either original centroid was. An inverted dendrogram can no longer be read with simple horizontal cuts — junction heights no longer increase up the tree — so a "taller junction = farther apart" reading breaks.
15.8.3 Worked Example: Min vs Centroid on Four Points
Worked example — min linkage on four points (real numbers): four points with coordinates , , , . Pairwise distances:
| pair | distance |
|---|---|
| 1.00 | |
| 1.12 | |
| 1.80 | |
| 2.06 | |
| 2.83 | |
| 3.61 |
Round 1: the minimum entry is , so {1} and {2} merge — the same first move the lecture described for its four-point figure.
Round 2: the distance from the new cluster {1, 2} to point 3 is not measured to a center; min looks at the closest pair, . The distance to point 4 is . The smallest entry is 1.12, so {1, 2} merges with point 3.
Round 3: the cluster {1, 2, 3} versus point 4 uses the closest pair again: . The merge happens at 1.80, and everything is one cluster.
The cluster grows in a linear, chain-like fashion: 12, then 123, then 1234 — each new point attaches through its nearest existing point, never through the group's center.
Now contrast what centroid linkage does to the same decision. After {1, 2} merges, its centroid is . The centroid distance to point 3 is — noticeably larger than min's 1.12, because the centroid averages the close point 2 and the far point 1. Working the whole dataset through with the centroid ruler is set as homework — you try it yourself and see how the cluster shapes come out differently. The mechanism to watch: whenever the centroid is not the nearest point, the merge order changes; and because the centroid moves after every merge, the history keeps rewiring.
15.8.4 Continuous Clustering (Chaining)
This chain-like growth is not accidental. Min strategy actually supports continuous clustering, also called chaining: each new point attaches to the existing chain through its nearest neighbor, so the cluster stretches out in a line-wise fashion. The lecture revisited this idea with a figure showing distances between two clusters defined by the minimum distance between them, and noted that continuous clustering is exactly the behavior min produces.
Think of it as a railway: the cluster is a line, and every new station connects to the station that is closest to it, wherever that lies on the line — so the line can snake arbitrarily far from where it started. In the four-point walkthrough above, points attach at 1.00, then 1.12, then 1.80 — each attachment through the nearest single point, producing the linear chain 12 → 123 → 1234.
Pitfall — the chaining trade-off: chaining is what makes min find long, thin, chain-like clusters — great for elongated natural shapes, terrible when noise connects clusters like a zipper. Centroid linkage (when the data is convex) produces compact clusters instead, because distance to the center makes outliers pay. But compactness only comes free under the convexity assumption; break that assumption and the centroid starts lying. The trade-off is now visible: min finds long, thin, chain-like clusters, while centroid linkage finds compact ones — but only when the data is actually convex.
Exam note: the homework asks you to run the centroid strategy yourself on the four-point example and compare it with min — work the same dataset you saw and check how the cluster shapes come out differently (watch whether the merge order changes, and whether the dendrogram stays monotone).
Recap: centroid linkage summarizes each cluster by its mean and measures center-to-center distance — easy to draw, but it assumes convex clusters and can invert the dendrogram. Bridge: Ward's method is the last linkage — and it answers the same "one number per cluster" idea with error instead of a center.
15.9 Ward's Method
15.9.1 SSE as a Cluster Quality Measure
The last method is Ward's method, and its logic is simple. Consider two clusters C1 and C2; each cluster, on its own, has some SSE value. SSE is the sum of squared errors of the cluster:
where is a point in the cluster and is the centroid of the cluster. The error of one point is its distance from the cluster's centroid, and SSE squares that error and adds it over every point — the same objective function k-means minimizes. (The professor described SSE only in words — "as we start merging clusters the SSE value goes on increasing" — and the sum-of-squared-distances form above is the standard definition used in the reference; it is what you should write on the exam.)
Why squared? Squaring does two things: it makes every error count positively (no cancelling of + and − deviations), and it punishes large errors more than linearly — one point that is very far from the centroid contributes a disproportionately large penalty. That is exactly the behavior we want from a quality measure: a cluster with one stray faraway point is much worse than a cluster where the same total error is spread evenly.
If every point is its own cluster, each cluster has SSE zero, because each point sits exactly at its own centroid. As clusters merge, the SSE value keeps increasing, because points are now measured against a centroid that is not their own. So the lower the SSE, the purer the clusters: SSE is a quality gauge that starts at perfect zero and degrades with every merge.
15.9.2 The Minimum-Increment Rule
Ward's method turns this into a merging rule. When you merge two clusters, the SSE of the combined cluster is bigger than the sum of the two separate SSEs, and the difference is the increment:
Ward's method says: merge the two clusters where the increment in SSE is minimum. You always merge the pair whose union costs the least extra error. Note the two terms on the right are what we already have (the separate SSEs, known before the merge); the only computation is the SSE of the would-be union. So the increment measures the price of a merge in error units, and Ward always pays the cheapest price available.
There is a closed-form shortcut for the increment that avoids recomputing the union's SSE — it depends only on the sizes and centroids of the two clusters:
Why the formula takes this shape (derivation): the increment is driven entirely by the separation between the two centroids, scaled by how balanced the two clusters are. The full algebra:
Subtracting from both sides gives the closed form. A sanity check: when both clusters are singletons, , the scale factor is , and the increment is — merging two single points costs half the squared distance between them. The larger either cluster is, the more expensive it is to drag it across a fixed centroid gap, because more points share the new, compromised centroid.
15.9.3 The Temporary-Merge Procedure
To apply the rule, you try merges before committing. With clusters C1, C2, C3, C4 in front of you, temporarily merge C1 and C2 and note down the increment in SSE. Then temporarily merge C1 and C3 and note that increment. Then C2 and C3, and so on, covering the candidate pairs. Whichever pair shows the smallest increment is the one you actually merge, and then you repeat the whole procedure for the next step. So Ward's method defines similarity between two clusters as the increase in squared error when the two clusters are merged, and the algorithm keeps choosing the pair that minimizes that increase.
Worked example (real numbers): four points, , , , . All singletons start with SSE 0, so each round's increments come from the closed form.
Round 1 — try every pair of singletons:
| candidate pair | SSE | |
|---|---|---|
| {1}, {2} | 1.00 | 0.50 |
| {2}, {3} | 1.25 | 0.63 |
| {3}, {4} | 3.25 | 1.63 |
| {1}, {3} | 4.25 | 2.13 |
| {2}, {4} | 8.00 | 4.00 |
| {1}, {4} | 13.00 | 6.50 |
Smallest increment: 0.50 → merge {1} and {2}.
Round 2 — try the pairs among {1, 2}, {3}, {4}:
Smallest increment: 1.63 → merge {3} and {4}. Note what just happened: min linkage on the same data merged {1, 2} with {3} second (chain-like growth), while Ward's method merges {3, 4} instead — the increment rule balances the tree and resists the chain.
Round 3 — one pair left:
The total SSE at the end is — the accumulated increments exactly add up to the SSE of the final single cluster, a useful way to check the arithmetic. Sense-check: the increments grow (0.50 < 1.63 < 5.56), as they must — merging always costs at least as much extra error as before.
Pitfall — SSE rewards convex, ball-shaped clusters: Ward's method inherits k-means' objective, so it quietly assumes clusters are roughly spherical with comparable sizes. Merging a tiny tight cluster with a large scattered one costs a big increment (many points dragged to a far centroid), so Ward resists such unions — usually a feature, but a bias if your truth is elongated or very unequal in size. And like all agglomerative methods, each Ward merge is final; the method is greedy with respect to total SSE and never revisits a decision.
Note: Ward's method is the correct hierarchical analog of k-means — both minimize the same SSE objective — and it is mathematically close to group average when the point distances are squared. Because of that connection, Ward's output is often used as a smart initialization for k-means: cluster hierarchically, cut, then refine with k-means.
Recap: Ward's method merges the pair with the smallest increase in SSE, computable as . Bridge: with five linkage rules defined, the natural question is cost — the proximity-matrix machinery is simple, but is it cheap?
15.10 Complexity of Agglomerative Clustering
15.10.1 The Cost of the Matrix and Its Updates
What is the complexity of the agglomerative strategy? It comes out to roughly for points. (The professor's spoken number was garbled — "roughly nq" — and the standard analysis gives for the naive implementation, with an variant; both are stated below and both are fair game for the exam.)
The reasoning in three pieces:
Piece 1 — building the matrix costs . The proximity matrix holds the distance between every pair of points. There are pairs, and since the matrix is symmetric you can store just one triangle — either way, the number of distances is proportional to . Computing each entry takes constant work (one Euclidean distance in fixed dimension), so filling the matrix is .
Piece 2 — each of the merges costs in the worst case. The loop runs times, because each merge reduces the cluster count by one, from down to 1. Two tasks repeat every round:
- Find the minimum among the inter-cluster distances to pick the next merge. Scanning the current matrix costs when there are clusters left.
- Update the matrix after the merge. Only the cells touching the new cluster change — cells out of the total (section 15.4.4).
With shrinking from down to 1, the scanning dominates, and summing the round costs gives:
Piece 3 — smarter bookkeeping gives the variant. If the distances from each cluster to every other cluster are kept in a sorted structure (a heap or sorted list), finding the closest pair drops from to per round, and the total becomes . The storage cost is the same in both cases: the matrix itself occupies space.
The bottom line: naive agglomerative clustering is time and space; the heap-based variant reaches time. Either way, the in the space and the extra in the time are why hierarchical clustering is described as expensive — it is practical for thousands of points, not millions.
15.10.2 Where the Algorithms Land
Putting the complexity numbers together: k-means costs , which is a good complexity — linear in the number of points, the only problem there is that it is a center-based strategy, so you can only get convex clusters. Hierarchical clustering, whether agglomerative or bisecting k-means, is costlier — agglomerative pays or , bisecting k-means pays an extra factor over k-means.
If you are looking for non-convex structure, density can be another notion of what a cluster is — which is exactly where the next algorithm comes in. The complexity ledger so far:
| Method | Time | Space |
|---|---|---|
| K-means | ||
| Bisecting k-means | ||
| Agglomerative (naive) | ||
| Agglomerative (heap variant) |
15.10.3 Choosing a Linkage Method in Practice
Q: Is choosing among these methods in a real-time setting a subjective decision?
A: Yes. These are different ways in which you can define your clusters, and based on your requirement you choose min, max, group average, Ward's method, or another — whichever fits your problem definition. There is no single best linkage for everything; the choice is driven by what your data and your application need. If the data is clean and elongated, min; if it is noisy and you expect tight balls, max; if you want a balanced default, group average; if you want compact, variance-minimizing clusters, Ward's.
Exam note: be ready to reproduce the complexity story: building the proximity matrix is , the repeated minimum-finding and updates push the naive total to roughly , and the heap-based variant reaches — versus k-means' much cheaper .
Recap: agglomerative clustering buys its K-free flexibility with -style costs. Bridge: since all distance-based methods fail on non-convex shapes, the next unit switches the notion of similarity entirely — from distance to density.
15.11 A Divisive Strategy: Minimum Spanning Tree
Hook: Splitting a cluster means choosing which connection to cut. If the points are held together by a network of edges, the most natural cut is the most expensive edge of the cheapest possible network — that is the entire minimum-spanning-tree strategy, and it is a divisive mirror of single-link agglomerative clustering.
15.11.1 Building the MST
Another example of a divisive hierarchical strategy is based on the minimum spanning tree, or MST. The strategy is easy to visualize.
What a spanning tree is: take the points as nodes and draw edges between them, with each edge labeled by its length. A spanning tree is a set of edges that (1) connects every point to every other point (no point is left isolated), (2) uses exactly edges for points, and (3) contains no cycles — there is exactly one path between any two points. A minimum spanning tree is the spanning tree with the smallest possible total edge length.
Purpose: the MST is a skeleton of the data — the cheapest network that keeps the points connected — and its edges are ranked by length, which gives the divisive algorithm a natural cutting order.
Building it: initially all the points are treated as one big cluster. First you build a minimum spanning tree over the points — the tree that connects all the points with minimum total edge length. Standard algorithms (Kruskal's or Prim's) grow this tree in time with a heap, or on dense inputs. Once the MST exists, every point is connected to every other point through the tree, so all the points belong to one cluster.
Why the MST, and not the full distance graph? The full graph has edges; the MST keeps only the most important ones. It is the same compression that min linkage performs implicitly: the shortest-edge connections alone are enough to encode the cluster structure, which is why the MST hierarchy ends up equivalent to single-link clustering.
15.11.2 Breaking the Largest Edge
Now you break the big cluster into smaller parts. Which edge do you cut? You break the edge with the maximum distance, because that edge contributes most to the dissimilarity of the cluster.
Worked example (from the lecture): in the example, the edge between point one and point three has the maximum distance in the tree, so that edge is broken first: this produces cluster one and cluster two. (Breaking one edge splits the tree into exactly two connected pieces — one containing point 1, the other containing point 3 and everything attached to it.) Then you repeat: find the next largest-distance edge and break it, producing three clusters, then a fourth cluster, and so on, iteratively, until each point is its own cluster. The sequence of cuts 1 → 2 → 3 → 4 clusters is the divisive hierarchy, and the lengths of the broken edges are the merge heights of the equivalent dendrogram.
The intuition for "break the largest edge": the tree's edges are the chains of evidence that hold the cluster together. A short edge means "these two points are close — one group"; a long edge means "these two points are barely connected — this is the weakest link." Cutting the weakest link first produces the most defensible split. Note that "largest edge length" is the same thing as "smallest similarity," since distance and similarity are inverse — the professor used both phrasings.
15.11.3 Algorithm Summary
To restate the algorithm:
- Create a minimum spanning tree over all the points.
- Repeat: create a new cluster by breaking the link that corresponds to the largest distance (the smallest similarity).
- Stop when every point is a singleton cluster.
Each break of the largest edge turns one cluster into two, and the sequence of breaks forms the divisive hierarchy.
Complexity and cost: building the MST costs (heap-based Kruskal or Prim), and breaking the remaining edges is cheap once they are sorted by length — so the whole divisive hierarchy is dramatically cheaper than the agglomerative scan. The tree itself needs storage.
Equivalence worth knowing: the MST strategy produces exactly the same cluster hierarchy as single-link (min) agglomerative clustering — both are driven by the shortest edges in the graph. The two algorithms look opposite (splitting vs merging) but encode the same structure, which is a good exam-style connection.
Pitfall — greedy cuts, brittle with noise: each cut is made once and never revisited, so a single noisy point that happens to be linked by a long edge can create a one-point "cluster" early, fragmenting the structure. And because the MST keeps only the shortest edges, an outlier pair can distort the skeleton. If the data is noisy, combine the MST idea with a density check (as DBSCAN does in the next sections) rather than trusting edge lengths alone.
Recap: MST divisive clustering = build the cheapest spanning tree, repeatedly cut the largest edge, until singletons — the splitting mirror of single-link merging, at cost. Bridge: all methods so far measure distance; the next unit abandons distance as the primary criterion and measures density instead.
15.12 DBSCAN: Why Density?
Hook: Two crescents face each other — two groups to the human eye — and k-means draws one straight line through both of them. Distance is not the problem: the points are far apart and close together in different places. The missing ingredient is density — how many points are packed into a region — and that is what DBSCAN clusters by.
15.12.1 When Distance Does Not Help
All the strategies so far are distance-based clustering mechanisms: min, max, group average, Ward's method — distance is the main criterion everywhere. But a lot of the time distance does not help you find the natural clusters in the data.
Consider an example: the points on the screen form two natural groups, and if you look closely you can see both of them. Now suppose you use a center-based strategy, say k-means with K equals two. One centroid lands in one region, the other centroid lands in another, and the clusters k-means returns cut right across the natural groups.
Worked failure (from the lecture): the two natural groups are shaped like interlocking crescents. K-means with K equals two places one centroid in one open region and the other centroid in the other open region, then assigns every point to the nearer centroid. Because the assignment boundary is a straight perpendicular bisector, the two returned clusters cut across both crescents — each returned cluster grabs the tail of the other's natural group. The returned clusters are not the natural clusters at all.
Why does this happen? K-means is a center-based model of a cluster: a cluster is "everything near one center," so its boundaries are convex (straight cuts, then circular or elliptical regions). A crescent is not convex — the natural group wraps around empty space — so no single center and no straight boundary can represent it. Distance alone cannot separate these two natural groups, so sometimes you have to come up with a different measure to form natural groups in the data — and one such measure is density.
Visual intuition: think of a night-sky map. Astronomers find star clusters not by measuring how far each star is from every other, but by noticing where stars are packed thickly versus spread thinly. The Milky Way is one giant chain of dense patches connected by fainter ones. "Thickly packed" is a local, spatial statement — it needs no global center and no fixed number of groups — and that is exactly the viewpoint DBSCAN adopts.
15.12.2 Density Needs Two Ingredients
If you want to define density, you need two things. First, you have to define an area: in how much area, in some unit, are we counting points — is it a square, a circle? Second, you have to say how many points should be inside: the minimum number of points that makes a region dense. If there are more points than that minimum, you call the region dense; if fewer, it is less dense. So density always comes with two components: the definition of the area, and the minimum number of points, which we call minPts.
An everyday analogy: "how crowded is a restaurant neighborhood?" Two numbers answer it — how far you are willing to walk (the area) and how many restaurants make a block "busy" (the minimum count). Change the walk distance and the same block flips from busy to empty; change the minimum and the same crowd flips from crowded to not. Density is not an intrinsic property of the data; it is a property of data measured with your chosen area and threshold — which is why both numbers become tunable parameters of the algorithm.
15.12.3 The Full Name
The algorithm built on this notion is DBSCAN, which stands for Density-Based Spatial Clustering of Applications with Noise. It is a density-based clustering algorithm: you define density using minPts and eps, you pass both as tunables when you run it, and it finds clusters by connecting dense regions.
Decompose the name and you get the whole plan:
- Density-Based: similarity is measured by point density, not by distance to a center.
- Spatial: the area component is a circle of radius eps around each point — a spatial neighborhood.
- Applications with Noise: the algorithm has an explicit, first-class category for noise — points that belong to no dense region — instead of forcing every point into some cluster.
Real-world: natural groups in the real world are often non-convex — crescent shapes, rings, elongated blobs — which is exactly when density-based thinking helps and center-based thinking fails. Store customers clustered in walking neighborhoods, crime hotspots on a city map, galaxies in a sky survey — all are spatial density phenomena.
Recap: distance fails on non-convex shapes; density — points-per-area with a threshold minPts — is the alternative measure, and DBSCAN is its standard algorithm. Bridge: density needs a precise vocabulary: which points count as "inside," and who decides whether a region is dense? The next section defines the three point categories: core, border, and noise.
15.13 DBSCAN: Core, Border, and Noise Points
15.13.1 The Two Parameters: Eps and MinPts
DBSCAN takes two tunable parameters: eps, the radius of the neighborhood circle drawn around a point, and minPts, the minimum number of points that must lie in that area for the region to count as dense. Example values from the lecture: eps equals one centimeter, minPts equals five. To check whether a point lies in a dense region, build the circle of radius eps around it and count the points inside. If the count is greater than or equal to minPts, the area is dense.
Formally, the eps-neighborhood of a point is the set of points within distance eps of :
The inequality is inclusive — it admits every point whose distance to is at most eps, including itself, because satisfies it. (The professor did not state this explicitly; it is the standard convention: the count in the neighborhood includes the point itself.) This convention is what makes the definition well-behaved — with eps = 1 cm and minPts = 5, the point itself is already counted, so a point needs four other points inside its circle to qualify.
Why two parameters? eps fixes the scale of "nearby" (how far you look), minPts fixes the threshold of "crowded" (how many must be there). Both together define a density standard; change either one and the same dataset is read as dense or sparse differently.
15.13.2 Core Points
Every point in the dataset belongs to one of three categories. A core point is a point that satisfies the minPts criterion in the area of radius eps around it. For point p1: draw the circle of radius eps, count the points inside, and if the count is at least minPts, p1 is a core point. So a core point is a point whose eps-neighborhood is dense, and the dense area it sits in is called a dense region:
The vertical bars mean "size of the set" — the number of points inside the neighborhood. With eps = 1 cm and minPts = 5, p1 is a core point because its circle contains five points (including itself). A core point is the interior of a cluster: it has enough company around it that it can anchor other points. Core points are the load-bearing points of DBSCAN — clusters are built out of them, and no point can be part of a cluster without a chain of core points behind it.
15.13.3 Border Points
A border point is a point that does not satisfy the minPts criterion itself, but can still be reached with the help of a core point. For point p2 in the example: draw the circle around p2 and count — the count is four, which is less than minPts of five, so p2 is not a core point. But p2 becomes a border point if, in its surrounding area, there is at least one point that is a core point. If any point in p2's eps-neighborhood is a core point, p2 counts as a border point, because it hangs off a dense region even though it does not sit inside a dense region of its own.
So border points are the edges of clusters: they are the points that are close enough to the dense interior to belong, but not dense enough to support anyone else. A border point cannot expand a cluster — it only attaches to one. (Note the definition is a one-way street: the core point must lie within eps of the border point, i.e., the border point must lie within eps of the core point — the two conditions are the same distance check.)
15.13.4 Outlier (Noise) Points
The third category is the outlier point, also called the noise point. An outlier satisfies neither condition: in its given area it does not satisfy the minPts criterion, and it cannot be reached with the help of any core point — there is no core point anywhere in its surrounding area. Consider point c: build the area around it, the count falls below minPts, and scanning its neighborhood, no point there is a core point. Then c is a noise point.
Visual intuition for all three: draw eps-circles on a scatter plot and label each point:
- Circle is crowded (≥ minPts points inside) → core — a filled-in area.
- Circle is sparse, but touching a core point's circle → border — the rim of the dense region.
- Circle is sparse and far from any core point → noise — an island in empty space.
Worked example (from the lecture): with eps = 1 cm and minPts = 5 —
- Point p1 has five points inside its circle (p1 itself plus four others). Since , p1 is a core point.
- Point p2 has four points inside its circle. Since , p2 is not a core point. But a core point lies within p2's vicinity, so p2 is a border point.
- Point c has fewer than minPts points inside its circle, and scanning the circle reveals no core point anywhere near it. Since c satisfies neither condition, c is a noise point.
The three categories were re-explained with a clean example: point A is a core point because its area is dense; point B does not satisfy the minPts criterion but can still be reached with the help of a core point, so B is a border point; point C satisfies neither condition, so C is a noise point.
Pitfall — minPts semantics trip students up: the count includes the point itself, so "five points in the circle" really means "the point plus four others." Also note minPts is a global standard: it is compared against every point's neighborhood, so a point is never "a little core" — it either meets the bar or it does not, and the entire classification follows from one count per point.
Cost note: classifying every point requires, per point, finding all points within eps — a naive all-pairs scan costs , but with a spatial index (such as a kd-tree) DBSCAN runs in about for low-dimensional data, and it needs only memory for labels.
Recap: every point is core (neighborhood ≥ minPts), border (below minPts but reachable from a core point), or noise (neither). Bridge: the categories alone don't cluster anything — the next section defines how points get connected into clusters: direct and indirect density reachability.
15.14 DBSCAN: Building Clusters from Reachability
15.14.1 Direct Density Reachable
With the three point categories in place, DBSCAN defines how points connect. A point A is direct density reachable if it can be reached by traversing through a core point — in plain words, if there is at least one core point in its vicinity. Border points are exactly the points that are direct density reachable from some core point.
The precise statement: A is directly density reachable from a point B when B is a core point and A lies within eps of B — that is, . The asymmetry is essential and easy to miss: the reachability must start at a core point. A border point cannot reach anything — it lacks the density to vouch for other points — but it can be reached. In the example figure, every blue border point is directly reachable from some green core point, and no border point acts as a source.
Think of it as a reputation chain: only "established residents" (core points) can vouch for newcomers; newcomers can receive a voucher but cannot issue one.
15.14.2 Indirect Density Reachable
Then there is indirect density reachable. Point A and point B are indirect density reachable if you can travel from B to A by traversing through core points in a sequential fashion: B sits next to a core point, that core point sits next to another core point, and so on, until you reach A. The chain of core points is the bridge that connects two dense areas.
Formally: A and B are (indirectly) density reachable when there is a sequence of points with , , where each step is direct density reachability (each for is a core point and ). The first step may start from a core point, and the final step may land on a border point — the middle of the chain is all core points.
The everyday picture: a bridge built of stepping stones. Each stone (core point) is close enough to the next that you can cross; the chain connects two banks (dense regions) that are never directly adjacent. This is why a cluster can snake across a large area — no single point needs to see the whole cluster, only its neighbor in the chain.
15.14.3 How a Cluster Grows
Worked example (from the lecture): this is how DBSCAN builds clusters. Given a dataset with two natural clusters, red and blue, the algorithm first identifies a core point somewhere. All the points in the vicinity of that core point become part of the cluster, and the cluster grows from there: every point in the neighborhood is checked, points that are themselves core points connect onward, and the cluster grows iteratively until no more points can be reached. Two points are part of the same cluster when you can go from point one to point two by moving through a dense area the whole way.
In the accompanying graph, all the green points are core points; connect the green points together, and each connected component is a separate cluster, with the blue points as border points attached to the green chains and the red points as noise.
The growth rule in one sentence: a cluster is everything reachable from a starting core point through chains of core points — including the border points attached at the ends — and nothing else.
The algorithm's five steps (standard form): (1) label every point core, border, or noise; (2) discard the noise points; (3) put an edge between every pair of core points within eps of each other; (4) take each connected component of core points as a cluster; (5) assign each border point to the cluster of one of its associated core points (a tie-breaking rule is needed when a border point touches two clusters). The lecture's narrative — "identify a core point, grow through core neighbors, stop when nothing more is reachable" — is the same procedure viewed from the inside.
15.14.4 The Core-Bridge Picture
The whole idea, restated: we are connecting two dense areas together. We do it by putting core points in the center and connecting core points in a sequential fashion, so that all the dense areas link up into one cluster. What you have to find, in the end, is the set of indirect density reachable points, and from that set the clusters emerge.
Visual intuition: imagine dense blobs of points separated by thin bridges of sparse points. The blobs are the core regions; the bridges are chains of core points (still dense enough to pass the minPts test, just barely); noise floats between them unattached. Each maximal reachable group is one cluster, and the number of clusters is decided by the data's connectivity — not by any K chosen in advance. That is the density answer to the "how many clusters?" question: as many as there are separate reachable regions.
Pitfall — reachability is not symmetric: density reachability is one-directional because the first point in a direct step must be a core point. A border point can be reached from a core point, but the reverse (border → core as a first step) is not allowed. In most well-formed clusters this asymmetry is invisible (border points of the same cluster are mutually reachable through the core chain), but it matters for precision — and it is a favorite exam distinction between "density reachable" and "density connected."
Recap: clusters = connected components of core points, extended by border points; direct reachability starts at a core point, indirect reachability chains core steps across dense regions, noise is discarded. Bridge: with the machinery in place, the next section asks when DBSCAN shines — and the one situation where it breaks.
15.15 DBSCAN: Strengths and Failure Mode
15.15.1 Resistance to Noise and Arbitrary Shapes
DBSCAN has a clear advantage: it is resistant to noise. If you use a center-based cluster, noise moves the center around; DBSCAN has a dedicated category of points — outliers — that is focused on finding the noise, so noise gets labeled instead of shifting the cluster. It can handle noise, and it can handle clusters of various sizes and shapes.
The contrast is structural. In k-means, every point is assigned to a cluster, and every point counts in the centroid update — so a few outliers pull the center and distort the whole boundary. In DBSCAN, outliers never join a cluster: they fail both conditions and are dropped from cluster formation entirely, so they influence nothing. Noise is labeled, not absorbed.
Worked example (arbitrary shapes, from the lecture): in the example, the algorithm identifies one core point, checks all the points in its vicinity, connects the core points it finds, and grows the cluster across the arbitrary shape — a blob that snakes and bends, impossible for any straight boundary. The same is repeated iteratively on the other natural cluster. Each cluster is exactly a reachable region of dense points, so its shape is whatever the data's shape is — crescents, rings, and amoebas all come out whole.
Visual intuition: compare the two cluster models on the same amoeba-shaped group. K-means draws a circle around the middle of it — cutting off the tentacles. DBSCAN follows the dense path wherever it leads — the tentacles are part of the cluster because they are dense, not because they are near a center.
Real-world: real data is almost always noisy, so an algorithm with an explicit outlier category is attractive in practice — outliers are labeled, not absorbed. In fraud detection or sensor cleaning, the noise points themselves are often the valuable output: DBSCAN doubles as an outlier detector.
15.15.2 When DBSCAN Does Not Work: Varying Density
DBSCAN does not work properly when density is not uniform — when the density in one cluster is different from the density in another.
Worked failure (from the lecture): the example dataset actually contains six natural clusters, but with a particular choice of minPts and eps, DBSCAN returns three clusters: the dense clusters get found, while the sparser ones are merged or mislabeled. If you change minPts and eps, you get a different set of clusters, but still not the six. You can see it in the figure — the algorithm identifies this region as one cluster and that region as another, but the true natural clusters are the smaller six.
The reason is the algorithm's assumption: it assumes one density scale for the whole dataset, so when clusters live at different densities, a single eps and minPts cannot serve all of them. The mechanism in detail: eps and minPts are global numbers, compared against every point's neighborhood. Set them for the dense clusters and the sparse clusters' neighborhoods fall below minPts — their points get labeled noise or get absorbed into whatever dense region is near. Set them for the sparse clusters and the dense clusters' neighborhoods all interconnect — several dense clusters merge into one big blob, exactly the six-to-three collapse above.
This is the same lesson as every clustering method: the model encodes an assumption about cluster shape. K-means assumes convexity, min assumes chains, DBSCAN assumes one density. The fixed eps circle is a single yardstick; a dataset with mixed density needs a ruler per region (which is what algorithms like OPTICS attempt) — beyond this course's scope but worth knowing why it fails.
15.15.3 Choosing Eps and MinPts
How do you decide on the values of eps and minPts? The lecture assigns this as homework: the last slide of the presentation is based on that question, and you are expected to work out the approach for choosing the radius and the minimum point count. Both values are tunables you pass to the algorithm, and the choice drives everything — as the varying-density example shows, the same dataset under different eps and minPts settings gives very different clusterings.
The standard approach, for reference: the k-dist plot. For a chosen (the intended minPts), compute the distance from every point to its -th nearest neighbor; sort those values in increasing order and plot them. Points inside real clusters have small k-dist values (their -th neighbor is close); noise points have large ones. The plot is flat for a long stretch and then rises sharply at the knee — the knee's value is a good eps, and is minPts. The lecture's example dataset (3000 points) yields a clear knee, and eps = 10, minPts = 4 recovers its clusters. Rule of thumb: if is too small, a few close noise points get mislabeled as clusters; if is too large, small genuine clusters (smaller than ) get labeled as noise.
Exam note: choosing eps and minPts is set as homework, so make sure you can reason about how the two tunables affect the result — a larger eps connects more points (fewer, bigger clusters); a smaller eps disconnects more (more, smaller clusters or noise); minPts sets how much company a point needs before it can anchor a cluster. The varying-density case — six natural clusters returning three — is the canonical illustration of a bad (eps, minPts) pairing.
Recap: DBSCAN's strengths — noise labeled instead of absorbed, arbitrary shapes and sizes — rest on one assumption: a single density scale. When densities vary, one eps and one minPts cannot win. Bridge: that trade-off, plus the complexity picture, closes the clustering unit in the next section.
15.16 The Clustering Landscape: Complexity Recap
15.16.1 K-Means vs Hierarchical vs Density
| Algorithm | Strategy | Complexity | Shape assumption |
|---|---|---|---|
| K-means | Center-based (partitional) | Convex clusters only | |
| Bisecting k-means | Divisive hierarchical | Inherits k-means splitter | |
| Agglomerative clustering | Agglomerative hierarchical | Roughly , variant | Depends on the linkage |
| DBSCAN | Density-based | No K needed; two tunables eps, minPts | Any shape, uniform density |
The clustering unit closes with this contrast. K-means has good complexity, and its only problem is that it is a center-based strategy, so you only get convex clusters. Hierarchical algorithms avoid choosing K but pay a higher cost. And when you are looking for natural, non-convex, noisy clusters, density — in the form of DBSCAN — is another notion altogether, one that does not rely on distance as the main criterion.
Reading the table as a decision ladder:
- Data is blob-shaped and K is guessable, or speed matters? → K-means, , with the caveat of convex-only clusters and centroid sensitivity to noise.
- Need a hierarchy (taxonomy, nested groups) and can pay for it? → Agglomerative methods (linkage choice = shape assumption) or bisecting k-means; the dendrogram repays the / cost with K-free flexibility.
- Clusters are arbitrarily shaped, noisy, or of very different sizes? → DBSCAN, trading two tunable parameters (eps, minPts) for the ability to handle crescents, rings, and outliers — with the uniform-density caveat.
Each family answers the same question — "what is a cluster?" — with a different model: near a center, merged by a linkage rule, or connected through dense regions. No method is universally right; each one's assumption is its strength and its failure mode.
15.16.2 What Comes Next
The next topic of the course is an application of data mining techniques: malware detection. That is what the final session of the semester will discuss — a concrete case of the techniques from this and earlier units being turned on a real problem, and a reminder that every method studied so far (clustering included) exists to serve applied detection and decision tasks.
Exam note: everything covered until the last class is part of the comprehensive syllabus, so the material in this clustering unit — including the linkage methods and DBSCAN — is examinable. The complexity comparison above (k-means cheap but convex-only; hierarchical expensive but K-free; DBSCAN shape-free but density-uniform) is a classic summary question.
Recap of the whole unit: two ways to build a hierarchy (agglomerative and divisive), one reading tool (the dendrogram), five linkage rules (min, max, group average, centroid, Ward's), two complexity stories (O(n³)-class for agglomerative, log-factor for bisecting k-means), and one density-based alternative (DBSCAN) — each defined by what it assumes about the shape of a cluster.
Exam Guidance Summary
- Comprehensive syllabus: everything covered until the last class is part of the comprehensive syllabus. The clustering material in this unit — hierarchical clustering, the dendrogram, bisecting k-means, the linkage methods (min, max, group average, centroid, Ward's method), the MST-based divisive strategy, and DBSCAN — is examinable.
- DBSCAN homework: the homework on choosing eps and minPts is set for you to work out: make sure you can reason about how the two tunables affect the clustering, including the varying-density failure case (six natural clusters returning three). Recall the standard k-dist approach for the radius, and what happens when k is too small or too large.
- Centroid homework: the homework on the centroid strategy is to run it yourself on the four-point example: work the same dataset you saw with min and compare how the cluster shapes come out. Watch whether the merge order changes and whether the dendrogram stays monotone (inversions).
- Reading a dendrogram: be ready to read one — points on the X axis, distance on the Y axis, merge heights equal to merge distances, and clusters read off by cutting at any level. A horizontal cut at height h means "no cluster may contain points merged above distance h."
- Complexity comparisons: k-means is and cheap; hierarchical methods are costlier, roughly for agglomerative clustering with variants (heap-based), and bisecting k-means runs k-means times on a balanced binary tree. The proximity matrix alone costs to build and store.
- DBSCAN point categories: the distinction between core, border, and noise — and the notions of direct and indirect density reachability — are core conceptual points to explain precisely. Remember the neighborhood count includes the point itself.
- Vocabulary traps: max linkage defines inter-cluster distance through the two most dissimilar points, but merging always combines the two most similar clusters; and centroid linkage assumes convex clusters (which is why a centroid can sit in empty space for crescent-shaped data). Ward's method is the hierarchical analog of k-means' SSE objective.
- MST connection: the MST divisive strategy produces the same hierarchy as single-link (min) agglomerative clustering — a useful equivalence to be able to state.
Key Industry Applications
- Taxonomies and hierarchies: hierarchical clustering mirrors real-life taxonomies, such as the nested classifications used in biological science — species inside genera, genera inside families — so tree-based clustering is the natural model wherever the domain itself is hierarchical: biological taxonomy, file-system organization, phylogenetic trees, and organizational charts.
- Non-convex natural groups: when clusters in the data are non-convex (crescents, rings, elongated shapes), center-based methods like k-means fail to find the natural groups; density-based clustering like DBSCAN is the practical alternative — customer neighborhoods on city maps, galaxy surveys, and any spatially organized data with arbitrarily shaped regions.
- Noisy real data: real datasets contain noise, and DBSCAN's explicit outlier category labels noise instead of letting it shift cluster centers, which matters whenever data quality is imperfect. In anomaly-oriented fields (fraud detection, sensor fault detection), the labeled noise points are often the most valuable output — DBSCAN doubles as an outlier detector.
- Linkage choice is a judgment call: the choice of linkage method in practice is a judgment call — min, max, group average, centroid, or Ward's method — made according to the requirement and the problem definition, not fixed by any rule: clean elongated data favors min; noisy compact data favors max; balanced defaults use group average; variance-conscious compact clustering uses Ward's.
- Application unit: the course closes the clustering unit by moving to an applied topic, malware detection, as an example of a data mining application built on the techniques from this and earlier units — a reminder that clustering, classification, and evaluation methods exist to serve concrete detection and decision problems.
DM Lecture 15 notes · Hierarchical Clustering and Density-Based Clustering
Sections Breakdown
Why hierarchical clustering needs no K, and the agglomerative (merge up) versus divisive (split down) strategies with AGNES and DIANA.
Reading the merge history: points on the X axis, distance on the Y axis, and cutting the tree at any level.
Repeated 2-means splits, the O(log n times i times k times n times d) complexity, and the greedy local-optimum limitation.
The build-merge-update loop, matrix properties, the nine-point worked example, and what a horizontal cut returns.
Single link: the closest cross pair decides; worked numbers and the chaining sensitivity to noise.
Complete link: the farthest pair decides the ruler, while merging still chooses the most similar clusters.
UPGMA: averaging every cross-cluster point pair as the middle path between min and max.
Center-to-center distance, the convexity assumption, the four-point contrast with min, and continuous clustering.
SSE as a quality measure, the minimum-increment rule with its closed form, and the temporary-merge procedure.
O(n^3) naive versus O(n^2 log n) heap-based, and linkage choice as a subjective decision.
Building the MST, breaking the largest edge, and its equivalence to single-link agglomerative clustering.
Why distance fails on non-convex shapes, and how density (area plus minPts) becomes the alternative measure.
Eps and minPts, and the three point categories with the eps equals 1 cm, minPts equals 5 example.
Direct and indirect density reachability, and how clusters grow from chains of core points.
Noise resistance and arbitrary shapes, the varying-density failure, and the k-dist plot for choosing eps.
The full comparison table, the decision ladder, and the next topic: malware detection.
Exam strategy: comprehensive syllabus coverage, the two homework tasks, and vocabulary traps.
Taxonomies, non-convex and noisy real data, and linkage choice as a judgment call in practice.
Exam Revision Notes
Below is the distilled, exam-ready core. Every entry comes from the full explanation above. Use this section for rapid review; return to the main notes when a point needs more context.
Hierarchical Clustering: Two Strategies, No K
Must-know: Hierarchical clustering needs no K: build a tree (agglomerative = merge up; divisive = split down), then cut the tree at a level to get clusters. AGNES (bottom-up) and DIANA (top-down) are the classic pair.
âš ï¸ Top pitfall: Forgetting that each cut of the same tree yields a different clustering, and that both strategies produce nested clusters (a dendrogram).
Self-check: Which strategy starts with every point as its own cluster: agglomerative or divisive?
Connects to: 15.2
The Dendrogram
Must-know: Merge height equals merge distance: taller junction means the joined clusters were farther apart; cutting at height h means no cluster contains points merged above distance h.
âš ï¸ Top pitfall: Reading junction height as cluster size instead of merge distance; or trusting horizontal cuts when the linkage produces inversions (non-monotone heights).
Self-check: If a dendrogram's lowest junction is at height 0.11, what does 0.11 record?
Connects to: 15.4, 15.1
Bisecting K-Means (Divisive)
Must-know: Bisecting k-means: repeatedly split the biggest (or chosen) cluster with k-means, K = 2. Complexity = O(log n * i * k * n * d) on a balanced binary tree because tree height is log n. Greedy: once split, two clusters can never be re-merged even if very similar; it sees only local factors and never reaches the global optimum.
âš ï¸ Top pitfall: Believing bisecting k-means can recover clusters that cross split boundaries; it cannot, because splits are greedy and final (local optimum per cluster, never global).
Self-check: Why does bisecting k-means run k-means about log n times on a balanced binary tree?
Connects to: 15.16, 15.2
The Agglomerative Algorithm and the Proximity Matrix
Must-know: Agglomerative loop: compute proximity matrix -> merge closest pair -> update matrix -> repeat until one cluster. Matrix cell M[i][j] = d(p_i, p_j); symmetric, diagonal zero; only O(m) cells change per merge.
âš ï¸ Top pitfall: Recomputing the whole matrix after every merge, or forgetting that each merge is final — an early bad merge corrupts every level above it.
Self-check: When two clusters merge, which cells of the proximity matrix need updating?
Connects to: 15.5, 15.10
Min Linkage
Must-know: Min linkage: d(C1, C2) = min over all p in C1, q in C2 of d(p, q) — the closest cross pair decides. Also called single link. Merge order = sorted order of the smallest matrix entries. Sensitive to noise (chaining).
âš ï¸ Top pitfall: One noisy point bridging two clusters (chaining) — a single close pair hijacks the merge decision.
Self-check: Under min linkage, if the smallest entry of the proximity matrix is d(3,6) = 0.11, which clusters merge first and at what height?
Connects to: 15.6, 15.8
Max Linkage
Must-know: Max linkage: d(C1, C2) = max over all p in C1, q in C2 of d(p, q) — the farthest pair decides. Also called complete link. Merging still combines the most similar clusters (smallest max-distance). Different ruler -> different merge order; favors compact globular clusters; less susceptible to noise.
âš ï¸ Top pitfall: Thinking max linkage merges the most dissimilar clusters. It only defines the distance measure; the merge rule still chooses the most similar pair.
Self-check: Under max linkage, what is the distance from {3,6} to {2,5} if d(3,2)=0.15, d(6,2)=0.25, d(3,5)=0.28, d(6,5)=0.39?
Connects to: 15.5, 15.7
Group Average Linkage
Must-know: Group average: d(C1, C2) = (sum of all d(p, q) over p in C1, q in C2) / (|C1| * |C2|) — average over point pairs (UPGMA). Middle ground between min and max; every pair contributes; standard default when no reason to prefer the extremes.
âš ï¸ Top pitfall: Dividing by the number of points instead of the number of point pairs |C1| x |C2|.
Self-check: For clusters of size 3 and 2, how many pairwise distances are averaged by group average?
Connects to: 15.5, 15.6, 15.9
Centroid Linkage
Must-know: Centroid linkage: d(C1, C2) = ||mu1 - mu2||. Not arbitrary, but it assumes natural clusters are convex/circular; for crescents the centroid lies in empty space. Min on four points chains 12 -> 123 -> 1234 (continuous clustering); centroid is homework. Centroid can produce inversions (non-monotone dendrogram heights).
âš ï¸ Top pitfall: Applying centroid distance to non-convex clusters (crescents, rings) — the centroid falls outside the data; or reading an inverted dendrogram with horizontal cuts.
Self-check: Why does a centroid-based strategy fail when natural clusters are crescent-shaped?
Connects to: 15.5, 15.9
Ward's Method
Must-know: SSE(C) = sum over p in C of ||p - mu_C||^2; singletons have SSE 0 and SSE grows with merges (lower SSE = purer clusters). Ward's increment: Delta SSE = SSE(C1 U C2) - SSE(C1) - SSE(C2) = |C1||C2|/(|C1|+|C2|) * ||mu1 - mu2||^2. Merge the pair with the smallest increment. It is the hierarchical analog of k-means' SSE objective and resists chaining.
âš ï¸ Top pitfall: Forgetting that a pair of singletons costs half the squared distance (|C1|=|C2|=1), or expecting Ward to find elongated clusters — it inherits k-means' convex bias.
Self-check: On the four-point example, why did Ward's method merge {3,4} in round 2 while min linkage merged {1,2} with {3}?
Connects to: 15.8, 15.4
Complexity of Agglomerative Clustering
Must-know: Complexity: building the proximity matrix is O(n^2) (n(n-1)/2 pairs); each of the n-1 merges scans O(m^2) entries; the naive total is roughly O(n^3), and sorted-list/heap bookkeeping reaches O(n^2 log n); space O(n^2). Linkage choice (min, max, group average, Ward) is a subjective decision based on requirement and problem definition.
âš ï¸ Top pitfall: Quoting only the matrix build (O(n^2)) and forgetting the repeated minimum-finding that pushes the total to O(n^3).
Self-check: Why does the heap-based variant reduce the agglomerative complexity to O(n^2 log n)?
Connects to: 15.3, 15.16
A Divisive Strategy: Minimum Spanning Tree
Must-know: MST divisive clustering: (1) build the minimum spanning tree (n-1 edges, minimum total length, no cycles, O(n log n) with heap-based Prim/Kruskal); (2) repeatedly break the edge with the largest distance (smallest similarity) to create a new cluster; (3) stop at singletons. The hierarchy equals single-link (min) agglomerative clustering.
âš ï¸ Top pitfall: Cutting an arbitrary edge instead of the largest one, or forgetting that MST-based clustering is equivalent to single-link — and shares its noise sensitivity.
Self-check: Why is breaking the largest edge the right first cut in the MST strategy?
Connects to: 15.5, 15.1
DBSCAN: Why Density?
Must-know: Distance alone fails when natural clusters are non-convex (two crescents: k-means K=2 returns clusters that cut across both). Density needs two ingredients: the area (eps-radius circle) and the minimum number of points inside (minPts); a region is dense when the count is at least minPts. DBSCAN = Density-Based Spatial Clustering of Applications with Noise.
âš ï¸ Top pitfall: Applying k-means to non-convex groups and trusting the returned clusters; or defining density without both ingredients (area and threshold).
Self-check: Why can't k-means with K=2 separate two interlocking crescent-shaped natural clusters?
Connects to: 15.13, 15.16
DBSCAN: Core, Border, and Noise Points
Must-know: N_eps(p) = {q : d(p, q) <= eps} includes the point itself. p is core iff |N_eps(p)| >= minPts. Border: count below minPts but at least one core point in its eps-neighborhood. Noise: neither. Example: eps = 1 cm, minPts = 5; p1 with 5 points in its circle is core, p2 with 4 is border (core nearby), c is noise.
âš ï¸ Top pitfall: Forgetting that the eps-neighborhood count includes the point itself, so minPts = 5 means the point plus four others.
Self-check: With eps = 1 cm and minPts = 5, is a point with 4 points inside its circle a core point? What makes it a border point?
Connects to: 15.14, 15.15
DBSCAN: Building Clusters from Reachability
Must-know: Direct density reachable: A is directly reachable from B if B is a core point and d(A, B) <= eps (border points are exactly those reachable from a core point). Indirect density reachable: a sequential chain of core points connects A and B. Cluster = connected components of core points + attached border points; noise discarded. Growth: find a core point, expand through core neighbors, stop when nothing is reachable.
âš ï¸ Top pitfall: Treating reachability as symmetric — the first point in a direct step must be a core point; border points can be reached but cannot reach others.
Self-check: Why must every step of a density-reachability chain start from a core point?
Connects to: 15.13, 15.15
DBSCAN: Strengths and Failure Mode
Must-know: Strengths: noise resistant (dedicated outlier category; noise is labeled, never shifts centers) and handles arbitrary shapes/sizes. Failure: density not uniform — a dataset with six natural clusters returns three under a fixed eps and minPts, and retuning still cannot recover six. Assumption: one density scale for the whole dataset. Choosing eps/minPts (homework): k-dist plot — sorted k-th-nearest-neighbor distances with a sharp knee; knee value = eps, k = minPts.
âš ï¸ Top pitfall: Expecting DBSCAN to handle clusters of widely varying density with one global eps and minPts; or picking k too small (noise labeled as clusters) or too large (small clusters labeled as noise).
Self-check: Why does a fixed eps and minPts return three clusters instead of six when cluster densities vary?
Connects to: 15.13, 15.16
The Clustering Landscape: Complexity Recap
Must-know: Complexity table: k-means O(i*k*n*d) cheap but convex-only; bisecting k-means O(log n * i * k * n * d); agglomerative roughly O(n^3) with O(n^2 log n) variants; DBSCAN needs no K, two tunables (eps, minPts), any shape but uniform density. Everything up to the last class, including this unit, is in the comprehensive syllabus; the next topic is malware detection.
âš ï¸ Top pitfall: Claiming any single clustering algorithm is universally best — each family's assumption (convexity, linkage, uniform density) is its strength and its failure mode.
Self-check: Which algorithm family handles arbitrary cluster shapes and noise, and under what assumption does it fail?
Connects to: 15.3, 15.10, 15.15
Exam Guidance Summary
Must-know: Everything covered until the last class is in the comprehensive syllabus, including this clustering unit. Homework: (1) derive an approach for choosing eps and minPts (k-dist knee), including the varying-density failure; (2) run centroid linkage yourself on the four-point example and compare with min.
âš ï¸ Top pitfall: Max linkage merges the most similar clusters despite measuring distance with the most dissimilar pair; centroid linkage assumes convex clusters; the eps-neighborhood count includes the point itself.
Self-check: List the complexity of k-means, bisecting k-means, and naive agglomerative clustering.
Connects to: 15.1, 15.15, 15.8
Key Industry Applications
Must-know: Hierarchical clustering fits naturally hierarchical domains (biological taxonomy); DBSCAN handles non-convex shapes and labels noise instead of absorbing it (useful in anomaly/fraud detection); linkage choice is a problem-driven judgment call.
Self-check: In which real-world situation is DBSCAN preferred over k-means?
Connects to: 15.1, 15.12, 15.15
Was this lecture useful?
BitsNotes AI Assistant
Subject Notes AssistantConfigure AI Chat
Choose how to access the chatbotSigned in as
Powered by BitsNotes — 20 messages per day. No API key needed. Want unlimited access? Use "Bring Your Own Key" mode.
Sign in to use AI Chat
Get 20 free AI messages per day to ask questions about your lecture notes. Sign in with Google or GitHub — it takes 5 seconds.
Sign In to BitsNotesSwitch to "Bring Your Own Key" tab above for unlimited access with any OpenAI-compatible provider.