Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scikit-Learn · Function

adjusted_rand_score

Computes the Rand similarity between two clusterings and corrects it for chance. It is symmetric, returns 1.0 for identical partitions up to label permutation, and is near 0.0 for random labelings.

How it works

The function compares two assignments by examining whether sample pairs are grouped together or separately in each labeling. It adjusts the resulting Rand similarity against its expected value for random labelings, producing a symmetric score that accounts for chance and ignores cluster-name permutations.

Syntax

sklearn.metrics.adjusted_rand_score(labels_true, labels_pred)

Parameters

NameTypeDescription
labels_truearray-like of shape (n_samples,)Ground truth class labels to be used as a reference.
labels_predarray-like of shape (n_samples,)Cluster labels to evaluate.

Returns

ARIfloat similarity score between -0.5 and 1.0. Random labelings have an ARI close to 0.0; 1.0 stands for a perfect match.

Key points

  • Use this metric to compare two cluster assignments while correcting the Rand index for agreement expected by chance.
  • A perfect partition match returns 1.0 even if cluster identifiers have been renamed.
  • Its random-label baseline is designed to stay near zero regardless of the dataset size or number of clusters.
  • Argument order does not affect the result, so the two label arrays are interchangeable.

Common mistakes

  • Although 1.0 indicates an exact match, strongly disagreeing clusterings can produce values down to -0.5.
  • A score near zero can represent chance-level agreement rather than complete disagreement.

Example: Evaluate a clustering

from sklearn.metrics import adjusted_rand_score

true_labels = [0, 0, 1, 1]
predicted_labels = [1, 1, 0, 0]

print(adjusted_rand_score(true_labels, predicted_labels))  # 1.0

Equivalent cluster IDs are treated as the same partition, so relabeling clusters does not reduce the score.

When to use it

External clustering evaluation

You have reference class assignments and want to assess an unsupervised clustering result.

Permutation-invariant comparison

Different algorithms or runs use different numeric cluster IDs for equivalent groups.

Chance-adjusted agreement

You need a chance-corrected score for comparing partitions with different cluster counts or sample sizes.

Interview questions

QHow does adjusted_rand_score differ from the ordinary Rand index?

It computes similarity between two clusterings from pairwise agreement: whether each sample pair is placed in the same or different cluster in both labelings. The raw Rand score is normalized against expected random agreement, giving the adjusted Rand index.

Follow-up: Why can the score be negative? Because adjustment subtracts expected random agreement, sufficiently discordant assignments can fall below zero, down to the documented lower bound of -0.5.

QIs adjusted_rand_score symmetric?

Yes. Swapping the two arguments leaves the result unchanged, so either labeling can be supplied first. This symmetry follows from comparing pairwise agreements between the two assignments.

Follow-up: Does cluster-ID renaming matter? No; identical partitions receive 1.0 even when their numeric cluster labels are permuted.

QWhat do the two parameters represent?

The inputs are two array-like label sequences with one label per sample: labels_true is the reference assignment and labels_pred is the clustering assignment being evaluated. The function returns a floating-point similarity score.

Follow-up: What score indicates chance-level agreement? Random labelings are expected to produce an ARI close to 0.0.

  • adjusted_mutual_info_score
  • rand_score

Source: adjusted_rand_score — scikit-learn 1.9.1 documentation. Checked 2026-10-15.