# Median Absolute Error

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

- Skill: `qhjqhj00/median-absolute-error` (Agent Skill)
- Install (CLI): `npx skillmds add qhjqhj00/median-absolute-error`
- Raw SKILL.md: https://api.skillmd.com/api/skills/qhjqhj00/median-absolute-error/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/median-absolute-error

---


# median-absolute-error

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

## When to invoke this skill

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

## Reference signature

```python
from sklearn.metrics import median_absolute_error

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

## Library docstring

```
Median absolute error regression loss.

Median absolute error output is non-negative floating point. The best value
is 0.0. Read more in the :ref:`User Guide <median_absolute_error>`.

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.

multioutput : {'raw_values', 'uniform_average'} or array-like of shape             (n_outputs,), default='uniform_average'
    Defines aggregating of multiple output values. Array-like value defines
    weights used to average errors.

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

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

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

    .. versionadded:: 0.24

Returns
-------
loss : float or ndarray of floats
    If multioutput is 'raw_values', then mean absolute 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.

Examples
--------
>>> from sklearn.metrics import median_absolute_error
>>> y_true = [3, -0.5, 2, 7]
>>> y_pred = [2.5, 0.0, 2, 8]
>>> median_absolute_error(y_true, y_pred)
0.5
>>> y_true = [[0.5, 1], [-1, 1], [7, -6]]
>>> y_pred = [[0, 2], [-1, 2], [8, -5]]
>>> median_absolute_error(y_true, y_pred)
0.75
>>> median_absolute_error(y_true, y_pred, multioutput='raw_values')
array([0.5, 1. ])
>>> median_absolute_error(y_true, y_pred, multioutput=[0.3, 0.7])
0.85
```

## Quick recipe

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

