rcrps#

openstef_beam.metrics.rcrps(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]], quantiles: list[Quantile], lower_quantile: Quantile = _Q_05, upper_quantile: Quantile = _Q_95, sample_weights: ndarray[tuple[Any, ...], dtype[floating]] | None = None, method: QuantileWeightingMethod = 'interval') float[source]#

Calculate the relative Continuous Ranked Probability Score (rCRPS).

The rCRPS normalizes the CRPS by the range of observed values, making it scale-invariant and suitable for comparing forecast quality across different datasets or time periods with varying magnitudes.

Parameters:
  • y_true (ndarray[tuple[Any, ...], dtype[floating]]) – Observed values with shape (num_samples,).

  • y_pred (ndarray[tuple[Any, ...], dtype[floating]]) – Predicted quantiles with shape (num_samples, num_quantiles).

  • quantiles (list[Quantile]) – Quantile levels with shape (num_quantiles,). Must be sorted in ascending order and contain values in [0, 1].

  • lower_quantile (Quantile) – Lower quantile for range calculation. Must be in [0, 1].

  • upper_quantile (Quantile) – Upper quantile for range calculation. Must be in [0, 1] and greater than lower_quantile.

  • sample_weights (ndarray[tuple[Any, ...], dtype[floating]] | None) – Optional weights for each sample with shape (num_samples,).

  • method (QuantileWeightingMethod) – Quantile weighting scheme to use, either “interval” (default) or “uniform”.

Returns:

The relative CRPS as a float. Returns NaN if the range between quantiles is zero.

Return type:

float

Example

Compare forecast quality across different scales

>>> import numpy as np
>>> # High load period
>>> y_true_high = np.array([1000, 1200, 1100])
>>> quantiles = np.array([0.1, 0.5, 0.9])
>>> y_pred_high = np.array([[950, 1000, 1050],
...                         [1150, 1200, 1250],
...                         [1050, 1100, 1150]])
>>> rcrps_high = rcrps(y_true_high, y_pred_high, quantiles)
>>> isinstance(rcrps_high, float)
True

Note

rCRPS allows fair comparison of forecast quality between periods with different load levels, such as summer vs. winter energy demand.

Parameters:
Return type:

float