computeKmeans: K-means clustering

View source: R/sampleCompute.R

computeKmeansR Documentation

K-means clustering

Description

Perform K-means clustering, dealing with the number of clusters K, automatically or not.

Usage

computeKmeans(x, K = 0, K.max = 20, kmeans.variance.min = 0.95, graph = FALSE)

Arguments

x

matrix of raw data (point by line).

K

number of clusters. If K=0 (default), this number is automatically computed thanks to the Elbow method.

K.max

maximal number of clusters (K.Max=20 by default).

kmeans.variance.min

elbow method cumulative explained variance > criteria to stop K-search.

graph

boolean: if TRUE, figures for total of within-class inertia and explained variance are plotted.

Details

computeKmeans performs K-means clustering, dealing with the number of clusters K, automatically or not

Value

res.kmeans results obtained from kmeans algorithm.

See Also

computeUnSupervised, computeEM

Examples

dat <- rbind(matrix(rnorm(100, mean = 0, sd = 0.3), ncol = 2), 
             matrix(rnorm(100, mean = 2, sd = 0.3), ncol = 2), 
             matrix(rnorm(100, mean = 4, sd = 0.3), ncol = 2))
tf <- tempfile()
write.table(dat, tf, sep=",", dec=".")

x <- importSample(file.features=tf)
res.kmeans <- computeKmeans(x$features$initial$x, K=0, graph=TRUE)
plot(dat[,1], dat[,2], type = "p", xlab = "x", ylab = "y", 
col = res.kmeans$cluster, main = "K-means clustering")




RclusTool documentation built on May 29, 2024, 5:23 a.m.