Losses
Loss functions for model evaluation.
The most important train signal is the forecast error, which is the difference between the observed value and the prediction , at time :
The train loss summarizes the forecast errors in different evaluation metrics.
1. Scale-dependent Errors
Mean Absolute Error (MAE)
source
mae
*Mean Absolute Error (MAE)
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.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actual values and predictions. | |
models | List | Columns that identify the models predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Mean Squared Error
source
mse
*Mean Squared Error (MSE)
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.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actual values and predictions. | |
models | List | Columns that identify the models predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Root Mean Squared Error
source
rmse
*Root Mean Squared Error (RMSE)
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.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actual values and predictions. | |
models | List | Columns that identify the models predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
source
bias
*Forecast estimator bias.
Defined as prediction - actual*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actual values and predictions. | |
models | List | Columns that identify the models predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
2. Percentage Errors
Mean Absolute Percentage Error
source
mape
*Mean Absolute Percentage Error (MAPE)
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.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actual values and predictions. | |
models | List | Columns that identify the models predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Symmetric Mean Absolute Percentage Error
source
smape
*Symmetric Mean Absolute Percentage Error (SMAPE)
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 100% which is desirable compared to normal MAPE that may be undetermined when the target is zero.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actual values and predictions. | |
models | List | Columns that identify the models predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
3. Scale-independent Errors
Mean Absolute Scaled Error
source
mase
*Mean Absolute Scaled Error (MASE)
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.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actuals and predictions. | |
models | List | Columns that identify the models predictions. | |
seasonality | int | Main frequency of the time series; Hourly 24, Daily 7, Weekly 52, Monthly 12, Quarterly 4, Yearly 1. | |
train_df | DFType | Training dataframe with id and actual values. Must be sorted by time. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Relative Mean Absolute Error
source
rmae
*Relative Mean Absolute Error (RMAE)
Calculates the RAME between two sets of forecasts (from two different forecasting methods). A number smaller than one implies that the forecast in the numerator is better than the forecast in the denominator.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, times, actuals and predictions. | |
models | List | Columns that identify the models predictions. | |
baseline | str | Column that identifies the baseline model predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Mean Squared Scaled Error
source
msse
*Mean Squared Scaled Error (MSSE)
MSSE measures the relative prediction accuracy of a forecasting method by comparinng the mean squared errors of the prediction and the observed value against the mean squared errors of the seasonal naive model.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actuals and predictions. | |
models | List | Columns that identify the models predictions. | |
seasonality | int | Main frequency of the time series; Hourly 24, Daily 7, Weekly 52, Monthly 12, Quarterly 4, Yearly 1. | |
train_df | DFType | Training dataframe with id and actual values. Must be sorted by time. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Root Mean Squared Scaled Error
source
rmsse
*Root Mean Squared Scaled Error (RMSSE)
MSSE measures the relative prediction accuracy of a forecasting method by comparinng the mean squared errors of the prediction and the observed value against the mean squared errors of the seasonal naive model.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, actuals and predictions. | |
models | List | Columns that identify the models predictions. | |
seasonality | int | Main frequency of the time series; Hourly 24, Daily 7, Weekly 52, Monthly 12, Quarterly 4, Yearly 1. | |
train_df | DFType | Training dataframe with id and actual values. Must be sorted by time. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
4. Probabilistic Errors
Quantile Loss
source
quantile_loss
*Quantile Loss (QL)
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.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, times, actuals and predictions. | |
models | Dict | Mapping from model name to the model predictions for the specified quantile. | |
q | float | 0.5 | Quantile for the predictions’ comparison. |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Multi-Quantile Loss
source
mqloss
*Multi-Quantile loss (MQL)
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.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, times, actuals and predictions. | |
models | Dict | Mapping from model name to the model predictions for each quantile. | |
quantiles | ndarray | Quantiles to compare against. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Coverage
source
coverage
Coverage of y with y_hat_lo and y_hat_hi.
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, times, actuals and predictions. | |
models | List | Columns that identify the models predictions. | |
level | int | Confidence level used for intervals. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
Calibration
source
calibration
Fraction of y that is lower than the model’s predictions.
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, times, actuals and predictions. | |
models | Dict | Mapping from model name to the model predictions. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |
CRPS
Where is the an estimated multivariate distribution, and are its realizations.
source
scaled_crps
*Scaled Continues Ranked Probability Score
Calculates a scaled variation of the CRPS, as proposed by Rangapuram
(2021), to measure the accuracy of predicted quantiles y_hat
compared
to the observation y
. This metric averages percentual weighted
absolute deviations as defined by the quantile losses.*
Type | Default | Details | |
---|---|---|---|
df | DFType | Input dataframe with id, times, actuals and predictions. | |
models | Dict | Mapping from model name to the model predictions for each quantile. | |
quantiles | ndarray | Quantiles to compare against. | |
id_col | str | unique_id | Column that identifies each serie. |
target_col | str | y | Column that contains the target. |
Returns | DFType | dataframe with one row per id and one column per model. |