kMeansLloyd: K-Means Clustering

Description Usage Arguments Value References See Also Examples

View source: R/kMeansLloyd.R

Description

kMeansLloyd performs the k-means algorithm based on Lloyd's paper (1982) on a data matrix.

Usage

1
kMeansLloyd(x, centroids, maxIter = 10L, nStart = 1L)

Arguments

x

matrix or an object that can be coerced to a matrix (e.g. data.frame): contains the observations that are clustered. Note: x has to be numeric and does not contain missing values

centroids

integer (numeric) or matrix: If an integer, a random set of (distinct) rows in x is chosen as the intitial centres. If an appropriate matrix, the first row corresponds to the first initial cluster center. The provided integer or the number of rows of the provided matrix determines the number of clusters.

maxIter

integer (numeric): is the maximum number of iterations that is allowed.

nStart

integer (numeric): if centroids is a number, nStart determines the number of random sets that are chosen.

Value

kMeansLloyd returns an object of class kMeans. Methods implemented for class kMeans include: print, summary, plot and fitted.

An object of class kMeans is a list containing the following components:

cluster

a vector of integers indicating the cluster allocation of each point.

centroids

a matrix of cluster centroids.

iterations

the number of iterations.

groupSizes

the number of points in each cluster.

data

the data matrix.

withinSS

a vector of within-cluster sum of squares (one component per cluster).

withinTot

total within-cluster sum of squares (i.e. sum(withinss)).

References

Lloyd, S. P. (1957, 1982). Least squares quantization in PCM. Technical Note, Bell Laboratories. Published in 1982 in IEEE Transactions on Information Theory, 28, 128-137.

See Also

print.kMeans, summary.kMeans, plot.kMeans, fitted.kMeans

Examples

1
2
3
X <- rbind(matrix(rnorm(50, sd = 0.5), ncol = 2),
matrix(rnorm(50, mean = 1, sd = 0.5), ncol = 2))
result <- kMeansLloyd(x = X, centroids = 2, nStart = 2)

heiligerl/kMeans_Rpackage documentation built on Aug. 16, 2020, 4:04 p.m.