Learn R Programming

clusteval (version 0.1)

jaccard_indep: Computes the Jaccard similarity coefficient of two clusterings of the same data set under the assumption that the two clusterings are independent.

Description

For two clusterings of the same data set, this function calculates the Jaccard similarity coefficient of the clusterings from the comemberships of the observations. Basically, the comembership is defined as the pairs of observations that are clustered together.

Usage

jaccard_indep(labels1, labels2)

Arguments

Value

the Jaccard coefficient for the two sets of cluster labels (See Details.)

Details

To calculate the Rand index, we compute the 2x2 contingency table, consisting of the following four cells: [object Object],[object Object],[object Object],[object Object]

The Jaccard similarity coefficient is defined as: $$J = \frac{n_{11}}{n_{11} + n_{10} + n_{01}}$$.

In the special case that the Jaccard coefficient results in $0/0$, we define $J = 0$. For instance, this case can occur when both clusterings consist of all singleton clusters.

To compute the contingency table, we use the comembership_table function.

Examples

Run this code
# We generate K = 3 labels for each of n = 10 observations and compute the
# Jaccard similarity coefficient between the two clusterings.
set.seed(42)
K <- 3
n <- 10
labels1 <- sample.int(K, n, replace = TRUE)
labels2 <- sample.int(K, n, replace = TRUE)
jaccard_indep(labels1, labels2)

# Here, we cluster the \code{\link{iris}} data set with the K-means and
# hierarchical algorithms using the true number of clusters, K = 3.
# Then, we compute the Jaccard similarity coefficient between the two
# clusterings.
iris_kmeans <- kmeans(iris[, -5], centers = 3)$cluster
iris_hclust <- cutree(hclust(dist(iris[, -5])), k = 3)
jaccard_indep(iris_kmeans, iris_hclust)

Run the code above in your browser using DataLab