++++
Data Science
May 2026×Notebook lesson

Notebook converted from Jupyter for blog publishing.

00-DBSCAN

Driptanil Datta
Driptanil DattaSoftware Developer

Introduction to DBSCAN

Let's briefly explore visually the differences between DBSCAN and other clustering techniques, such as K-Means Clustering.

DBSCAN and Clustering Examples

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
blobs = pd.read_csv('../DATA/cluster_blobs.csv')
blobs.head()
HTML
MORE
X1
X2
0
4.645333
6.822294
sns.scatterplot(data=blobs,x='X1',y='X2')
RESULT
<AxesSubplot:xlabel='X1', ylabel='X2'>
PLOT
Output 1
moons = pd.read_csv('../DATA/cluster_moons.csv')
moons.head()
HTML
MORE
X1
X2
0
0.674362
-0.444625
sns.scatterplot(data=moons,x='X1',y='X2')
RESULT
<AxesSubplot:xlabel='X1', ylabel='X2'>
PLOT
Output 2
circles = pd.read_csv('../DATA/cluster_circles.csv')
circles.head()
HTML
MORE
X1
X2
0
-0.348677
0.010157
sns.scatterplot(data=circles,x='X1',y='X2')
RESULT
<AxesSubplot:xlabel='X1', ylabel='X2'>
PLOT
Output 3

Label Discovery

def display_categories(model,data):
    labels = model.fit_predict(data)
    sns.scatterplot(data=data,x='X1',y='X2',hue=labels,palette='Set1')

Kmeans Results

from sklearn.cluster import KMeans
model = KMeans(n_clusters = 2)
display_categories(model,moons)
PLOT
Output 4
model = KMeans(n_clusters = 3)
display_categories(model,blobs)
PLOT
Output 5
model = KMeans(n_clusters = 2)
display_categories(model,circles)
PLOT
Output 6

DBSCAN Results

from sklearn.cluster import DBSCAN
model = DBSCAN(eps=0.6)
display_categories(model,blobs)
PLOT
Output 7
model = DBSCAN(eps=0.15)
plt.figure(figsize=(10,6),dpi=150)
display_categories(model,moons)
PLOT
Output 8
display_categories(model,circles)
PLOT
Output 9

Let's further explore DBSCAN Hyperparameters!

Drip

Driptanil Datta

Software Developer

Building full-stack systems, one commit at a time. This blog is a centralized learning archive for developers.

Legal Notes
Disclaimer

The content provided on this blog is for educational and informational purposes only. While I strive for accuracy, all information is provided "as is" without any warranties of completeness, reliability, or accuracy. Any action you take upon the information found on this website is strictly at your own risk.

Copyright & IP

Certain technical content, interview questions, and datasets are curated from external educational sources to provide a centralized learning resource. Respect for original authorship is maintained; no copyright infringement is intended. All trademarks, logos, and brand names are the property of their respective owners.

System Operational

© 2026 Driptanil Datta. All rights reserved.