Description Usage Arguments Value Examples
Silhouette index in [0,1]. Higher score means a good clustering.
1 | quality.sil(data, cluster)
|
data |
an (n\times p) matrix of row-stacked observations, or |
cluster |
a length-n vector of class labels (from 1:k). |
an index value.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # -------------------------------------------------------------
# clustering validity check with 3 Gaussians
# -------------------------------------------------------------
## PREPARE
X1 = matrix(rnorm(30*3, mean=-5), ncol=3)
X2 = matrix(rnorm(30*3), ncol=3)
X3 = matrix(rnorm(30*3, mean=5), ncol=3)
XX = rbind(X1, X2, X3)
## CLUSTERING WITH DIFFERENT K VALUES & COMPUTE QUALITY INDICES
vec_k = 2:10
vec_cl = rep(0, 9)
for (i in 1:length(vec_k)){
cl_now = T4cluster::kmeans(XX, k=vec_k[i])$cluster
vec_cl[i] = quality.sil(XX, cl_now)
}
## VISUALIZE
opar <- par(no.readonly=TRUE)
plot(vec_k, vec_cl, type="b", lty=2, xlab="number of clusteres",
ylab="score", main="Silhouette index")
abline(v=3, lwd=2, col="red")
par(opar)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.