| cluster_kmeans | R Documentation |
k-means clustering using stats::kmeans.
cluster_kmeans(k = 1, nstart = 10)
k |
the number of clusters to form. |
nstart |
number of random initializations; the best (lowest within-cluster sum of squares) is kept. Default 10 for robust clustering (stats::kmeans uses 1). |
Partitions data into k clusters minimizing within‑cluster sum of squares. The intrinsic quality metric returned is the total within‑cluster SSE (lower is better).
The base clusterer() uses wcss as a generic default, but
cluster_kmeans() specializes that choice because k-means is usually
interpreted through compactness and separation between centroid-based groups.
Default evaluation in cluster_kmeans() is:
main metric: metric_silhouette()
internal evaluation: silhouette, davies_bouldin, calinski_harabasz
external evaluation: entropy, purity, adjusted_rand_index
The general wcss fallback is not kept as the main metric here because it
decreases mechanically as k grows and is therefore weaker as a standalone
quality criterion for comparing partitions.
returns a k-means object.
MacQueen, J. (1967). Some Methods for classification and Analysis of Multivariate Observations. Lloyd, S. (1982). Least squares quantization in PCM. Rousseeuw, P. J. (1987). Silhouettes: A graphical aid to the interpretation and validation of cluster analysis. Davies, D. L., & Bouldin, D. W. (1979). A cluster separation measure. Calinski, T., & Harabasz, J. (1974). A dendrite method for cluster analysis.
# setup clustering
model <- cluster_kmeans(k=3)
#load dataset
data(iris)
# build model
model <- fit(model, iris[,1:4])
clu <- cluster(model, iris[,1:4])
table(clu)
# evaluate model using external metric
eval <- evaluate(model, clu, iris$Species)
eval
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.