Skip to content
Back to skills

Mean Absolute Percentage Error

ASecurity

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

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

Security analysis

A100/100

Scanned September 11, 2026

npx -y skills add qhjqhj00/research-skills-pool --skill mean-absolute-percentage-error --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mean Absolute Percentage Error?

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

Security grade badge for Mean Absolute Percentage Error
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/qhjqhj00-mean-absolute-percentage-error/badge)](https://www.skillsdirectory.com/skills/qhjqhj00-mean-absolute-percentage-error)

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: mean-absolute-percentage-error
description: Compute the mean_absolute_percentage_error metric — provided by scikit-learn. Use when the user has predictions and ground-truth and needs to compute mean_absolute_percentage_error, or asks how to score with mean_absolute_percentage_error.
metadata:
  skill_kind: metric
  source_lib: scikit-learn
  import_path: sklearn.metrics.mean_absolute_percentage_error
  source: library_introspection
---

# mean-absolute-percentage-error

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

## When to invoke this skill

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

## Reference signature

```python
from sklearn.metrics import mean_absolute_percentage_error

# mean_absolute_percentage_error(y_true, y_pred, *, sample_weight=None, multioutput='uniform_average')
```

## Library docstring

```
Mean absolute percentage error (MAPE) regression loss.

Note that we are not using the common "percentage" definition: the percentage
in the range [0, 100] is converted to a relative value in the range [0, 1]
by dividing by 100. Thus, an error of 200% corresponds to a relative error of 2.

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

.. versionadded:: 0.24

Parameters
----------
y_true : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Ground truth (correct) target values.

y_pred : array-like of shape (n_samples,) or (n_samples, n_outputs)
    Estimated target values.

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

multioutput : {'raw_values', 'uniform_average'} or array-like
    Defines aggregating of multiple output values.
    Array-like value defines weights used to average errors.
    If input is list then the shape must be (n_outputs,).

    'raw_values' :
        Returns a full set of errors in case of multioutput input.

    'uniform_average' :
        Errors of all outputs are averaged with uniform weight.

Returns
-------
loss : float or ndarray of floats
    If multioutput is 'raw_values', then mean absolute percentage error
    is returned for each output separately.
    If multioutput is 'uniform_average' or an ndarray of weights, then the
    weighted average of all output errors is returned.

    MAPE output is non-negative floating point. The best value is 0.0.
    But note that bad predictions can lead to arbitrarily large
    MAPE values, especially if some `y_true` values are very close to zero.
    Note that we return a large value instead of `inf` when `y_true` is zero.

Examples
--------
>>> from sklearn.metrics import mean_absolute_percentage_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> mean_absolute_percentage_error(y_true, y_pred)
0.3273...
>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> mean_absolute_percentage_error(y_true, y_pred)
0.5515...
>>> mean_absolute_percentage_error(y_true, y_pred, multioutput=[0.3, 0.7])
0.6198...
>>> # the value when some element of the y_true is zero is arbitrarily high
```

## Quick recipe

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