mae#

openstef_beam.metrics.mae(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]], *, sample_weights: ndarray[tuple[Any, ...], dtype[floating]] | None = None, allow_nan: bool = False) float[source]#

Calculate the Mean Absolute Error (MAE).

MAE measures the average magnitude of errors in a set of predictions, without considering their direction. It provides a straightforward interpretation of forecast accuracy in the same units as the data.

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,).

  • sample_weights (ndarray[tuple[Any, ...], dtype[floating]] | None) – Optional weights for each sample with shape (num_samples,). If None, all samples are weighted equally.

  • allow_nan (bool) – If True, allows NaN values in y_true and y_pred, which will be ignored in the MAE calculation. If False, any NaN values will result in a NaN MAE.

Returns:

The Mean Absolute Error as a float.

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, 132, 107]) >>> mae(y_true, y_pred) 2.0

Parameters:
  • y_true (ndarray[tuple[Any, ...], dtype[floating]])

  • y_pred (ndarray[tuple[Any, ...], dtype[floating]])

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

  • allow_nan (bool)

Return type:

float