clustMixType (version 0.2-2)

silhouette_kproto: Validating k Prototypes Clustering: Silhouette index

Description

Calculating the Silhouette index for a k-Prototypes clustering with k clusters or computing the optimal number of clusters based on the Silhouette index for k-Prototype clustering.

Usage

silhouette_kproto(object = NULL, data = NULL, k = NULL, ...)

Arguments

object

Object of class kproto resulting from a call with kproto(..., keep.data=TRUE)

data

Original data; only required if object == NULL.

k

Vector specifying the search range for optimum number of clusters; if NULL the range will set as 2:sqrt(n). Only required if object == NULL.

...

Further arguments passed to kproto, like:

  • nstart: If > 1 repetetive computations of kproto with random initializations are computed.

  • lambda: Factor to trade off between Euclidean distance of numeric variables and simple matching coefficient between categorical variables.

  • verbose: Logical whether information about the cluster procedure should be given. Caution: If verbose=FALSE, the reduction of the number of clusters is not mentioned.

Value

For computing the optimal number of clusters based on the Silhouette index for k-Prototype clustering the output contains:

k_opt

optimal number of clusters

indices

calculated indices for \(k=2,...,k_{max}\)

For computing the Silhouette index-value for a given k-Prototype clustering the output contains:

index

calculated index-value

Details

$$Silhouette = \frac{1}{n} \sum_{i=1}^n \frac{b(i)-a(i)}{max(a(i),b(i))}$$ \(a(i)\) is the average dissimilarity of the ith object to all other objects of the same/own cluster. \(b(i)=min(d(i,C))\), where \(d(i,C)\) is the average dissimilarity of the ith object to all the other clusters except the own/same cluster. The maximum value of the index is used to indicate the optimal number of clusters.

References

See Also

Other clustervalidation indices: dunn_kproto, dunn_kproto, gamma_kproto, gplus_kproto, mcclain_kproto, ptbiserial_kproto, tau_kproto

Examples

Run this code
# NOT RUN {
# generate toy data with factors and numerics

n   <- 10
prb <- 0.99
muk <- 2.5

x1 <- sample(c("A","B"), 2*n, replace = TRUE, prob = c(prb, 1-prb))
x1 <- c(x1, sample(c("A","B"), 2*n, replace = TRUE, prob = c(1-prb, prb)))
x1 <- as.factor(x1)

x2 <- sample(c("A","B"), 2*n, replace = TRUE, prob = c(prb, 1-prb))
x2 <- c(x2, sample(c("A","B"), 2*n, replace = TRUE, prob = c(1-prb, prb)))
x2 <- as.factor(x2)

x3 <- c(rnorm(n, mean = -muk), rnorm(n, mean = muk), rnorm(n, mean = -muk), rnorm(n, mean = muk))
x4 <- c(rnorm(n, mean = -muk), rnorm(n, mean = muk), rnorm(n, mean = -muk), rnorm(n, mean = muk))

x <- data.frame(x1,x2,x3,x4)

# apply k prototyps
kpres <- kproto(x, 4, keep.data=TRUE)

# calculate index-value
silhouette_value <- silhouette_kproto(object = kpres)

# calculate optimal number of cluster
k_opt <- silhouette_kproto(data = x, k = 3:5, nstart = 5, verbose = FALSE)

# }

Run the code above in your browser using DataCamp Workspace