scoringrules.interval_score#
- scoringrules.interval_score(obs: ArrayLike, lower: ArrayLike, upper: ArrayLike, alpha: ArrayLike, *, backend: Backend = None) Array#
Compute the Interval Score or Winkler Score.
The interval score [(Gneiting & Raftery, 2012)](https://doi.org/10.1198/016214506000001437) is defined as
\[\begin{split}\text{IS} = \begin{cases} (u - l) + \frac{2}{\alpha}(l - y) & \text{for } y < l \\ (u - l) & \text{for } l \leq y \leq u \\ (u - l) + \frac{2}{\alpha}(y - u) & \text{for } y > u. \\ \end{cases}\end{split}\]for an \(1 - \alpha\) prediction interval of \([l, u]\) and the true value \(y\).
- Parameters:
- obsarray_like
The observations as a scalar or array of values.
- lowerarray_like
The predicted lower bound of the PI as a scalar or array of values.
- upperarray_like
The predicted upper bound of the PI as a scalar or array of values.
- alphaarray_like
The 1 - alpha level for the PI as a scalar or array of values.
- backendstr
The name of the backend used for computations. Defaults to ‘numba’ if available, else ‘numpy’.
- Returns:
- interval_scorearray_like
Array with the interval score for the input values.
- Raises:
- ValueError:
If the lower and upper bounds do not have the same shape or if the number of PIs does not match the number of alpha levels.
Notes
Given an obs array of shape (…,), in the case when multiple PIs are evaluated alpha is an array of shape (K,), then lower and upper must have shape (…,K) and the output will have shape (…,K).
Examples
>>> import numpy as np >>> import scoringrules as sr >>> sr.interval_score(0.1, 0.0, 0.4, 0.5) 0.4
>>> sr.interval_score( ... obs=np.array([0.1, 0.2, 0.3]), ... lower=np.array([0.0, 0.1, 0.2]), ... upper=np.array([0.4, 0.3, 0.5]), ... alpha=0.5, ... ) array([0.4, 0.2, 0.4])
>>> sr.interval_score( ... obs=np.random.uniform(size=(10,)), ... lower=np.ones((10,5)) * 0.2, ... upper=np.ones((10,5)) * 0.8, ... alpha=np.linspace(0.1, 0.9, 5), ... ).shape (10, 5)