# Load a test dataset
data(Dataset_1)
x <- Dataset_1[, c("x", "y")]
class <- Dataset_1$class
clplot(x, class)
# We use MinPts 3 and use the knee at eps = .1 for dbscan
kNNdistplot(x, minPts = 3)
cl <- dbscan(x, eps = .1, minPts = 3)
clplot(x, cl)
dbcv(x, cl)
# compare to the DBCV index on the original class labels and
# with a random partitioning
dbcv(x, class)
dbcv(x, sample(1:4, replace = TRUE, size = nrow(x)))
# find the best eps using dbcv
eps_grid <- seq(.05,.2, by = .01)
cls <- lapply(eps_grid, FUN = function(e) dbscan(x, eps = e, minPts = 3))
dbcvs <- sapply(cls, FUN = function(cl) dbcv(x, cl)$score)
plot(eps_grid, dbcvs, type = "l")
eps_opt <- eps_grid[which.max(dbcvs)]
eps_opt
cl <- dbscan(x, eps = eps_opt, minPts = 3)
clplot(x, cl)
Run the code above in your browser using DataLab