Learn R Programming

FuzzySpec (version 1.0.0)

clustering.accuracy: Clustering Accuracy with Optimal Label Matching

Description

Computes the fraction of correctly classified observations between two label vectors after optimally matching cluster labels using Thresher::matchLabels.

Usage

clustering.accuracy(A, B)

Value

A single numeric value in \([0, 1]\): the accuracy after optimal label matching.

Arguments

A

An integer or character vector of cluster labels of length \(n\).

B

An integer or character vector of cluster labels of length \(n\).

Details

The function creates the contingency table table(A, B), permutes columns to best align labels using matchLabels, and returns the sum of the diagonal divided by \(n\).

Inputs must have equal length and the same number of unique labels; otherwise an error is given.

References

K. R. Coombes (2025). Thresher: Threshing and Reaping for Principal Components. R package version 1.1.5.

See Also

fuzzy.spectral.clustering, gen.fuzzy, plot.fuzzy, matchLabels

Examples

Run this code
set.seed(1)
n <- 200
k <- 3
A <- sample.int(k, n, replace = TRUE) # assumed true clustering labels
perm <- sample.int(k) # assumed predicted labels (sampled by permutating)
B <- perm[A]
flips <- sample.int(n, 20) # add some error a few errors
B[flips] <- sample.int(k, length(flips), replace = TRUE)

clustering.accuracy(A, B)

Run the code above in your browser using DataLab