module utilsforecast.losses
Loss functions for model evaluation.
function mae
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function mse
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function rmse
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function bias
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function cfe
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function pis
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function spis
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function mape
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function smape
df(pandas or polars DataFrame): Input dataframe with id, actual values and predictions.models(list of str): Columns that identify the models predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function mase
df(pandas or polars DataFrame): Input dataframe with id, actuals and predictions.models(list of str): 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(pandas or polars DataFrame): Training dataframe with id and actual values. Must be sorted by time.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
[1] https: //robjhyndman.com/papers/mase.pdf
function rmae
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(list of str): Columns that identify the models predictions.baseline(str): Column that identifies the baseline model predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function nd
df: Input dataframe with id, times, actuals and predictions.models: Columns that identify the models predictions.id_col: Column that identifies each serie. Defaults to ‘unique_id’.target_col: Column that contains the target. Defaults to ‘y’.
function msse
df(pandas or polars DataFrame): Input dataframe with id, actuals and predictions.models(list of str): 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(pandas or polars DataFrame): Training dataframe with id and actual values. Must be sorted by time.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
[1] https: //otexts.com/fpp3/accuracy.html
function rmsse
df(pandas or polars DataFrame): Input dataframe with id, actuals and predictions.models(list of str): 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(pandas or polars DataFrame): Training dataframe with id and actual values. Must be sorted by time.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
[1] https: //otexts.com/fpp3/accuracy.html
function quantile_loss
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(dict from str to str): Mapping from model name to the model predictions for the specified quantile.q(float, optional): Quantile for the predictions’ comparison. Defaults to 0.5.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function scaled_quantile_loss
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(dict from str to str): Mapping from model name to the model predictions for the specified quantile.seasonality(int): Main frequency of the time series; Hourly 24, Daily 7, Weekly 52, Monthly 12, Quarterly 4, Yearly 1.train_df(pandas or polars DataFrame): Training dataframe with id and actual values. Must be sorted by time.q(float, optional): Quantile for the predictions’ comparison. Defaults to 0.5.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function mqloss
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(dict from str to list of str): Mapping from model name to the model predictions for each quantile.quantiles(numpy array): Quantiles to compare against.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
[1] https: //www.jstor.org/stable/2629907
function scaled_mqloss
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(dict from str to list of str): Mapping from model name to the model predictions for each quantile.quantiles(numpy array): Quantiles to compare against.seasonality(int): Main frequency of the time series; Hourly 24, Daily 7, Weekly 52, Monthly 12, Quarterly 4, Yearly 1.train_df(pandas or polars DataFrame): Training dataframe with id and actual values. Must be sorted by time.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
function coverage
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(list of str): Columns that identify the models predictions.level(int): Confidence level used for intervals.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
[1] https: //www.jstor.org/stable/2629907
function calibration
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(dict from str to str): Mapping from model name to the model predictions.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
[1] https: //www.jstor.org/stable/2629907
function scaled_crps
y_hat compared to the observation y. This metric averages percentual weighted absolute deviations as defined by the quantile losses.
Args:
df(pandas or polars DataFrame): Input dataframe with id, times, actuals and predictions.models(dict from str to list of str): Mapping from model name to the model predictions for each quantile.quantiles(numpy array): Quantiles to compare against.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: dataframe with one row per id and one column per model.
[1] https: //proceedings.mlr.press/v139/rangapuram21a.html
function tweedie_deviance
power parameter defines the specific compound distribution:
- 1: Poisson
- (1, 2): Compound Poisson-Gamma
- 2: Gamma
-
2: Inverse Gaussian
df(pandas or polars DataFrame): Input dataframe with id, actuals and predictions.models(list of str): Columns that identify the models predictions.power(float, optional): Tweedie power parameter. Determines the compound distribution. Defaults to 1.5.id_col(str, optional): Column that identifies each serie. Defaults to ‘unique_id’.target_col(str, optional): Column that contains the target. Defaults to ‘y’.
pandas or polars DataFrame: DataFrame with one row per id and one column per model, containing the mean Tweedie deviance.
[1] https: //en.wikipedia.org/wiki/Tweedie_distribution

