rrmse#
- openstef_beam.metrics.metrics_deterministic.rrmse(y_true: NDArray[floating], y_pred: NDArray[floating], *, lower_quantile: Quantile = _Q_05, upper_quantile: Quantile = _Q_95, norm_value: float | None = None, allow_nan: bool = False, sample_weights: NDArray[floating] | None = None) float[source]#
Calculate the relative Root Mean Squared Error (rRMSE) using percentiles for range calculation.
The rRMSE normalizes the RMSE in the same way as
rmae()normalizes the MAE: by default by the range of true values between two quantiles, or by norm_value when it is provided. This makes it scale-invariant and comparable across targets.- Parameters:
y_true (
NDArray[floating]) – Ground truth values with shape (num_samples,).y_pred (
NDArray[floating]) – Predicted values with shape (num_samples,).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.norm_value (
float|None) – Optional pre-calculated normalization value. If provided, it will be used directly instead of calculating the range from quantiles.allow_nan (
bool) – If True, allows NaN values in y_true and y_pred, which will be ignored in the rRMSE calculation. If False, any NaN values will result in a NaN rRMSE.sample_weights (
NDArray[floating] |None) – Optional weights for each sample with shape (num_samples,). If None, all samples are weighted equally.
- Return type:
- Returns:
The relative Root Mean Squared Error as a float. Returns NaN if the range between quantiles is zero.
Example
Basic usage with energy load data
>>> import numpy as np >>> y_true = np.array([100, 120, 110, 130, 105]) >>> y_pred = np.array([98, 122, 108, 135, 107]) >>> error = rrmse(y_true, y_pred) >>> round(error, 3) 0.106