Skip to main content

1. Introduction

All NeuralForecast models work out of the box with sensible default parameters. However, to achieve optimal forecasting performance on your specific dataset, hyperparameter optimization is highly recommended. Hyperparameter optimization is the process of automatically finding the best configuration for a model by systematically exploring different combinations of parameters such as learning rate, hidden layer sizes, number of layers, and other architectural choices. Unlike model parameters that are learned during training, hyperparameters must be set before training begins. NeuralForecast provides AutoModel classes that automate this optimization process. Each AutoModel wraps a corresponding forecasting model and uses techniques like grid search, random search, or Bayesian optimization to explore the hyperparameter space and identify the configuration that minimizes validation loss.

BaseAuto Class

All AutoModel classes inherit from BaseAuto, which provides a unified interface for hyperparameter optimization. BaseAuto handles the complete optimization workflow:
  1. Search Space Definition: Defines which hyperparameters to explore and their ranges
  2. Temporal Cross-Validation: Splits data temporally to avoid look-ahead bias
  3. Training & Evaluation: Runs multiple trials with different hyperparameter configurations
  4. Model Selection: Selects the configuration with the best validation performance
  5. Refitting: Trains the final model with optimal hyperparameters
The optimization process uses temporal cross-validation where the validation set sequentially precedes the test set. This ensures that hyperparameter selection is based on realistic forecasting scenarios. The validation loss guides the selection process, so it’s important that the validation period is representative of future forecasting conditions.

BaseAuto

Bases: LightningModule Class for Automatic Hyperparameter Optimization, it builds on top of ray to give access to a wide variety of hyperparameter optimization tools ranging from classic grid search, to Bayesian optimization and HyperBand algorithm. The validation loss to be optimized is defined by the config['loss'] dictionary value, the config also contains the rest of the hyperparameter search space. It is important to note that the success of this hyperparameter optimization heavily relies on a strong correlation between the validation and test periods. Parameters:
NameTypeDescriptionDefault
cls_modelPyTorch/PyTorchLightning modelSee neuralforecast.models collection here.required
hintForecast horizonrequired
lossPyTorch moduleInstantiated train loss class from losses collection.required
valid_lossPyTorch moduleInstantiated valid loss class from losses collection.required
configdict or callableDictionary with ray.tune defined search space or function that takes an optuna trial and returns a configuration dict.required
search_algray.tune.search variant or optuna.samplerFor ray see https://docs.ray.io/en/latest/tune/api_docs/suggestion.html For optuna see https://optuna.readthedocs.io/en/stable/reference/samplers/index.html.BasicVariantGenerator(random_state=1)
num_samplesintNumber of hyperparameter optimization steps/samples.10
cpusintNumber of cpus to use during optimization. Only used with ray tune.cpu_count()
gpusintNumber of gpus to use during optimization, default all available. Only used with ray tune.device_count()
refit_with_valboolRefit of best model should preserve val_size.False
verboseboolTrack progress.False
aliasstrCustom name of the model.None
backendstrBackend to use for searching the hyperparameter space, can be either ‘ray’ or ‘optuna’.‘ray’
callbackslist of callableList of functions to call during the optimization process. ray reference: https://docs.ray.io/en/latest/tune/tutorials/tune-metrics.html optuna reference: https://optuna.readthedocs.io/en/stableNone

2. Available AutoModels

NeuralForecast provides 34 AutoModel variants, each wrapping a specific forecasting model with automatic hyperparameter optimization. Each AutoModel has a default_config attribute that defines sensible search spaces for its corresponding model.

RNN-Based Models

Recurrent neural networks for sequential forecasting:

Transformer-Based Models

Attention-based architectures for capturing complex temporal patterns:

CNN-Based Models

Convolutional architectures for local pattern recognition:

Linear and MLP Models

Simple yet effective linear and feed-forward architectures:

Specialized Models

Models designed for specific forecasting scenarios:

3. Usage Examples

Data Preparation

First, prepare your time series data and create a TimeSeriesDataset:

Basic Usage

The simplest way to use an AutoModel is with its default search space:

Hierarchical Forecasting with AutoHINT

AutoHINT combines hyperparameter optimization with hierarchical reconciliation. This is useful when forecasting hierarchical time series (e.g., product hierarchies, geographic hierarchies).

Optimize Model, Then Apply Fixed Reconciliation

Joint Optimization of Model and Reconciliation Method