deepar¶
Classes
|
Wrapper for |
- class DeepARModel(decoder_length: Optional[int] = None, encoder_length: Optional[int] = None, dataset_builder: Optional[etna.models.nn.utils.PytorchForecastingDatasetBuilder] = None, train_batch_size: int = 64, test_batch_size: int = 64, lr: float = 0.001, cell_type: str = 'LSTM', hidden_size: int = 10, rnn_layers: int = 2, dropout: float = 0.1, loss: Optional[pytorch_forecasting.metrics.DistributionLoss] = None, trainer_params: Optional[Dict[str, Any]] = None, quantiles_kwargs: Optional[Dict[str, Any]] = None)[source]¶
Wrapper for
pytorch_forecasting.models.deepar.DeepAR
.Notes
We save
pytorch_forecasting.data.timeseries.TimeSeriesDataSet
in instance to use it in the model. It`s not right pattern of using Transforms and TSDataset.Initialize DeepAR wrapper.
- Parameters
decoder_length (Optional[int]) – Decoder length.
encoder_length (int) – Encoder length.
dataset_builder (etna.models.nn.utils.PytorchForecastingDatasetBuilder) – Dataset builder for PytorchForecasting.
train_batch_size (int) – Train batch size.
test_batch_size (int) – Test batch size.
lr (float) – Learning rate.
cell_type (str) – One of ‘LSTM’, ‘GRU’.
hidden_size (int) – Hidden size of network which can range from 8 to 512.
rnn_layers (int) – Number of LSTM layers.
dropout (float) – Dropout rate.
loss (Optional[DistributionLoss]) – Distribution loss function. Keep in mind that each distribution loss function might have specific requirements for target normalization. Defaults to
pytorch_forecasting.metrics.NormalDistributionLoss
.trainer_params (Dict[str, Any]) – Additional arguments for pytorch_lightning Trainer.
quantiles_kwargs (Optional[Dict[str, Any]]) – Additional arguments for computing quantiles, look at
to_quantiles()
method for your loss.
- fit(ts: etna.datasets.tsdataset.TSDataset)¶
Fit model.
- Parameters
ts (etna.datasets.tsdataset.TSDataset) – TSDataset to fit.
- Returns
model
- forecast(ts: etna.datasets.tsdataset.TSDataset, prediction_size: int, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975), return_components: bool = False) etna.datasets.tsdataset.TSDataset [source]¶
Make predictions.
This method will make autoregressive predictions.
- Parameters
ts (etna.datasets.tsdataset.TSDataset) – Dataset with features
prediction_size (int) – Number of last timestamps to leave after making prediction. Previous timestamps will be used as a context for models that require it.
prediction_interval (bool) – If True returns prediction interval for forecast
quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% are taken to form a 95% prediction interval
return_components (bool) – If True additionally returns forecast components
- Returns
TSDataset with predictions.
- Return type
- get_model() Any [source]¶
Get internal model that is used inside etna class.
Model is the instance of
pytorch_forecasting.models.deepar.DeepAR
.- Returns
Internal model
- Return type
Any
- classmethod load(path: pathlib.Path) typing_extensions.Self ¶
Load an object.
Warning
This method uses
dill
module which is not secure. It is possible to construct malicious data which will execute arbitrary code during loading. Never load data that could have come from an untrusted source, or that could have been tampered with.- Parameters
path (pathlib.Path) – Path to load object from.
- Returns
Loaded object.
- Return type
typing_extensions.Self
- params_to_tune() Dict[str, etna.distributions.distributions.BaseDistribution] [source]¶
Get default grid for tuning hyperparameters.
This grid tunes parameters:
hidden_size
,rnn_layers
,dropout
,lr
. Other parameters are expected to be set by the user.- Returns
Grid to tune.
- Return type
Dict[str, etna.distributions.distributions.BaseDistribution]
- predict(ts: etna.datasets.tsdataset.TSDataset, prediction_size: int, prediction_interval: bool = False, quantiles: Sequence[float] = (0.025, 0.975), return_components: bool = False) etna.datasets.tsdataset.TSDataset [source]¶
Make predictions.
This method will make predictions using true values instead of predicted on a previous step. It can be useful for making in-sample forecasts.
- Parameters
ts (etna.datasets.tsdataset.TSDataset) – Dataset with features
prediction_size (int) – Number of last timestamps to leave after making prediction. Previous timestamps will be used as a context.
prediction_interval (bool) – If True returns prediction interval for forecast
quantiles (Sequence[float]) – Levels of prediction distribution. By default 2.5% and 97.5% are taken to form a 95% prediction interval
return_components (bool) – If True additionally returns prediction components
- Returns
TSDataset with predictions.
- Return type
- save(path: pathlib.Path)¶
Save the object.
- Parameters
path (pathlib.Path) – Path to save object to.
- set_params(**params: dict) etna.core.mixins.TMixin ¶
Return new object instance with modified parameters.
Method also allows to change parameters of nested objects within the current object. For example, it is possible to change parameters of a
model
in aPipeline
.Nested parameters are expected to be in a
<component_1>.<...>.<parameter>
form, where components are separated by a dot.- Parameters
**params – Estimator parameters
self (etna.core.mixins.TMixin) –
params (dict) –
- Returns
New instance with changed parameters
- Return type
etna.core.mixins.TMixin
Examples
>>> from etna.pipeline import Pipeline >>> from etna.models import NaiveModel >>> from etna.transforms import AddConstTransform >>> model = model=NaiveModel(lag=1) >>> transforms = [AddConstTransform(in_column="target", value=1)] >>> pipeline = Pipeline(model, transforms=transforms, horizon=3) >>> pipeline.set_params(**{"model.lag": 3, "transforms.0.value": 2}) Pipeline(model = NaiveModel(lag = 3, ), transforms = [AddConstTransform(in_column = 'target', value = 2, inplace = True, out_column = None, )], horizon = 3, )
- to_dict()¶
Collect all information about etna object in dict.
- property context_size: int¶
Context size of the model.