# Label Ranking Average Precision Score

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

- Skill: `qhjqhj00/label-ranking-average-precision-score` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/label-ranking-average-precision-score`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/label-ranking-average-precision-score/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: qhjqhj00 (https://skillmd.com/u/qhjqhj00)
- Updated: 2026-09-08
- Page: https://skillmd.com/skills/qhjqhj00/label-ranking-average-precision-score

---


# label-ranking-average-precision-score

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

## When to invoke this skill

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

## Reference signature

```python
from sklearn.metrics import label_ranking_average_precision_score

# label_ranking_average_precision_score(y_true, y_score, *, sample_weight=None)
```

## Library docstring

```
Compute ranking-based average precision.

Label ranking average precision (LRAP) is the average over each ground
truth label assigned to each sample, of the ratio of true vs. total
labels with lower score.

This metric is used in multilabel ranking problem, where the goal
is to give better rank to the labels associated to each sample.

The obtained score is always strictly greater than 0 and
the best value is 1.

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

Parameters
----------
y_true : {array-like, sparse matrix} of shape (n_samples, n_labels)
    True binary labels in binary indicator format.

y_score : array-like of shape (n_samples, n_labels)
    Target scores, can either be probability estimates of the positive
    class, confidence values, or non-thresholded measure of decisions
    (as returned by "decision_function" on some classifiers).
    For :term:`decision_function` scores, values greater than or equal to
    zero should indicate the positive class.

sample_weight : array-like of shape (n_samples,), default=None
    Sample weights.

    .. versionadded:: 0.20

Returns
-------
score : float
    Ranking-based average precision score.

Examples
--------
>>> import numpy as np
>>> from sklearn.metrics import label_ranking_average_precision_score
>>> y_true = np.array([[1, 0, 0], [0, 0, 1]])
>>> y_score = np.array([[0.75, 0.5, 1], [1, 0.2, 0.1]])
>>> label_ranking_average_precision_score(y_true, y_score)
0.416
```

## Quick recipe

```python
import sklearn.metrics as _m
score = _m.label_ranking_average_precision_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)`.

