Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 580
Manish Sharma Avatar asked Dec 28 '17 15:12

Manish Sharma


2 Answers

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.

like image 117
screen grab Avatar answered Oct 12 '22 10:10

screen grab


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.

like image 44
Has QUIT--Anony-Mousse Avatar answered Oct 12 '22 11:10

Has QUIT--Anony-Mousse