Skip to content
Back to skills

Rand Score

ASecurity

Compute the rand_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute rand_score, or asks how to score with rand_score.

  • 3 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 11, 2026
documentationpython

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill rand-score --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rand Score?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rand Score
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-rand-score/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-rand-score)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rand-score
description: Compute the rand_score metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute rand_score, or asks how to score with rand_score.
metadata:
  skill_kind: metric
  source_lib: scikit-learn
  import_path: sklearn.metrics.rand_score
  source: library_introspection
---

# rand-score

> Metric `rand_score` from `scikit-learn` (sklearn.metrics.rand_score)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with rand_score, or
mentions `sklearn.metrics.rand_score` directly, or wants the standard scikit-learn implementation.

## Reference signature

```python
from sklearn.metrics import rand_score

# rand_score(labels_true, labels_pred)
```

## Library docstring

```
Rand index.

The Rand Index computes a similarity measure between two clusterings
by considering all pairs of samples and counting pairs that are
assigned in the same or different clusters in the predicted and
true clusterings [1]_ [2]_.

The raw RI score [3]_ is:

.. code-block:: text

    RI = (number of agreeing pairs) / (number of pairs)

Read more in the :ref:`User Guide <rand_score>`.

Parameters
----------
labels_true : array-like of shape (n_samples,), dtype=integral
    Ground truth class labels to be used as a reference.

labels_pred : array-like of shape (n_samples,), dtype=integral
    Cluster labels to evaluate.

Returns
-------
RI : float
   Similarity score between 0.0 and 1.0, inclusive, 1.0 stands for
   perfect match.

See Also
--------
adjusted_rand_score: Adjusted Rand Score.
adjusted_mutual_info_score: Adjusted Mutual Information.

References
----------
.. [1] :doi:`Hubert, L., Arabie, P. "Comparing partitions."
   Journal of Classification 2, 193–218 (1985).
   <10.1007/BF01908075>`.

.. [2] `Wikipedia: Simple Matching Coefficient
    <https://en.wikipedia.org/wiki/Simple_matching_coefficient>`_

.. [3] `Wikipedia: Rand Index <https://en.wikipedia.org/wiki/Rand_index>`_

Examples
--------
Perfectly matching labelings have a score of 1 even

  >>> from sklearn.metrics.cluster import rand_score
  >>> rand_score([0, 0, 1, 1], [1, 1, 0, 0])
  1.0

Labelings that assign all classes members to the same clusters
are complete but may not always be pure, hence penalized:

  >>> rand_score([0, 0, 1, 2], [0, 0, 1, 1])
  0.83
```

## Quick recipe

```python
import sklearn.metrics as _m
score = _m.rand_score(y_true, y_pred)
```

## Don'ts

- Don't reimplement when the library version handles edge cases (NaN, ties, empty inputs) better than a hand-rolled formula.
- Always check the library version's argument order — sklearn is `(y_true, y_pred)` while torchmetrics is `(preds, target)`.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.