adjusted_mutual_info_score#

cuml.metrics.cluster.adjusted_mutual_info_score(
labels_true,
labels_pred,
*,
average_method='arithmetic',
) → float[source]#

Adjusted Mutual Information between two clusterings.

Adjusted Mutual Information (AMI) is an adjustment of the Mutual Information (MI) score to account for chance. It accounts for the fact that the MI is generally higher for two clusterings with a larger number of clusters, regardless of whether there is actually more information shared. For two clusterings \(U\) and \(V\), the AMI is given as:

AMI(U, V) = [MI(U, V) - E(MI(U, V))] / [avg(H(U), H(V)) - E(MI(U, V))]

Here, H is entropy, E(MI) is the expected mutual information under random reassignment preserving both partitions’ cluster sizes, and avg is the mean selected by average_method.

This metric is independent of the absolute values of the labels: a permutation of the class or cluster label values won’t change the score value in any way.

This metric is furthermore symmetric: switching \(U\) (label_true) with \(V\) (labels_pred) will return the same score value. This can be useful to measure the agreement of two independent label assignment strategies on the same dataset when the real ground truth is not known.

Parameters:
labels_truearray-like (device or host) of shape (n_samples,)

One-dimensional integer labels assigning samples to disjoint subsets. Accepts lists, NumPy or CuPy arrays, pandas or cuDF Series, and one-dimensional arrays implementing the CUDA array interface.

labels_predarray-like (device or host) of shape (n_samples,)

One-dimensional integer labels assigning samples to disjoint subsets. Accepts lists, NumPy or CuPy arrays, pandas or cuDF Series, and one-dimensional arrays implementing the CUDA array interface.

average_method{‘min’, ‘geometric’, ‘arithmetic’, ‘max’}, default=’arithmetic’

How to compute the normalizer in the denominator.

Returns:
float

The AMI returns a value of 1 when the two partitions are identical (i.e. perfectly matched). Random partitions (independent labellings) have an expected AMI around 0 on average hence can be negative. The score is dimensionless. See Notes for cases with undefined normalization.

See also

adjusted_rand_score

Adjusted Rand Index.

mutual_info_score

Mutual Information (not adjusted for chance).

Notes

Special cases are handled as follows:

  • Identical partitions return 1.0, including two empty partitions, two single-cluster partitions, or two partitions where every sample is in its own cluster (all singletons).

  • A single-cluster partition compared with a multi-cluster partition returns 0.0.

  • If exactly one partition is all singletons and the other contains more than one cluster, the result is NaN for average_method='min' and 0.0 for the other averaging methods. The 'min' normalization is 0 / 0 in this case.

Examples

>>> import cupy as cp
>>> from cuml.metrics.cluster import adjusted_mutual_info_score
>>> labels_true = cp.asarray([0, 0, 1, 1])
>>> labels_pred = cp.asarray([1, 1, 0, 0])
>>> adjusted_mutual_info_score(labels_true, labels_pred)
1.0
>>> labels_pred = cp.asarray([0, 0, 1, 2])
>>> score = adjusted_mutual_info_score(labels_true, labels_pred)
>>> print(f"{score:.4f}")
0.5714