Learn R Programming

fpc (version 1.2-2)

kmeansruns: k-means clustering with several random initializations

Description

This calls the function kmeans to perform a k-means clustering, but initializes the k-means algorithm several times with random points from the data set as means. Furthermore, it is more robust against the occurrence of empty clusters in the algorithm.

Usage

kmeansruns(data,k,iter.max=100,runs=100,scaledata=FALSE,plot=FALSE)

Arguments

data
A numeric matrix of data, or an object that can be coerced to such a matrix (such as a numeric vector or a data frame with all numeric columns).
k
integer. The number of clusters.
iter.max
integer. The maximum number of iterations allowed.
runs
integer. Number of starts of the k-means algorithm.
scaledata
logical. If TRUE, the variables are centered and scaled to unit variance before execution.
plot
logical. If TRUE, every clustering resulting from a run of the algorithm is plotted.

Value

  • The output of the optimal run of the kmeans-function. A list with components
  • clusterA vector of integers indicating the cluster to which each point is allocated.
  • centersA matrix of cluster centers.
  • withinssThe within-cluster sum of squares for each cluster.
  • sizeThe number of points in each cluster.

See Also

kmeans

Examples

Run this code
set.seed(20000)
  face <- rFace(50,dMoNo=2,dNoEy=0,p=2)
  kmr1 <- kmeansruns(face,k=5,runs=1)
  kmr5 <- kmeansruns(face,k=5,runs=5)

Run the code above in your browser using DataLab