Hello again team, any one know how to add a custom...
# general
l
Hello again team, any one know how to add a custom loss metric in to the AutoMLForecast class? I'm currently working in retail and I need to apply a custom metric in to my CV, any help is welcome :D
j
Hey. You need to implement a function that takes the out of sample df and the training dataframe and returns a single float. The first df will have the predictions in a column named
model
, so you can do for example:
Copy code
from utilsforecast.losses import rmse

def my_loss(df, train_df):
    return rmse(df, models=["model"])["model"].mean()
l
So if I want to implement a custom code metri, it would look something like this?
Copy code
def my_loss(df, train_df):
    # Calculate RMSE
    rmse_value = np.sqrt(((train_df['y'] - df['model']) ** 2).mean())
    return rmse_value
j
the
y
has to come from
df
as well, e.g.
rmse_value = np.sqrt((df['y'] - df['model']) ** 2).mean())
🙌 1
l
Ohh I get it now, thanks a lot
j
The train_df is there in case you want a metric that depends on the training set like mase