Learn R Programming

clusterCrit (version 1.2.8)

bestCriterion: Best clustering index

Description

bestCriterion returns the best index value according to a specified criterion.

Usage

bestCriterion(x, crit)

Arguments

x

[matrix] : a numeric vector of quality index values.

crit

[character] : a string specifying the name of the criterion which was used to compute the quality indices.

Value

The index in vector x of the best value according to the criterion specified by the crit argument.

Author

Bernard Desgraupes bernard.desgraupes@u-paris10.fr University of Paris Ouest - Nanterre Lab Modal'X (EA 3454)

Details

Given a vector of several clustering quality index values computed with a given criterion, the function bestCriterion returns the index of the "best" one in the sense of the specified criterion. Typically, a set of data has been clusterized several times (using different algorithms or specifying a different number of clusters) and a clustering index has been calculated each time : the bestCriterion function tells which value is considered the best according to the given clustering index. For instance, if one uses the Calinski_Harabasz index, the best value is the largest one.

A list of all the supported criteria can be obtained with the getCriteriaNames function. The criterion name (crit argument) is case insensitive and can be abbreviated.

See Also

getCriteriaNames, intCriteria.

Examples

Run this code
# NOT RUN {
# Create some spheric data around three distinct centers
x <- rbind(matrix(rnorm(100, mean = 0, sd = 0.5), ncol = 2),
           matrix(rnorm(100, mean = 2, sd = 0.5), ncol = 2),
           matrix(rnorm(100, mean = 4, sd = 0.5), ncol = 2))
vals <- vector()
for (k in 2:6) {
    # Perform the kmeans algorithm
    cl <- kmeans(x, k)
    # Compute the Calinski_Harabasz index
    vals <- c(vals,as.numeric(intCriteria(x,cl$cluster,"Calinski_Harabasz")))
}
idx <- bestCriterion(vals,"Calinski_Harabasz")
cat("Best index value is",vals[idx],"\n")
# }

Run the code above in your browser using DataLab