normalize_by_range#

openstef_beam.metrics.metrics_helpers.normalize_by_range(error: float, y_true: NDArray[floating], *, lower_quantile: Quantile, upper_quantile: Quantile, norm_value: float | None, allow_nan: bool) → float[source]#

Normalize an error by the range of the true values or by a given norm value.

Parameters:
  • error (float) – The error to normalize, e.g. a MAE or RMSE value.

  • y_true (NDArray[floating]) – Ground truth values with shape (num_samples,).

  • lower_quantile (Quantile) – Lower quantile of y_true for the range. Must be in [0, 1].

  • upper_quantile (Quantile) – Upper quantile of y_true for the range. Must be in [0, 1] and greater than lower_quantile.

  • norm_value (float | None) – Optional pre-calculated normalization value. If provided, it is used directly instead of the quantile range.

  • allow_nan (bool) – If True, NaN values in y_true are ignored when computing the range.

Return type:

float

Returns:

The normalized error as a float. Returns NaN if the error is NaN or the range is zero.