Learn R Programming

bootkmeans (version 1.0.0)

compare.tables: Contingency tables comparing true labels to fitted clusterings

Description

Given the output of compare.clusters and a vector of true class labels, prints confusion tables for: (i) hard \(k\)-means labels, (ii) the bootstrap augmented \(k\)-means MAP out-of-bag labels, and (optionally) (iii) fuzzy \(c\)-means hard labels.

Usage

compare.tables(full.res = NULL, true.labs = NULL, verbose = TRUE)

Value

A list with components:

kmeans

A contingency table comparing true labels to \(k\)-means cluster assignments.

bootkmeans

A contingency table comparing true labels to boot\(k\)means cluster assignments.

fuzzcmeans

(Optional) A contingency table comparing true labels to fuzzy \(c\)-means cluster assignments, included only if full.res$what == "all".

If verbose = TRUE, the tables are also printed to the console.

Arguments

full.res

A list returned by compare.clusters, containing components km, bkm, and fkm (the latter only if argument what = "all" in function compare.clusters).

true.labs

A vector of true class labels.

verbose

Logical; if TRUE, prints the contingency tables to the console. Default is TRUE.

Details

For \(k\)-means, hard labels are taken from full.res$km$cluster. For bootstrap \(k\)-means, labels are taken from full.res$bkm$clusters. If full.res$what == "all" results are also taken from full.res$fkm$clus, which are the hard cluster assignments from the fuzzy \(c\)-means algorithm.

The function prints two or three contingency tables to the console, with three presented if compare.clusters has argument what = "all", and two otherwise.

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.clusters, bootk.hardsoftvis, kmeans, FKM

Examples

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

# fit three methods (kmeans, bootstrap kmeans, fuzzy \eqn{c}-means)
res <- compare.clusters(x, groups = 3, nstart = 10, what = "all")

# compare contigency tables
compare.tables(res, true.labs = iris$Species)

Run the code above in your browser using DataLab