DBSCAN Walk-Through Example
Practice DBSCAN algorithm with a step-by-step walk-through example in this lesson.
Dry running an example
Let’s run DBSCANS on the following dataset shown in the graph:
Distance calculation
First, let’s choose the value of eps
and minPts
.
eps = 1.2
minPts = 2
Simple enough, let’s calculate the distance of all the points from each other. For the sake of ease, we’re going to calculate for
Euclidean Distance From (2, 1.5)
Data Points | Euclidean Distance From (2, 1.5) |
1, 2 | 1.118033989 |
2, 1 | 0.5 |
2, 1.5 | 0 |
2.5, 3.5 | 2.061552813 |
3, 4 | 2.692582404 |
4, 3.5 | 2.828427125 |
4, 7.5 | 6.32455532 |
5, 6 | 5.408326913 |
5, 7 | 6.264982043 |
5.5, 2 | 3.535533906 |
6, 1.5 | 4 |
6, 3 | 4.272001873 |
6, 5.5 | 5.656854249 |
6.5, 5 | 5.700877125 |
7, 2.5 | 5.099019514 |
1,8 | 6.57647322 |
Enter any data point from the above table as input using the format Px,Py
to the following program to get its Euclidean distance from all the data points:
# Importing required packagesfrom sklearn.metrics.pairwise import euclidean_distances as dis_scoreimport numpy as npx = np.array([1, 2, 2, 2.5, 3, 4, 4, 5, 5, 5.5, 6, 6, 6, 6.5, 7, 1])y = np.array([2, 1, 1.5, 3.5, 4, 3.5, 7.5, 6, 7, 2, 1.5, 3, 5.5, 5, 2.5, 8])data_points = [[x[i], y[i]] for i in range(len(x))]Pt = input()Px, Py = Pt.split(',')print(f"Dissimilarity scores for point ({Px}, {Py}):\n",dis_score(data_points, [[Px, Py]]))
Enter the input below
Identification of neighborhood points
Once we compute the Euclidean distance between the data point and all other data points, we can identify which data ...