Description Usage Arguments Details Value Author(s) See Also Examples
Performs K-means clustering on vector data.
1 2 3 |
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 |
prototypes |
Initial values for the
prototypes (it must have the same number of columns as |
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 |
... |
not used |
This methods implements the standard (batch) K-means clustering algorithm (more precisely the Lloyd-Forgy algorithm).
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
|
weights |
the weights of the data points if the function is called with
|
Fabrice Rossi
See batchsom
for Self-Oganising Map which
provides both clustering and visualisation and kmeans
for the version provided by the stats
package.
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.