batchkmeans.default: K-means Clustering for vector data

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Performs K-means clustering on vector data.

Usage

1
2
3
## Default S3 method:
batchkmeans(data, ncenters, init = c("prototypes", "random", "cluster"),
prototypes, weights, max.iter, verbose = FALSE, keepdata = TRUE, ...)

Arguments

data

the data to cluster. This can be, a matrix or data frame of observations

ncenters

the number of clusters

init

the initialisation method ((see batchkmeans for details)

prototypes

Initial values for the prototypes (it must have the same number of columns as data and its row number must be equal to ncenters). If missing, initial prototypes are chosen via the method specified by the init parameter (see details)

weights

optional weights for the data points

max.iter

maximal number of iterations of the algorithm

verbose

switch for tracing the clustering process

keepdata

if TRUE, the original data are returned as part of the result object

...

not used

Details

This methods implements the standard (batch) K-means clustering algorithm (more precisely the Lloyd-Forgy algorithm).

Value

An object of class "batchkmeans" and of class "batchkmeansnum", a list with components including

prototypes

a matrix containing the coordinates of the prototypes

classif

a vector of integer indicating to which cluster each observation has been assigned

errors

a vector containing the evolution of the quantisation error during the fitting process

data

the original data if the function is called with keepdata = TRUE

weights

the weights of the data points if the function is called with keepdata = TRUE and if the weights is given

Author(s)

Fabrice Rossi

See Also

See batchsom for Self-Oganising Map which provides both clustering and visualisation and kmeans for the version provided by the stats package.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## inspired by the kmeans example in the stats package
require(graphics)

## 2 dimensional dataset
X <- cbind(rnorm(200,mean=2,sd=0.35),rnorm(200,mean=-1,sd=0.35))
Y <- cbind(runif(200,min=-1.5,max=-0.75),runif(200,min=0,max=0.5))
Z <- cbind(rnorm(200,sd=0.15),rnorm(200,sd=0.5))
M <- matrix(c(sin(pi/4),cos(pi/4),-cos(pi/4),sin(pi/4)),ncol=2)
U <- rbind(X,Y,Z%*%M+c(rep(0.25,200),rep(-0.5,200)))
U <- scale(U)

km <- batchkmeans(U,3)

plot(U,col=km$classif,cex=0.5)
points(km$prototypes,col=1:3,pch=20,cex=2)

yasomi documentation built on May 2, 2019, 5:59 p.m.