Skip to content
Back to skills

Multilabelaverageprecision

ASecurity

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

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

Security analysis

A100/100

Scanned September 11, 2026

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

Installs into .claude/skills of the current project.

Are you the author of Multilabelaverageprecision?

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

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

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: multilabelaverageprecision
description: Compute the MultilabelAveragePrecision metric — provided by torchmetrics. Use when the user has predictions and ground-truth and needs to compute MultilabelAveragePrecision, or asks how to score with MultilabelAveragePrecision.
metadata:
  skill_kind: metric
  source_lib: torchmetrics
  import_path: torchmetrics.classification.MultilabelAveragePrecision
  source: library_introspection
---

# multilabelaverageprecision

> Metric `MultilabelAveragePrecision` from `torchmetrics` (torchmetrics.classification.MultilabelAveragePrecision)

## When to invoke this skill

The user has predictions + ground truth and asks to evaluate with MultilabelAveragePrecision, or
mentions `torchmetrics.classification.MultilabelAveragePrecision` directly, or wants the standard torchmetrics implementation.

## Reference signature

```python
from torchmetrics.classification import MultilabelAveragePrecision

# MultilabelAveragePrecision(num_labels: int, average: Optional[Literal['micro', 'macro', 'weighted', 'none']] = 'macro', thresholds: Union[int, list[float], torch.Tensor, NoneType] = None, ignore_index: Optional[int] = None, validate_args: bool = True, **kwargs: Any) -> None
```

## Library docstring

```
Compute the average precision (AP) score for multilabel tasks.

The AP score summarizes a precision-recall curve as an weighted mean of precisions at each threshold, with the
difference in recall from the previous threshold as weight:

.. math::
    AP = \sum_{n} (R_n - R_{n-1}) P_n

where :math:`P_n, R_n` is the respective precision and recall at threshold index :math:`n`. This value is
equivalent to the area under the precision-recall curve (AUPRC).

As input to ``forward`` and ``update`` the metric accepts the following input:

- ``preds`` (:class:`~torch.Tensor`): A float tensor of shape ``(N, C, ...)`` containing probabilities or logits
  for each observation. If preds has values outside [0,1] range we consider the input to be logits and will auto
  apply sigmoid per element.
- ``target`` (:class:`~torch.Tensor`): An int tensor of shape ``(N, C, ...)`` containing ground truth labels, and
  therefore only contain {0,1} values (except if `ignore_index` is specified).

As output to ``forward`` and ``compute`` the metric returns the following output:

- ``mlap`` (:class:`~torch.Tensor`): If `average=None|"none"` then a 1d tensor of shape (n_classes, ) will be
  returned with AP score per class. If `average="micro|macro"|"weighted"` then a single scalar is returned.

Additional dimension ``...`` will be flattened into the batch dimension.

The implementation both supports calculating the metric in a non-binned but accurate version and a binned
version that is less accurate but more memory efficient. Setting the `thresholds` argument to `None` will activate
the non-binned  version that uses memory of size :math:`\mathcal{O}(n_{samples})` whereas setting the
`thresholds` argument to either an integer, list or a 1d tensor will use a binned version that uses memory of
size :math:`\mathcal{O}(n_{thresholds} \times n_{labels})` (constant memory).

Args:
    num_labels: Integer specifying the number of labels
    average:
        Defines the reduction that is applied over labels. Should be one of the following:

        - ``micro``: Sum score over all labels
        - ``macro``: Calculate score for each label and average them
        - ``weighted``: calculates score fo
```

## Quick recipe

```python
import torchmetrics.classification as _m
score = _m.MultilabelAveragePrecision(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.