Machine Learning, FoundationsLesson 65 of 92

Module 7 · Learning without labels, and learning a representation

DBSCAN and hierarchical clustering: when shape and structure matter

In this lesson

  • 8 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 3 of 10 in this chapter

This chapter’s goalCluster a dataset and defend the number of clusters with more than an elbow plot, reduce dimensionality with PCA and state how much information the reduction discarded, explain what an embedding is as a geometric object, and build a working nearest-neighbour search over pretrained embeddings without a GPU.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmWatch1:55Not available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

DBSCAN: clusters as dense regions

k-means asks which centre a point is nearest. DBSCAN asks a different question: is this point in a crowded neighbourhood?

Two parameters define the answer. eps is a radius. min_samples is how many points must be within that radius for a point to count as a core point. Core points that are within eps of each other join into one cluster. Points near a cluster but not themselves core are border points, and points in neither category are labelled noise, with cluster id -1.

Python
from sklearn.cluster import DBSCAN
labels = DBSCAN(eps=0.5, min_samples=5).fit_predict(X_scaled)
(labels == -1).sum()      # how many were called noise

Three consequences follow directly, and they are exactly the things k-means could not do.

Clusters can be any shape. Two interleaved crescents, a ring around a blob, a long winding band: DBSCAN follows density, so shape is irrelevant. k-means cannot find any of them.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the How a Language Model Actually Works exam.

Stuck on something?Ask Funke, your AI tutor

How to cite: Addaly (2026) ‘DBSCAN and hierarchical clustering: when shape and structure matter’, in Machine Learning, Foundations. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/machine-learning-foundations/density-and-hierarchy (Accessed: 29 November 2026).