Good day support team, I am having some difficulti...
# mlforecast
p
Good day support team, I am having some difficulties implementing the automatic mlforecast. I try to apply the code to the attached dataset but get several errors. Specifically: I got errors of: "AutoRandomForest: ValueError: Some value(s) of y are negative which is not allowed for Poisson regression. AutoLinearRegression: ValueError: Found input variables with inconsistent numbers of samples: [134, 12] ValueError: Found input variables with inconsistent numbers of samples: [134, 12]"
Here is my code
from 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
)
Double check target but there was not any negative values (for AutoRF error) and tried varying slicing windows but did not get AutoLinearReg and AutoElasticNet to work
j
Hey. Thanks for the thorough report. The error for random forest is coming from the fact that we're applying differences (which produce negative values) and trying a poisson loss. We'll remove the poisson loss, in the meantime you can manually remove it by defining a different space like this:
Copy code
from 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:
Copy code
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)
p
Thank you so much Jose. All worked out for now. Much appreciate it ^_^