# Hierarchical and Density-Based Clustering

> Agglomerative clustering with dendrograms, and DBSCAN / HDBSCAN for arbitrary shapes and automatic noise detection. Free notes, key concepts, resources and a...

Canonical: https://www.internhack.in/roadmaps/tracks/machine-learning/hierarchical-and-density-clustering
Last updated: 2026-11-28

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](https://www.internhack.in/roadmaps/tracks/machine-learning/k-means)

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) and `min_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](https://scikit-learn.org/stable/modules/clustering.html) (scikit-learn)
- [HDBSCAN documentation](https://hdbscan.readthedocs.io/en/latest/) (hdbscan)

Previous: [k-Means Clustering](https://www.internhack.in/roadmaps/tracks/machine-learning/k-means) · Next: [Principal Component Analysis](https://www.internhack.in/roadmaps/tracks/machine-learning/pca)

## More in Finding Structure Without Labels

- [k-Means Clustering](https://www.internhack.in/roadmaps/tracks/machine-learning/k-means)
- [Hierarchical and Density-Based Clustering](https://www.internhack.in/roadmaps/tracks/machine-learning/hierarchical-and-density-clustering)
- [Principal Component Analysis](https://www.internhack.in/roadmaps/tracks/machine-learning/pca)
- [t-SNE and UMAP for Visualization](https://www.internhack.in/roadmaps/tracks/machine-learning/tsne-umap)
- [Anomaly and Outlier Detection](https://www.internhack.in/roadmaps/tracks/machine-learning/anomaly-detection)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Machine Learning Engineer Roadmap](https://www.internhack.in/roadmaps/tracks/machine-learning)
