Last data update: 2014.03.03
|
R: KmeansAutoElbow function
KmeansAutoElbow | R Documentation |
KmeansAutoElbow function
Description
KmeansAutoElbow performs k-means clustering on a dataframe with selection of optimal number of clusters using elbow criteria.
Usage
KmeansAutoElbow(features, Kmax, StopCriteria = 0.99, graph = FALSE)
Arguments
features |
dataframe or matrix of raw data.
|
Kmax |
maximum number of clusters allowed.
|
StopCriteria |
elbow method cumulative explained variance > criteria to stop K-search. (???)
|
graph |
boolean, if TRUE figures are plotted.
|
Details
KmeansAutoElbow returns partition and K number of groups according to kmeans clustering and Elbow method
Value
The function returns a list containing the following components:
K |
number of clusters in data according to explained variance and kmeans algorithm.
|
res.kmeans |
an object of class "kmeans" (see kmeans ) containing classification results.
|
See Also
kmeans
Examples
x <- rbind(matrix(rnorm(300, mean = 0, sd = 0.3), ncol = 2),
matrix(rnorm(100, mean = 2, sd = 0.3), ncol = 2),
matrix(rnorm(100, mean = 4, sd = 0.3), ncol = 2))
colnames(x) <- c("x", "y")
km<-KmeansAutoElbow(x,round(dim(x)/25,0)[1],StopCriteria=0.99,graph=TRUE)
plot(x,col=km$res.kmeans$cluster)
points(km$res.kmeans$centers, col = 1:km$K, pch = 16)
Results
|