### !! This algorithm is very slow, so we'll only test it on some datasets !!
### Helper function
test <- function(db, k) {
print(cl <- clustlearn::divisive_clustering(db, max_iterations = 5))
par(mfrow = c(1, 2))
plot(db, col = cutree(cl, k), asp = 1, pch = 20)
h <- rev(cl$height)[50]
clu <- as.hclust(cut(as.dendrogram(cl), h = h)$upper)
ctr <- unique(cutree(cl, k)[cl$order])
plot(clu, labels = FALSE, hang = -1, xlab = "Cluster", sub = "", main = "")
rect.hclust(clu, k = k, border = ctr)
}
### Example 1
# test(clustlearn::db1, 2)
### Example 2
# test(clustlearn::db2, 2)
### Example 3
# test(clustlearn::db3, 3)
### Example 4
# test(clustlearn::db4, 3)
### Example 5
test(clustlearn::db5, 3)
### Example 6
test(clustlearn::db6, 3)
### Example 7 (with explanations, no plots)
cl <- clustlearn::divisive_clustering(
clustlearn::db5[1:6, ],
details = TRUE,
waiting = FALSE
)
Run the code above in your browser using DataLab