Manish Sharma
Manish Sharma

Reputation: 79

How to estimate eps using knn distance plot in DBSCAN

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?

Upvotes: 6

Views: 8011

Answers (2)

screen grab
screen grab

Reputation: 31

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.

Upvotes: 3

Has QUIT--Anony-Mousse
Has QUIT--Anony-Mousse

Reputation: 77495

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.

Upvotes: 1

Related Questions