Learn R Programming

bootkmeans (version 1.0.0)

compare.clusters: Compare traditional \(k\)-means, bootstrap augmented \(k\)-means, and fuzzy \(c\)-means

Description

Fits three clustering procedures on the same data: standard kmeans, our bootstrap augmented \(k\)-means algorithm boot.kmeans, and (optionally) fuzzy \(c\)-means from FKM. Returns the fitted objects of all three whose object can be passed into compare.clusters to compare side-by-side confusion matrices.

Usage

compare.clusters( data = NULL,
                  groups = NULL,
                  seed = 13462,
                  nstart = 50,
                  what = "all")

Value

A named list with components:

km

kmeans fit object.

bkm

"BSKMeans" object returned by boot.kmeans.

fkm

(Only if what == "all") fclust fuzzy \(c\)-means fit.

what

Echo of the what argument.

Arguments

data

Numeric matrix or data frame of row observations and column variables. Required.

groups

Number of clusters \(K\). Required.

seed

Optional integer random seed for reproducibility.

nstart

Number of random starts for initialization for all methods.

what

Character flag; if "all" (default), include fuzzy \(c\)-means (FKM) in the output.

Details

The function runs the following algorithms:

  • km: stats::kmeans(data, centers = groups, nstart = nstart).

  • bkm: boot.kmeans(data, groups, nstart = nstart, returnall = FALSE).

  • fkm (if what == "all"): fclust::FKM(data, k = groups, RS = nstart).

References

Ghashti, J.S., Andrews, J.L., Thompson, J.R.J., Epp, J. and H.S. Kochar (2025). A bootstrap augmented \(k\)-means algorithm for fuzzy partitions. Submitted.

Bezdek, J.C. (1981). Pattern recognition with fuzzy objective function algorithms. New York: Plenum.

Hartigan, J.A. and M.A. Wong (1979). Algorithm AS 136: A K-means clustering algorithm. Applied Statistics, 28, 100–108.

Ferraro, M.B., Giordani P. and A. Serafini (2019). fclust: An R Package for Fuzzy Clustering, The R Journal, 11.

See Also

boot.kmeans, compare.tables, bootk.hardsoftvis, kmeans, FKM

Examples

Run this code
set.seed(1)
x <- as.matrix(iris[, -5])

# compare all three methods
res <- compare.clusters(x, groups = 3, nstart = 10, what = "all")

# hard clusters from bootstrap kmeans
table(res$bkm$clusters, iris$Species)

# fuzzy memberships from fuzzy \eqn{c}-means
head(res$fkm$U)

# compare class labels
cbind(res$bkm$clusters[1:5], res$fkm$clus[1:5,2], res$km$cluster[1:5])

Run the code above in your browser using DataLab