Hierarchical and Density-Based Clustering
Agglomerative clustering with dendrograms, and DBSCAN / HDBSCAN for arbitrary shapes and automatic noise detection.
Intermediate · about 4 hours · difficulty 3/5
Learn first: k-Means Clustering
When clusters are not round blobs, or you do not know how many there are, other families often work better than k-means.
Hierarchical (agglomerative) clustering
- Start with every point as its own cluster and repeatedly merge the closest pair.
- Linkage decides what closest means: single, complete, average or Ward (minimizes variance, most k-means-like).
- A dendrogram shows the full merge tree; cut it at a height to choose the number of clusters.
- Quadratic memory cost limits it to tens of thousands of points.
DBSCAN and HDBSCAN
- Clusters are dense regions separated by sparse ones; points in sparse areas are labelled noise.
- DBSCAN needs
eps(neighbourhood radius) andmin_samples. A k-distance plot helps choose eps. - HDBSCAN removes the need for a single eps and handles varying density; often the better default.
- Finds arbitrary shapes and does not require k.
Tip
Clustering high-dimensional data directly is hard. Reduce dimensions first (PCA or UMAP), then cluster.
Good enough to move on when you can pick between k-means, agglomerative and HDBSCAN for a dataset and explain the choice.
Key concepts
- Agglomerative clustering
- Linkage criteria
- Dendrograms
- DBSCAN
- HDBSCAN
Mini project
Cluster GPS points of a public city dataset (for example NYC taxi pickup coordinates) with DBSCAN or HDBSCAN to find hotspots, and compare the result with k-means on a map scatter plot.
Check yourself
What does DBSCAN do with a point that is not within eps of enough neighbours, and why is that useful?
Free resources
- scikit-learn: Clustering (scikit-learn)
- HDBSCAN documentation (hdbscan)