### !! This algorithm is very slow, so we'll only test it on some datasets !!
### Helper function
test <- function(db, k) {
# Save old par settings
old_par <- par(no.readonly = TRUE)
# Ensure par settings are restored when function exits
on.exit(par(old_par))
print(cl <- 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(db1, 2)
### Example 2
# test(db2, 2)
### Example 3
# test(db3, 3)
### Example 4
# test(db4, 3)
### Example 5
test(db5, 3)
### Example 6
test(db6, 3)
### Example 7 (with explanations, no plots)
cl <- divisive_clustering(
db5[1:6, ],
learn = TRUE,
waiting = FALSE
)
Run the code above in your browser using DataLab