kmeans
Syntax
kmeans(X, k, [maxIter=300], [randomSeed])
Arguments
X is a table. Each row is an observation and each column is a feature.
k is a positive integer indicating the number of clusters to form.
maxIter is a positive integer indicating the maximum number of iterations of the k-means algorithm for a single run. The default value is 300.
randomSeed is an integer indicating the seed in the random number generator.
Details
Solve the k-means problem. Return a dictionary with the following keys:
centers: a k*m (m is the number of columns of X) matrix. Each row is the coordinates of a cluster center.
modelName: string “KMeans”.
model: a RESOURCE data type variable. It is an internal binary resource generated by function
kmeans
to be used by function predict.labels: a vector indicating which cluster each row of X belongs to.
Examples
$ t = table(100:0, `x0`x1, [DOUBLE, DOUBLE])
$ x0 = norm(1.0, 1.0, 50)
$ x1 = norm(1.0, 1.5, 50)
$ insert into t values (x0, x1)
$ x0 = norm(2.0, 1.0, 50)
$ x1 = norm(-1.0, 1.5, 50)
$ insert into t values (x0, x1)
$ x0 = norm(-1.0, 1.0, 50)
$ x1 = norm(-3.0, 1.5, 50)
$ insert into t values (x0, x1);
$ model = kmeans(t, 3);
$ model;
centers->
#0 #1
--------- ---------
-1.048027 -3.809539
1.110899 1.24216
1.677974 -1.19158
modelName->KMeans
model->KMeans
labels->[2,2,2,2,2,2,3,2,3,2,...]