module neuralforecast.losses.numpy
function mae
y and y_hat. MAE measures the relative prediction accuracy of a forecasting method by calculating the deviation of the prediction and the true value at a given time and averages these devations over the length of the series.
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: MAE.
function mse
y and y_hat. MSE measures the relative prediction accuracy of a forecasting method by calculating the squared deviation of the prediction and the true value at a given time, and averages these devations over the length of the series.
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: MSE.
function rmse
y and y_hat. RMSE measures the relative prediction accuracy of a forecasting method by calculating the squared deviation of the prediction and the observed value at a given time and averages these devations over the length of the series. Finally the RMSE will be in the same scale as the original time series so its comparison with other series is possible only if they share a common scale. RMSE has a direct connection to the L2 norm.
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: RMSE.
function mape
y and y_hat. MAPE measures the relative prediction accuracy of a forecasting method by calculating the percentual deviation of the prediction and the observed value at a given time and averages these devations over the length of the series. The closer to zero an observed value is, the higher penalty MAPE loss assigns to the corresponding error.
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: MAPE.
function smape
y and y_hat. SMAPE measures the relative prediction accuracy of a forecasting method by calculating the relative deviation of the prediction and the observed value scaled by the sum of the absolute values for the prediction and observed value at a given time, then averages these devations over the length of the series. This allows the SMAPE to have bounds between 0% and 200% which is desirable compared to normal MAPE that may be undetermined when the target is zero.
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: SMAPE.
function mase
y and y_hat. MASE measures the relative prediction accuracy of a forecasting method by comparinng the mean absolute errors of the prediction and the observed value against the mean absolute errors of the seasonal naive model. The MASE partially composed the Overall Weighted Average (OWA), used in the M4 Competition.
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.y_insample(np.ndarray): Actual insample Seasonal Naive predictions.seasonality(int): Main frequency of the time series; Hourly 24, Daily 7, Weekly 52, Monthly 12, Quarterly 4, Yearly 1.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: MASE.
- Rob J. Hyndman, & Koehler, A. B. “Another look at measures of forecast accuracy”.
- Spyros Makridakis, Evangelos Spiliotis, Vassilios Assimakopoulos, “The M4 Competition: 100,000 time series and 61 forecasting methods”.
function rmae
y(np.ndarray): observed values.y_hat1(np.ndarray): Predicted values of first model.y_hat2(np.ndarray): Predicted values of baseline model.weights(np.ndarray, optional): Weights for weighted average. Defaults to None.axis(Optional[int], optional): Axis or axes along which to average a. Defaults to None. The default, axis=None, will average over all of the elements of the input array.
float: RMAE.
function quantile_loss
y and y_hat. QL measures the deviation of a quantile forecast. By weighting the absolute deviation in a non symmetric way, the loss pays more attention to under or over estimation. A common value for q is 0.5 for the deviation from the median (Pinball loss).
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.q(float, optional): The slope of the quantile loss, in the context of quantile regression, the q determines the conditional quantile level. Defaults to 0.5.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: Quantile loss.
function mqloss
y and y_hat. MQL calculates the average multi-quantile Loss for a given set of quantiles, based on the absolute difference between predicted quantiles and observed values.
The limit behavior of MQL allows to measure the accuracy of a full predictive distribution with the continuous ranked probability score (CRPS). This can be achieved through a numerical integration technique, that discretizes the quantiles and treats the CRPS integral with a left Riemann approximation, averaging over uniformly distanced quantiles.
Args:
y(np.ndarray): Actual values.y_hat(np.ndarray): Predicted values.quantiles(np.ndarray): Quantiles to estimate from the distribution of y.mask(np.ndarray, optional): Specifies date stamps per serie to consider in loss. Defaults to None.
float: MQLoss.

