How to estimate eps using knn distance plot in DBSCAN
Asked Answered
D

2

6

I have the following code to estimate the eps for DBSCAN. If the code is fine then I have obtained the knn distance plot. The code is :

ns = 4
nbrs = NearestNeighbors(n_neighbors=ns).fit(data)
distances, indices = nbrs.kneighbors(data)
distanceDec = sorted(distances[:,ns-1], reverse=True)
plt.plot(indices[:,0], distanceDec)

Where data is the array of pixel locations (rows and columns). I have obtained a plot but I am not getting how do I determine the eps. According to DBSCAN paper,

the threshold point is the first point in the first valley of the sorted k-dist graph

I dont know how do I implement it in the code. Moreover, is ns = 4 is my minPts or is there any way to estimate minPts from eps?

Detrusion answered 28/12, 2017 at 15:41 Comment(0)
E
3

Use

plt.plot(list(range(1,noOfPointsYouHave+1)), distanceDec)

You'll get an elbow plot. The distance where you have a sharp change in curve is your epsilon.

You can also make reverse=False, if you wish.

Extol answered 3/2, 2018 at 5:50 Comment(0)
P
1

As far as I can tell, this is to be determined visually by a human.

Automation doesn't seem to work.

Or you can use OPTICS.

Presentiment answered 28/12, 2017 at 17:29 Comment(1)
You probably are looking at the n-1 nearest neigh or, as I assume your code will always return 0 as first distance. Also, your choice of x for the plot doesn't make sense to me.Presentiment

© 2022 - 2024 — McMap. All rights reserved.