mape#

openstef_beam.metrics.mape(y_true: ndarray[tuple[Any, ...], dtype[floating]], y_pred: ndarray[tuple[Any, ...], dtype[floating]]) float[source]#

Calculate the Mean Absolute Percentage Error (MAPE).

MAPE measures the average magnitude of errors in percentage terms, making it scale-independent and easily interpretable. However, it can be undefined or inflated when true values are near zero.

Parameters:
  • y_true (ndarray[tuple[Any, ...], dtype[floating]]) – Ground truth values with shape (num_samples,). Should not contain values close to zero to avoid division issues.

  • y_pred (ndarray[tuple[Any, ...], dtype[floating]]) – Predicted values with shape (num_samples,).

Returns:

The Mean Absolute Percentage Error as a float. May return inf or extremely large values if y_true contains values close to 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 = mape(y_true, y_pred)
>>> round(error, 4)
0.0225

With perfect predictions:

>>> perfect_pred = np.array([100, 120, 110, 130, 105])
>>> mape(y_true, perfect_pred)
0.0
Parameters:
  • y_true (ndarray[tuple[Any, ...], dtype[floating]])

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

Return type:

float