Computes the Calinski-Harabasz and Davies-Bouldin indices, both of which
work from the data rather than a distance matrix, and both of which are used
the same way: fit at several values of k and compare.
Details
Calinski-Harabasz is between-cluster dispersion over within-cluster dispersion, each per degree of freedom. Higher is better.
Davies-Bouldin averages, over clusters, the worst-case ratio of combined within-cluster scatter to the distance between centroids. Lower is better.
Both assume roughly convex, centroid-shaped clusters, so they suit
shoal_kmeans() and shoal_gmm() better than the density-based algorithms.
For arbitrary cluster shapes prefer shoal_silhouette(), which needs only a
distance matrix.
Examples
fit <- shoal_kmeans(as.matrix(iris[, 1:4]), k = 3L)
shoal_metrics(fit)
#> n k calinski_harabasz davies_bouldin
#> 1 150 3 561.6278 0.6619715
# Comparing candidate values of k
do.call(rbind, lapply(2:5, function(k) {
shoal_metrics(shoal_kmeans(as.matrix(iris[, 1:4]), k = k))
}))
#> n k calinski_harabasz davies_bouldin
#> 1 150 2 513.9245 0.4042928
#> 2 150 3 561.6278 0.6619715
#> 3 150 4 530.4871 0.7757009
#> 4 150 5 495.5415 0.8059652
