How can we evaluate DBSCAN parameters? yes, DBSCAN parameters, and in particular the parameter eps (size of the epsilon neighborhood).
In the documentation we have a "Look for the knee in the plot".

Fine, but it requires a visual analysis. And it doesn't really work if we want to make things automatic.
So, I was wondering if it was possible to find a good eps in a few lines of code.

Let's imagine something like :


evaluate kNN distance  
sort these values
scale them (so that
the values are always between 0 and 1)
evaluate the derivative 
find the first point where derivative is higher than a certain
value, let's try with 1


In R, it would look like (using iris dataset as in the DBSCAN documentation) :

# evaluate kNN distance
dist &lt;- dbscan::kNNdist(iris, 4)

# order result
dist &lt;- dist[order(dist)]

# scale
dist &lt;- dist / max(dist)

# derivative
ddist &lt;- diff(dist) / ( 1 / length(dist))

# get first point where derivative is higher than 1
knee &lt;- dist[length(ddist)- length(ddist[ddist &gt; 1])]


and the result is 0.536 which looks quite good.


Is this approach relevant or totally nonsense ?
OPTICS gets rid of $\varepsilon$, you might want to have a look at it. Especially the reachability plot is a way to visualize what good choices of $\varepsilon$ in DBSCAN might be.

Wikipedia (article) illustrates it pretty well. The image on the top left shows the data points, the image on the bottom left is the reachability plot:



The $y$-axis are different values for $\varepsilon$, the valleys are the clusters. Each "bar" is for a single point, where the height of the bar is the minimal distance to the already printed points.