Skip to content

Evaluation, diagnostics, benchmarks, and additional tests · Evaluation, diagnostics, benchmarks, and additional hypothesis tests · EVA010 · Metric

Adjusted Rand index

Measures pairwise partition agreement corrected for chance under the fixed-marginal random-partition model.

Runs in CodeSplash Complete calculation CodeSplash's run and the reference's record

In CodeSplash

A CodeSplash method runs this entry in Python and R. Set it up from the method's page.

Do it in CodeSplash Run it on your own data, in Python or R.

Availability
Runs in CodeSplash
Code example
Complete calculation
Who ran it
CodeSplash's run and the reference's record
CodeSplash's run
Verified in Python and R through discover.choose_k, discover.gmm, discover.kmeans, discover.stability. The reference's example ran in Python and R here, and they agree.
The reference's record
Python: Ran in the reference's review. The report doesn't record which version of the code ran. R: Reviewed but not run: R wasn't available to the reference's authors.

Purpose

Measures pairwise partition agreement corrected for chance under the fixed-marginal random-partition model.

Question / hypotheses

How closely do two partitions agree, irrespective of their arbitrary label names?

Architecture / computational structure

A fixed scoring/calibration pipeline applied to model outputs or supplied observations; the formula and usage sections identify its operations.

Assumptions

Both partitions must refer to the same observations. Reference labels must represent the intended task rather than being assumed to be the only legitimate clustering.

Formula / computational definition

ARI=∑ij(nij2)−AB/(n2)(A+B)/2−AB/(n2),A=∑i(ai2), B=∑j(bj2).ARI=\frac{\sum_{ij}{n_{ij}\choose2}-A B/{n\choose2}}{(A+B)/2-A B/{n\choose2}},\quad A=\sum_i{a_i\choose2},\ B=\sum_j{b_j\choose2}.

Parameters and notation

n_ij are contingency counts; a_i,b_j are margins. There are no fitted weights. Noise treatment and the selected observation subset must be specified.

Fitting, fine-tuning, and adaptation

There is no model fine-tuning step for this evaluation procedure. Freeze the evaluated systems and evaluator before the final test. Select evaluation settings on development data; if a learned evaluator or calibration model is adapted, use separate fitting data, version it, and reassess its validity.

How to use and calibrate

Compute on independent reference annotations or repeated clustering fits. Report cluster sizes and the contingency table alongside the score.

Example application

Compare an unsupervised document partition with editorial labels without requiring matching numeric label IDs.

Interpretation / pitfalls

Watch out

ARI can be negative and is not a p-value. Agreement with one labeling may penalize alternative valid structure. Reusing labels for tuning makes a final external score optimistic.

Python and R code examples

Scope: Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

Validation: Python — Executed successfully on synthetic inputs. R — reviewed but not executed in this environment. Python dependencies are explicit imports; R uses base R unless a package/bridge is explicitly named.

Python and R

The reference's own programs, shown as written. A component demo shows one central piece of the method; it doesn't train a full model.

Python

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline. · needs sklearn

from sklearn.metrics import adjusted_rand_score
print(adjusted_rand_score([0,0,0,1,1,1],[1,1,0,0,0,0]))
R

Complete calculation — Mathematical calculation on synthetic inputs; not a complete benchmark pipeline.

a <- c(0,0,0,1,1,1); b <- c(1,1,0,0,0,0)
T <- table(a,b); c2 <- function(x) x*(x-1)/2
A <- sum(c2(rowSums(T))); B <- sum(c2(colSums(T))); expected <- A*B/c2(sum(T))
print((sum(c2(T))-expected)/((A+B)/2-expected))

Sources

From the CodeSplash reference, entry EVA010.