Hello everyone, I hope you can help me with the fo...
# neural-forecast
f
Hello everyone, I hope you can help me with the following: I’m using
neuralforecast
to tune hyperparameters with
Auto
models, aiming to find the best-performing model for each
unique_id
across a set of 7 different time series. During the optimization process, I permute both historical and future exogenous variables. Once the model is trained, I subject it to cross-validation. My question is whether this approach is correct, given that the model is supposed to have already selected the best hyperparameters. However, I’ve noticed that during cross-validation, the model seems to perform parameter permutations again. The ultimate goal is to compare the two trained models and determine which one performs best for each individual series.
1
o
It's a valid approach, but I'd personally not do it like this. Neural networks learn from the data, so you don't need to create explicit ewm-like features and try to optimize over the feature selection. Hence, remove all 'y-lag'-type features, and only include true exogenous features in your model. I'd exclude the entire feature selection part from your loop. Hope this helps
a
Thanks for tagging me @Max (Nixtla). I'll look through relevant sources and get back to you shortly.
In ​*NeuralForecast*​, your approach is correct but there's an important distinction to understand about how
Auto
models work with cross-validation (1) . When you use
Auto
models like
AutoNHITS
or
AutoLSTM
, the hyperparameter optimization happens during the initial
.fit()
method . The
Auto
models automatically perform hyperparameter tuning, training multiple models with different hyperparameters, producing forecasts on the validation set, and evaluating them . Only the best model is stored and used during inference . However, when you subsequently call
cross_validation
, you're not re-optimizing hyperparameters . The cross-validation method uses the already-optimized model with the best hyperparameters found during the initial training phase . The cross-validation process allows you to simulate multiple historic forecasts by defining a sliding window across the historical data and predicting the period following it . This gives you a better estimation of your model's predictive abilities across a wider range of temporal instances . For model comparison across your 7 time series, you can use the evaluation approach shown in the documentation :
Copy code
from utilsforecast.evaluation import evaluate
from utilsforecast.losses import mse, mae, rmse

evaluation_df = evaluate(cv_df.drop(columns='cutoff') , metrics=[mse, mae, rmse])
evaluation_df['best_model'] = evaluation_df.drop(columns=['metric', 'unique_id']) .idxmin(axis=1)
This will help you determine which model performs best for each individual
unique_id
.
To learn more, see the sources I considered: [[1] End to End Walkthrough](https://nixtlaverse.nixtla.io/neuralforecast/docs/tutorials/getting_started_complete.html)
Thanks for the feedback, glad I was helpful.
f
Thank you for your support, @Olivier. I’ll run the tests with your suggestions. And to you, @Max (Nixtla), thanks to the model I was able to clear up all my doubts.
a
Thanks for the feedback, glad I was helpful.