Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion pytorch_forecasting/models/deepar/_deepar.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,37 @@


class DeepAR(AutoRegressiveBaseModelWithCovariates):
"""DeepAR: Probabilistic forecasting with autoregressive recurrent networks."""
"""DeepAR: Probabilistic forecasting with autoregressive recurrent networks.

Examples
--------
Create a dataset, train a model, and predict the validation horizon:

.. code-block:: python

import lightning.pytorch as pl
from pytorch_forecasting import DeepAR, TimeSeriesDataSet
from pytorch_forecasting.data.examples import generate_ar_data

data = generate_ar_data(seasonality=10.0, timesteps=120, n_series=4)
cutoff = data["time_idx"].max() - 6
training = TimeSeriesDataSet(
data[lambda x: x.time_idx <= cutoff],
time_idx="time_idx",
target="value",
group_ids=["series"],
max_encoder_length=24,
max_prediction_length=6,
time_varying_unknown_reals=["value"],
)
validation = TimeSeriesDataSet.from_dataset(
training, data, min_prediction_idx=cutoff + 1
)
model = DeepAR.from_dataset(training, hidden_size=16)
trainer = pl.Trainer(max_epochs=1, logger=False, enable_checkpointing=False)
trainer.fit(model, training.to_dataloader(train=True, batch_size=32))
predictions = model.predict(validation.to_dataloader(train=False, batch_size=32))
"""

@classmethod
def _pkg(cls):
Expand Down
10 changes: 9 additions & 1 deletion pytorch_forecasting/models/deepar/_deepar_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@


class DeepAR_pkg(_BasePtForecaster):
"""DeepAR package container."""
"""DeepAR package container.

Examples
--------
The package container resolves to the user-facing model class:

>>> DeepAR_pkg.get_cls().__name__
'DeepAR'
"""

_tags = {
"info:name": "DeepAR",
Expand Down
29 changes: 29 additions & 0 deletions pytorch_forecasting/models/nbeats/_nbeats.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,35 @@ class NBeats(NBeatsAdapter):
nn.ModuleList([SMAPE(), MAE(), RMSE(), MAPE(), MASE()]).
**kwargs
Additional arguments forwarded to :py:class:`~BaseModel`.

Examples
--------
Create a dataset, train a model, and predict the validation horizon:

.. code-block:: python

import lightning.pytorch as pl
from pytorch_forecasting import NBeats, TimeSeriesDataSet
from pytorch_forecasting.data.examples import generate_ar_data

data = generate_ar_data(seasonality=10.0, timesteps=120, n_series=4)
cutoff = data["time_idx"].max() - 6
training = TimeSeriesDataSet(
data[lambda x: x.time_idx <= cutoff],
time_idx="time_idx",
target="value",
group_ids=["series"],
max_encoder_length=24,
max_prediction_length=6,
time_varying_unknown_reals=["value"],
)
validation = TimeSeriesDataSet.from_dataset(
training, data, min_prediction_idx=cutoff + 1
)
model = NBeats.from_dataset(training, context_length=24)
trainer = pl.Trainer(max_epochs=1, logger=False, enable_checkpointing=False)
trainer.fit(model, training.to_dataloader(train=True, batch_size=32))
predictions = model.predict(validation.to_dataloader(train=False, batch_size=32))
""" # noqa: E501

@classmethod
Expand Down
10 changes: 9 additions & 1 deletion pytorch_forecasting/models/nbeats/_nbeats_pkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@


class NBeats_pkg(_BasePtForecaster):
"""NBeats package container."""
"""NBeats package container.

Examples
--------
The package container resolves to the user-facing model class:

>>> NBeats_pkg.get_cls().__name__
'NBeats'
"""

_tags = {
"info:name": "NBeats",
Expand Down
Loading