kmeans.getk: Estimation of the number of clusters for _K_-means

kmeans.getkR Documentation

Estimation of the number of clusters for K-means

Description

Estimate the optimal number of cluster of the K-means clustering method.

Usage

kmeans.getk(
  d,
  max = 9,
  criterion = c("pseudo-F", "silhouette", "gap", "elbow"),
  nstart = 10,
  B = 100,
  graph = FALSE,
  seed = NULL
)

Arguments

d

The dataset (matrix or data.frame).

max

The largest number of clusters considered. Values from 2 to max are evaluated (from 1, for "gap" and "elbow", which are defined there).

criterion

How the number of clusters is chosen: "none" (the default, use k as it is), "pseudo-F", "silhouette", "gap" or "elbow". With any but the first, k is read as the largest number of clusters to consider. See the Details section.

nstart

The number of random sets chosen for kmeans initialization.

B

The number of bootstrap samples used by criterion = "gap".

graph

A logical indicating whether or not a graphic should be plotted.

seed

A specified seed for random number generation.

Value

The number of clusters retained by the chosen criterion.

References

Tibshirani, R., Walther, G. and Hastie, T. (2001). Estimating the number of clusters in a data set via the gap statistic. Journal of the Royal Statistical Society: Series B, 63(2), 411-423.

See Also

pseudoF, KMEANS, kmeans, silhouette, clusGap

Examples

require (datasets)
data (iris)
kmeans.getk (iris [, -5])
kmeans.getk (iris [, -5], criterion = "silhouette")
kmeans.getk (iris [, -5], criterion = "elbow")

# The gap statistic resamples, so it is much slower than the other three.
kmeans.getk (iris [, -5], criterion = "gap", B = 20, seed = 0)


fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.