pinball_loss#
- openstef_beam.metrics.metrics_deterministic.pinball_loss(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]], *, quantile: Quantile, sample_weights: ndarray[tuple[Any, ...], dtype[floating]] | None = None) float[source]#
Calculate the Pinball Loss (also known as Quantile Loss) for a single quantile.
The Pinball Loss is a scoring rule for a single quantile forecast that penalizes under- and over-predictions differently based on the quantile level.
- 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 (Quantile) – The quantile level being predicted (e.g., 0.1, 0.5, 0.9). Must be in [0, 1].
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 average Pinball Loss as a float. Lower is better.
- Return type:
Example
Basic usage for 10th percentile predictions
>>> import numpy as np >>> y_true = np.array([100, 120, 110]) >>> y_pred = np.array([95, 116, 111]) >>> pinball_loss(y_true, y_pred, quantile=0.1) 0.6