# NOT RUN {
## cluster the moons data set with HDBSCAN
data(moons)
res <- hdbscan(moons, minPts = 5)
res
plot(res)
plot(moons, col = res$cluster + 1L)
## cluster the moons data set with HDBSCAN using Manhattan distances
res <- hdbscan(dist(moons, method = "manhattan"), minPts = 5)
plot(res)
plot(moons, col = res$cluster + 1L)
## DS3 from Chameleon
data("DS3")
res <- hdbscan(DS3, minPts = 50)
res
## Plot the simplified tree, highlight the most stable clusters
plot(res, show_flat = TRUE)
## Plot the actual clusters (noise has cluster id 0 and is shown in black)
plot(DS3, col = res$cluster + 1L, cex = .5)
## Predict cluster for new data points.
newdata <- data.frame(
X = runif(n = 10, min(DS3[, 1]), max(DS3[, 1])),
Y = runif(n = 10, min(DS3[, 2]), max(DS3[, 2]))
)
plot(DS3, col = res$cluster + 1L, pch = ".")
points(newdata, col = "red", pch = 4, lwd = 2)
pred_label <- predict(res, newdata, data = DS3)
pred_label
points(newdata, col = pred_label + 1L, pch = 1, lwd = 2, cex = 2)
# }
Run the code above in your browser using DataLab