Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Sktime Pytorch forecasting RecurrentNetwork

From Leeroopedia


Knowledge Sources
Domains Time_Series, Forecasting, Deep_Learning
Last Updated 2026-02-08 08:00 GMT

Overview

RecurrentNetwork is an RNN-based time series forecasting model supporting LSTM and GRU cell types with autoregressive decoding.

Description

RecurrentNetwork extends AutoRegressiveBaseModelWithCovariates and implements a simple but effective recurrent architecture for time series forecasting. The model encodes the input sequence using stacked LSTM or GRU layers, then decodes predictions autoregressively during evaluation by feeding each predicted step back as input to the next step. It supports both single-target and multi-target forecasting, static and time-varying categorical and continuous covariates, and target lags for capturing seasonality.

Usage

Use RecurrentNetwork when you need a straightforward recurrent neural network for time series forecasting, especially for shorter horizons where autoregressive decoding is appropriate. It is a good baseline model and works well when the temporal dependencies are sequential in nature. The preferred instantiation method is via from_dataset.

Code Reference

Source Location

Signature

class RecurrentNetwork(AutoRegressiveBaseModelWithCovariates):
    def __init__(
        self,
        cell_type: str = "LSTM",
        hidden_size: int = 10,
        rnn_layers: int = 2,
        dropout: float = 0.1,
        static_categoricals: list[str] | None = None,
        static_reals: list[str] | None = None,
        time_varying_categoricals_encoder: list[str] | None = None,
        time_varying_categoricals_decoder: list[str] | None = None,
        categorical_groups: dict[str, list[str]] | None = None,
        time_varying_reals_encoder: list[str] | None = None,
        time_varying_reals_decoder: list[str] | None = None,
        embedding_sizes: dict[str, tuple[int, int]] | None = None,
        embedding_paddings: list[str] | None = None,
        embedding_labels: dict[str, np.ndarray] | None = None,
        x_reals: list[str] | None = None,
        x_categoricals: list[str] | None = None,
        output_size: int | list[int] = 1,
        target: str | list[str] = None,
        target_lags: dict[str, list[int]] | None = None,
        loss: MultiHorizonMetric = None,
        logging_metrics: nn.ModuleList = None,
        **kwargs,
    ):

from_dataset Signature

@classmethod
def from_dataset(
    cls,
    dataset: TimeSeriesDataSet,
    allowed_encoder_known_variable_names: list[str] = None,
    **kwargs,
):

Import

from pytorch_forecasting.models.rnn import RecurrentNetwork

I/O Contract

Inputs

Name Type Required Description
cell_type str No Recurrent cell type, one of "LSTM" or "GRU". Defaults to "LSTM".
hidden_size int No Hidden recurrent size. Defaults to 10.
rnn_layers int No Number of RNN layers. Defaults to 2.
dropout float No Dropout in RNN layers. Defaults to 0.1.
output_size list[int] No Number of outputs per target. Defaults to 1.
target list[str] No Target variable name(s). Defaults to None.
target_lags None No Dictionary of target names to lag time steps for seasonality. Defaults to empty.
loss MultiHorizonMetric No Loss function. Defaults to MAE().
logging_metrics nn.ModuleList No Metrics for logging. Defaults to [SMAPE, MAE, RMSE, MAPE, MASE].
static_categoricals None No Names of static categorical variables.
static_reals None No Names of static continuous variables.
embedding_sizes None No Mapping of categorical variables to (num_classes, embedding_dim).

Outputs

Name Type Description
prediction torch.Tensor Forecast output after transformation to target space.

Usage Examples

from pytorch_forecasting import TimeSeriesDataSet
from pytorch_forecasting.models.rnn import RecurrentNetwork

# Create model from dataset (preferred)
model = RecurrentNetwork.from_dataset(
    dataset,
    cell_type="LSTM",
    hidden_size=64,
    rnn_layers=2,
    dropout=0.1,
)

# Direct instantiation
model = RecurrentNetwork(
    cell_type="GRU",
    hidden_size=32,
    rnn_layers=3,
    dropout=0.2,
    target="sales",
    output_size=1,
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment