Skip to content

Quantile score

scoringrules.quantile_score

quantile_score(
    obs: ArrayLike,
    fct: ArrayLike,
    alpha: ArrayLike,
    backend: Backend | None = None,
) -> Array

Compute the quantile score for a given quantile level.

The quantile score (Koenker, R. and G. Bassett, 1978) is defined as

\[ S_{\alpha}(q_{\alpha}, y) = \begin{cases} (1 - \alpha) (q_{\alpha} - y), & \text{if } y \leq q_{\alpha}, \\ \alpha (y - q_{\alpha}), & \text{if } y > q_{\alpha}. \end{cases} \]

where \(y\) is the observed value and \(q_{\alpha}\) is the predicted value at the \(\alpha\) quantile level.

Parameters:

Name Type Description Default
obs ArrayLike

The observed values.

required
fct ArrayLike

The forecast values.

required
alpha ArrayLike

The quantile level.

required

Returns:

Name Type Description
score Array

The quantile score.

Examples:

>>> import scoringrules as sr
>>> sr.quantile_score(0.3, 0.5, 0.2)
0.16

Raises:

Type Description
ValueError

If the quantile level is not between 0 and 1.