relative_pinball_loss#
- openstef_beam.metrics.relative_pinball_loss(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]], *, quantile: float, measurement_range_lower_q: float = 0.05, measurement_range_upper_q: float = 0.95, sample_weights: ndarray[tuple[Any, ...], dtype[floating]] | None = None) float[source]#
Calculate the relative Pinball Loss (also known as relative Quantile Loss).
The relative pinball loss normalizes the pinball loss by the range of true values, making it scale-invariant and suitable for comparing quantile prediction errors across different datasets or time periods. The pinball loss can be used to quantify the accuracy of a single quantile.
- Parameters:
y_true (ndarray[tuple[Any, ...], dtype[floating]]) – Ground truth values with shape (num_samples,).
y_pred (ndarray[tuple[Any, ...], dtype[floating]]) – Predicted quantile values with shape (num_samples,).
quantile (float) – The quantile level being predicted (e.g., 0.1, 0.5, 0.9). Must be in [0, 1].
measurement_range_lower_q (float) – Lower quantile for range calculation. Must be in [0, 1].
measurement_range_upper_q (float) – Upper quantile for range calculation. Must be in [0, 1] and greater than measurement_range_lower_q.
sample_weights (ndarray[tuple[Any, ...], dtype[floating]] | None) – Optional weights for each sample with shape (num_samples,). If None, all samples are weighted equally.
- Returns:
The relative Pinball Loss as a float. Returns NaN if the measurement range is zero.
- Return type:
float
Example
Basic usage for 10th percentile predictions:
>>> import numpy as np >>> y_true = np.array([100, 120, 110, 130, 105]) >>> y_pred = np.array([95, 115, 105, 125, 100]) # 10th percentile predictions >>> rpbl = relative_pinball_loss(y_true, y_pred, quantile=0.1, measurement_range_lower_q=0.0, ... measurement_range_upper_q=1.0) >>> round(rpbl, 4) 0.0167
- Parameters:
y_true (
ndarray[tuple[Any,...],dtype[floating]])y_pred (
ndarray[tuple[Any,...],dtype[floating]])quantile (
float)measurement_range_lower_q (
float)measurement_range_upper_q (
float)sample_weights (
ndarray[tuple[Any,...],dtype[floating]] |None)
- Return type:
float