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, norm_value: float | None = None, allow_nan: bool = False, 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 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[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.

  • 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[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)

  • norm_value (float | None)

  • allow_nan (bool)

  • sample_weights (ndarray[tuple[Any, ...], dtype[floating]] | None)

Return type:

float