gluonts.torch.model.deepar.estimator module#
- class gluonts.torch.model.deepar.estimator.DeepAREstimator(freq: str, prediction_length: int, context_length: Optional[int] = None, num_layers: int = 2, hidden_size: int = 40, lr: float = 0.001, weight_decay: float = 1e-08, dropout_rate: float = 0.1, patience: int = 10, num_feat_dynamic_real: int = 0, num_feat_static_cat: int = 0, num_feat_static_real: int = 0, cardinality: Optional[List[int]] = None, embedding_dimension: Optional[List[int]] = None, distr_output: gluonts.torch.distributions.distribution_output.DistributionOutput = gluonts.torch.distributions.studentT.StudentTOutput(beta=0.0), scaling: bool = True, default_scale: Optional[float] = None, lags_seq: Optional[List[int]] = None, time_features: Optional[List[Callable[[pandas.core.indexes.period.PeriodIndex], numpy.ndarray]]] = None, num_parallel_samples: int = 100, batch_size: int = 32, num_batches_per_epoch: int = 50, imputation_method: Optional[gluonts.transform.feature.MissingValueImputation] = None, trainer_kwargs: Optional[Dict[str, Any]] = None, train_sampler: Optional[gluonts.transform.sampler.InstanceSampler] = None, validation_sampler: Optional[gluonts.transform.sampler.InstanceSampler] = None, nonnegative_pred_samples: bool = False)[source]#
Bases:
gluonts.torch.model.estimator.PyTorchLightningEstimator
Estimator class to train a DeepAR model, as described in [SFG17].
This class is uses the model defined in
DeepARModel
, and wraps it into aDeepARLightningModule
for training purposes: training is performed using PyTorch Lightning’spl.Trainer
class.Note: the code of this model is unrelated to the implementation behind SageMaker’s DeepAR Forecasting Algorithm.
- Parameters
freq – Frequency of the data to train on and predict.
prediction_length (int) – Length of the prediction horizon.
context_length – Number of steps to unroll the RNN for before computing predictions (default: None, in which case context_length = prediction_length).
num_layers – Number of RNN layers (default: 2).
hidden_size – Number of RNN cells for each layer (default: 40).
lr – Learning rate (default:
1e-3
).weight_decay – Weight decay regularization parameter (default:
1e-8
).dropout_rate – Dropout regularization parameter (default: 0.1).
patience – Patience parameter for learning rate scheduler.
num_feat_dynamic_real – Number of dynamic real features in the data (default: 0).
num_feat_static_real – Number of static real features in the data (default: 0).
num_feat_static_cat – Number of static categorical features in the data (default: 0).
cardinality – Number of values of each categorical feature. This must be set if
num_feat_static_cat > 0
(default: None).embedding_dimension – Dimension of the embeddings for categorical features (default:
[min(50, (cat+1)//2) for cat in cardinality]
).distr_output – Distribution to use to evaluate observations and sample predictions (default: StudentTOutput()).
scaling – Whether to automatically scale the target values (default: true).
default_scale – Default scale that is applied if the context length window is completely unobserved. If not set, the scale in this case will be the mean scale in the batch.
lags_seq – Indices of the lagged target values to use as inputs of the RNN (default: None, in which case these are automatically determined based on freq).
time_features – List of time features, from
gluonts.time_feature
, to use as inputs of the RNN in addition to the provided data (default: None, in which case these are automatically determined based on freq).num_parallel_samples – Number of samples per time series to that the resulting predictor should produce (default: 100).
batch_size – The size of the batches to be used for training (default: 32).
num_batches_per_epoch – Number of batches to be processed in each training epoch (default: 50).
trainer_kwargs – Additional arguments to provide to
pl.Trainer
for construction.train_sampler – Controls the sampling of windows during training.
validation_sampler – Controls the sampling of windows during validation.
nonnegative_pred_samples – Should final prediction samples be non-negative? If yes, an activation function is applied to ensure non-negative. Observe that this is applied only to the final samples and this is not applied during training.
- create_lightning_module() gluonts.torch.model.deepar.lightning_module.DeepARLightningModule [source]#
Create and return the network used for training (i.e., computing the loss).
- Returns
The network that computes the loss given input data.
- Return type
pl.LightningModule
- create_predictor(transformation: gluonts.transform._base.Transformation, module: gluonts.torch.model.deepar.lightning_module.DeepARLightningModule) gluonts.torch.model.predictor.PyTorchPredictor [source]#
Create and return a predictor object.
- Parameters
transformation – Transformation to be applied to data before it goes into the model.
module – A trained pl.LightningModule object.
- Returns
A predictor wrapping a nn.Module used for inference.
- Return type
- create_training_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.deepar.lightning_module.DeepARLightningModule, shuffle_buffer_length: Optional[int] = None, **kwargs) Iterable [source]#
Create a data loader for training purposes.
- Parameters
data – Dataset from which to create the data loader.
module – The pl.LightningModule object that will receive the batches from the data loader.
- Returns
The data loader, i.e. and iterable over batches of data.
- Return type
Iterable
- create_transformation() gluonts.transform._base.Transformation [source]#
Create and return the transformation needed for training and inference.
- Returns
The transformation that will be applied entry-wise to datasets, at training and inference time.
- Return type
- create_validation_data_loader(data: gluonts.dataset.Dataset, module: gluonts.torch.model.deepar.lightning_module.DeepARLightningModule, **kwargs) Iterable [source]#
Create a data loader for validation purposes.
- Parameters
data – Dataset from which to create the data loader.
module – The pl.LightningModule object that will receive the batches from the data loader.
- Returns
The data loader, i.e. and iterable over batches of data.
- Return type
Iterable
- lead_time: int#
- prediction_length: int#