edSlash Labs  /  Machine Learning Lab  /  Unsupervised Learning  /  DBSCAN Clustering
Algorithm 03 · Unsupervised learning · Clustering

DBSCAN Clustering

Learn how a computer finds groups by looking for dense areas of data. Unlike K-Means, DBSCAN does not ask you to choose the number of clusters first—and it can identify points that do not belong to any group.

Beginner friendly

The big idea

Dense areas become clusters. Isolated points can become noise.

DBSCAN = Density-Based ClusteringDensity-Based Spatial Clustering of Applications with Noise

DBSCAN looks around each data point. If enough points are close together, it can start or grow a cluster. Points in sparse areas may be marked as noise.

You control two settings: eps, the neighbourhood radius, and min_samples, the minimum number of nearby points needed to count an area as dense.

Three types of points

These roles decide how a cluster grows.

Core point

Has at least min_samples points in its eps neighbourhood, counting itself.

Border point

Has too few neighbours to be core, but lies inside a core point's neighbourhood.

Noise point

Is not reached by any cluster. It may be called an outlier.

Remember: DBSCAN discovers clusters from density. It does not need a preset number of clusters, and it can leave some points ungrouped.

1. How does DBSCAN work?

It checks neighbourhoods and grows a cluster from core points.

The process

Choose a point

Pick a point that has not been checked yet.

Look inside eps

Find all points within the chosen radius. This set is the point's neighbourhood.

Check min_samples

If the neighbourhood is large enough, the point is a core point and can start a cluster.

Grow the cluster

Add nearby points. Any new core points can bring in their own neighbours.

Mark noise

If a point is not part of a cluster after the search, it stays noise.

A simple way to picture it

Imagine people standing in a park. Draw a small circle around each person. If enough people are inside a circle, that person is in a crowded area. Nearby crowded areas can join to form one group.

Important: a border point can join a cluster even if it does not have enough neighbours to be a core point itself.

2. Live DBSCAN playground

Change eps and min_samples to see clusters, border points, and noise change.

Interactive experiment

Density map

Filled dots are core points, hollow dots are border points, and crosses are noise.

Core pointBorder pointNoise

The dashed circle shows the eps neighbourhood of the point currently being examined. Axes show two numerical features.

Clusters found—
Points checked0 / 0
Core points0
Noise points0
Choose “Next step” to examine the first point and its neighbourhood.
Try a small and a large eps. Then change min_samples. Watch how the number and shape of clusters change.

3. The mathematics behind DBSCAN

DBSCAN uses distance and a simple count of nearby points.

Distance between two points

For two points in a two-dimensional space, Euclidean distance is:

d = √((x₂ − x₁)² + (y₂ − y₁)²)

A point is in the eps neighbourhood when its distance from the centre point is less than or equal to eps.

Neighbourhood and core point

The eps-neighbourhood of point p contains all points no farther than eps from p.

|Neps(p)| ≥ min_samples

If the neighbourhood count reaches min_samples, p is a core point. The point p itself is included in the count.

How the two settings work together

SettingWhat it controlsIf you increase it
epsHow far DBSCAN looks around each point.More points can become neighbours; clusters may grow or join.
min_samplesHow many nearby points are needed for a dense area.It becomes harder to form a cluster; more points may be noise.
The best settings depend on the scale and density of your data. It is useful to test a few values and inspect the result.

4. Worked example: finding a busy area

Use a small set of points to understand the three point types.

Example points

Imagine these locations on a map. Let eps = 1.5 and min_samples = 3. The point itself counts as one neighbour.

PointXYNearby count
A1.01.03
B1.81.04
C1.21.83
D3.01.02
E8.58.51

What DBSCAN decides

Find the dense group

A, B, and C each have at least three points in their eps neighbourhood. They are core points and form a cluster.

Check point D

D has too few neighbours to be a core point, but it is close enough to a core point to join as a border point.

Check point E

E is far from the group and has too few neighbours. It is marked as noise.

A border point can belong to a cluster without being dense enough to grow that cluster. Noise is a point that DBSCAN cannot attach to any cluster.

5. How do we choose eps and min_samples?

These settings strongly affect the clusters DBSCAN discovers.

The k-distance idea

A common way to choose eps is to measure the distance to each point's k-th nearest neighbour, where k is often related to min_samples. Sort those distances and plot them. A bend in the curve can give a useful eps starting point.

Illustrative curve only. Always check the data and the result after choosing a value.

Practical tips

Scale your features

Distance is affected by feature size. Standardise features when their ranges differ a lot.

Try a few eps values

A very small radius can label many points as noise. A very large radius can join separate groups.

Choose min_samples carefully

A larger value asks for stronger local density before a cluster can grow.

Inspect the result

Check whether the groups make sense for the real problem.

eps too small

Neighbourhoods may be too tiny. Many points may be labelled as noise, and groups may split.

eps too large

Separate groups may join together. Even distant areas may become connected through chains of points.

6. DBSCAN in Python

Scikit-learn provides DBSCAN, which performs the neighbourhood search and cluster expansion.

Clustering with scikit-learn

Copy this example into a Python notebook.

# Install the libraries if needed:
# pip install numpy scikit-learn

import numpy as np
from sklearn.cluster import DBSCAN
from sklearn.preprocessing import StandardScaler

# Example data: two dense groups and a few isolated points
X = np.array([
    [1.0, 1.0], [1.2, 1.1], [0.9, 1.3],
    [1.3, 0.8], [1.5, 1.2],
    [7.0, 7.0], [7.2, 7.1], [6.8, 7.2],
    [7.3, 6.8], [7.1, 7.4],
    [4.5, 1.0], [9.0, 2.0]
])

# Scale features when their ranges are very different
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)

# Create and fit the DBSCAN model
model = DBSCAN(eps=0.7, min_samples=3)
labels = model.fit_predict(X_scaled)

# Cluster labels: -1 means noise
print("Cluster labels:", labels)
print("Clusters found:", len(set(labels) - {-1}))
print("Noise points:", np.sum(labels == -1))

# Core sample row indices
print("Core sample indices:", model.core_sample_indices_)

A label such as 0 or 1 identifies a cluster. A label of -1 means DBSCAN marked that row as noise.

Why scale the data? DBSCAN uses distance. A feature with much larger numbers can dominate the distance calculation. Scaling can help each feature contribute more fairly.

Useful Python terms

eps sets the neighbourhood radius. min_samples sets the density requirement. fit_predict() fits the model and returns labels. -1 marks noise. core_sample_indices_ gives the row indices of core points.

7. Where is DBSCAN used in real life?

It is useful when groups form dense areas and some points may be unusual.

Geographic hotspots

Find busy areas from location data, such as groups of reported events or service requests.

Outlier detection

Flag unusual records that do not sit near dense groups of similar records.

Image analysis

Group nearby image features or points when their positions form dense regions.

Movement patterns

Find common gathering areas or repeated location patterns from movement data.

Strengths and limitations

Know when DBSCAN is useful—and when it may struggle.

Strengths

  • You do not need to choose the number of clusters.
  • Can find curved and irregularly shaped groups.
  • Can identify noise and outliers.
  • Does not need starting cluster centres.

Limitations

  • Choosing eps can be difficult.
  • One eps value may not work well for groups with very different densities.
  • Distance becomes harder to interpret with many features.
  • Feature scaling can strongly affect the result.

DBSCAN vs K-Means

QuestionK-MeansDBSCAN
Choose cluster count first?Yes, choose K.No.
Find noise points?Not as part of its standard clustering result.Yes, labels them as -1.
Cluster shapeWorks best for compact groups.Can find irregular shapes.
Main settingsNumber of clusters K.eps and min_samples.

8. Knowledge check

Answer one question at a time. Your score and explanations will appear after the final question.

0 of 10 answered

Mini challenge

Use the playground. First increase eps, then increase min_samples. Can you explain why the number of clusters and noise points change?

Can DBSCAN find groups with curved shapes? Try the “Curved groups” dataset and see what happens.