Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

n_of_classes

Classes in a Partition


Description

Determine the number of classes and the class ids in a partition of objects.

Usage

n_of_classes(x)
cl_class_ids(x)
as.cl_class_ids(x)

Arguments

x

an object representing a (hard or soft) partition (for n_of_classes and cl_class_ids), or raw class ids (for as.cl_class_ids).

Details

These function are generic functions.

The methods provided in package clue handle the partitions obtained from clustering functions in the base R distribution, as well as packages RWeka, cba, cclust, cluster, e1071, flexclust, flexmix, kernlab, mclust, movMF and skmeans (and of course, clue itself).

Note that the number of classes is taken as the number of distinct class ids actually used in the partition, and may differ from the number of columns in a membership matrix representing the partition.

as.cl_class_ids can be used for coercing “raw” class ids (given as atomic vectors) to class id objects.

Value

For n_of_classes, an integer giving the number of classes in the partition.

For cl_class_ids, a vector of integers with the corresponding class ids. For soft partitions, the class ids returned are those of the nearest hard partition obtained by taking the class ids of the (first) maximal membership values.

See Also

Examples

data("Cassini")
party <- kmeans(Cassini$x, 3)
n_of_classes(party)
## A simple confusion matrix:
table(cl_class_ids(party), Cassini$classes)
## For an "oversize" membership matrix representation:
n_of_classes(cl_membership(party, 6))

clue

Cluster Ensembles

v0.3-59
GPL-2
Authors
Kurt Hornik [aut, cre] (<https://orcid.org/0000-0003-4198-9911>), Walter Böhm [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.