Learn R Programming

GFORCE (version 0.1.4)

gforce.kmeans: K-means Clustering.

Description

Solves the K-means problem using kmeans++ for the initialization and then runs Lloyd's algorithm.

Usage

gforce.kmeans(X, K, R_only = FALSE)

Arguments

X

\(n x m\) matrix. Each row is treated as a point in \(R^m\).

K

integer. The number of clusters to group the data into.

R_only

logical expression. If R_only == FALSE, then the included native code implementation will be used. Otherwise, an R implementation is used.

Value

Returns an object with the components:

clusters

a \(n\) dimensional integer vector. Entry \(i\) to the cluster assignment of the data point given by row \(i\) of X.

centers

a \(K x m\) numeric matrix. Row \(i\) corresponds to the center of cluster \(i\).

num_iters

an integer. Number of iterations of Lloyd's Algorithm.

time

a numeric. Runtime of Lloyd's Algorithm.

References

S.P. Lloyd. Least Squares Quantization in PCM. IEEE Transactions on Information Theory, 1982.

D. Arthur and S. Vassilvitskii. k-means++: The Advantages of Careful Seeding. SODA, 2007.

Examples

Run this code
# NOT RUN {
m <- 10 
n <- 10
X <- matrix(MASS::mvrnorm(m*n,rep(0,m*n),diag(m*n)), nrow = n)
km_res <- gforce.kmeans(X,3)

# }

Run the code above in your browser using DataLab