Phan Quoc Hung
05/09/2024, 11:00 AMPhan Quoc Hung
05/09/2024, 11:00 AMfrom sklearn.metrics import mean_squared_error
from math import sqrt
def mse_loss(forecast_df, train_df):
y_pred = forecast_df['y'].values
y_true = train_df['y'].values
return mean_squared_error(y_true, y_pred)
auto_mlf = AutoMLForecast(
models={'lr': AutoLinearRegression(), 'en': AutoElasticNet(), AutoRandomForest()},
freq='M',
season_length=12,
)
auto_mlf.fit(
rf_df,
n_windows= 5, #15(work), #16, #194//12: number of windows to evaluate
h=forecast_horizon,
num_samples=50, #trial to run
loss = mse_loss
)
Phan Quoc Hung
05/09/2024, 11:01 AMJosé Morales
05/09/2024, 4:27 PMfrom mlforecast.auto import AutoModel, random_forest_space
from sklearn.ensemble import RandomForestRegressor
def my_rf_space(trial):
return {k: v for k, v in random_forest_space(trial).items() if k != "criterion"}
my_auto_rf = AutoModel(RandomForestRegressor(), my_rf_space)
The other errors are coming from your custom loss. The training dataframe is provided in case you want to compute a loss that uses the training set, such as MASE. In this case you're comparing the forecasts vs the training set values of the target. I believe what you want to do is this instead:
def mse_loss(forecast_df, train_df):
y_true = forecast_df['y'].values
y_pred = forecast_df['model'].values
return mean_squared_error(y_true, y_pred)
Phan Quoc Hung
05/10/2024, 9:13 AM