When you have ground-truth labels, you can compare a clustering with them. The raw Rand index counts pairs of points that agree (both together or both apart), but random clusterings already agree on many pairs, so the raw score looks high by chance. The adjusted Rand index corrects for that: 0 means chance-level agreement, 1 means identical partitions, and negative values mean worse than chance.
Implement adjusted_rand_index(labels_true, labels_pred).
ValueError.1.0.Open one at a time. Each gives away a little more than the last.
np.unique(..., return_inverse=True) turns arbitrary labels into contiguous indices, which makes the contingency table a single np.add.at call.
Use comb(x, 2) = x * (x - 1) / 2, which works on numpy arrays. The denominator becomes zero only for trivial partitions.
No results yet
Run your code to check it against the examples, or submit to run every test.