# NOT RUN {
data(iris)
iris <- as.matrix(iris[,1:4])
## Find the 4-NN distance for each observation (see ?kNN
## for different search strategies)
kNNdist(iris, k = 4)
## Get a matrix with distances to the 1st, 2nd, ..., 4th NN.
kNNdist(iris, k = 4, all = TRUE)
## Produce a k-NN distance plot to determine a suitable eps for
## DBSCAN with MinPts = 5. Use k = 4 (= MinPts -1).
## The knee is visible around a distance of .7
kNNdistplot(iris, k = 4)
cl <- dbscan(iris, eps = .7, minPts = 5)
pairs(iris, col = cl$cluster+1L)
## Note: black points are noise points
# }
Run the code above in your browser using DataLab