rmae#
- openstef_beam.metrics.rmae(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]], *, lower_quantile: float = 0.05, upper_quantile: float = 0.95, sample_weights: ndarray[tuple[Any, ...], dtype[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 the range of true values, making it scale-invariant and suitable for comparing errors across different datasets or time periods.
- Parameters:
y_true (ndarray[tuple[Any, ...], dtype[floating]]) – Ground truth values with shape (num_samples,).
y_pred (ndarray[tuple[Any, ...], dtype[floating]]) – Predicted values with shape (num_samples,).
lower_quantile (float) – Lower quantile for range calculation. Must be in [0, 1].
upper_quantile (float) – 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,). If None, all samples are weighted equally.
- Returns:
The relative Mean Absolute Error as a float. Returns NaN if the range between quantiles is zero.
- Return type:
float
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
- Parameters:
y_true (
ndarray[tuple[Any,...],dtype[floating]])y_pred (
ndarray[tuple[Any,...],dtype[floating]])lower_quantile (
float)upper_quantile (
float)sample_weights (
ndarray[tuple[Any,...],dtype[floating]] |None)
- Return type:
float