rmae#
- openstef_beam.metrics.rmae(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 Mean Absolute Error (rMAE) using percentiles for range calculation.
The rMAE normalizes the Mean Absolute Error by default by the range of true values, making it scale-invariant and suitable for comparing errors across different datasets or time periods. If norm_value is provided, it will be used directly for normalization instead of calculating the range from quantiles. This can be useful for consistent normalization across multiple evaluations.
- 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 rMAE calculation. If False, any NaN values will result in a NaN rMAE.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 Mean Absolute 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 = rmae(y_true, y_pred) >>> round(error, 3) 0.096
With custom quantiles and weights
>>> weights = np.array([1, 2, 1, 2, 1]) >>> error = rmae(y_true, y_pred, lower_quantile=0.1, ... upper_quantile=0.9, sample_weights=weights) >>> isinstance(error, float) True