Zurück zu den Modellen
Regressor

SimpleRNNRegressorTorch

Simple recurrent neural network in PyTorch for time series regression.

Schnellstart

python
from sktime.regression.deep_learning.rnn import SimpleRNNRegressorTorch

estimator = SimpleRNNRegressorTorch(hidden_dim: int=6, n_layers: int=1, activation: str | Callable | None=None, activation_hidden: str | Callable='ReLU', bias: bool=True, init_weights: bool=True, dropout: float=0.0, fc_dropout: float=0.0, bidirectional: bool=False, num_epochs: int=100, batch_size: int=1, optimizer: str | None | Callable='RMSprop', criterion: str | None | Callable='MSELoss', callbacks: None | str | tuple [str, ... ]='ReduceLROnPlateau', criterion_kwargs: dict=None, optimizer_kwargs: dict=None, callback_kwargs: dict | None=None, metrics: None | str | Callable | tuple [str | Callable, ... ]=None, lr: float=0.001, verbose: bool=False, random_state: int=0)

Parameter(21)

hidden_dimint, default = 6
Number of features in the hidden state.
n_layersint, default = 1
Number of recurrent layers. Setting n_layers=2 would mean stacking two RNNs together to form a stacked RNN, with the second RNN taking in outputs of the first RNN and computing the final results.
activationstr, Callable, or None, default=None

Activation applied to the output layer.

Permitted values:

  • None: no activation is applied to the output layer and the network returns raw outputs.

  • str: name of a class in torch.nn. Case-sensitive names are recommended and must match PyTorch (e.g., "ReLU", "LeakyReLU"). Lowercase aliases for common activations are also accepted (e.g., "relu" is resolved to "ReLU"). The class is instantiated with default constructor arguments. Must be a valid torch.nn activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity

  • torch.nn.Module: an instance of a torch.nn.Module subclass, for example torch.nn.ReLU(). Arbitrary callables are not supported.

activation_hiddenstr, Callable, or None, default=”ReLU”

Activation applied inside the RNN.

Permitted values:

  • None: no activation is applied inside the RNN.

  • str: name of a class in torch.nn. Case-sensitive names are recommended and must match PyTorch (e.g., "ReLU", "LeakyReLU"). Lowercase aliases for common activations are also accepted (e.g., "relu" is resolved to "ReLU"). The class is instantiated with default constructor arguments. Must be a valid torch.nn activation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearity

  • torch.nn.Module: an instance of a torch.nn.Module subclass, for example torch.nn.ReLU(). Arbitrary callables are not supported.

Recommended activations: ReLU, Tanh.

Because currently PyTorch only supports these two activations inside the RNN. https://docs.pytorch.org/docs/stable/generated/torch.nn.RNN.html#torch.nn.RNN

biasbool, default = True
If False, then the layer does not use bias weights.
init_weightsbool, default = True
If True, then the weights are initialized.
dropoutfloat, default = 0.0
If non-zero, introduces a Dropout layer on the outputs of each RNN layer except the fully connected output layer, with dropout probability equal to dropout.
fc_dropoutfloat, default = 0.0
If non-zero, introduces a Dropout layer on the outputs of the fully connected output layer, with dropout probability equal to fc_dropout.
bidirectionalbool, default = False
If True, then the RNN is bidirectional.
num_epochsint, default = 100
The number of epochs to train the model.
optimizercase insensitive str or None or an instance of optimizers

defined in torch.optim, default = “RMSprop” The optimizer to use for training the model. List of available optimizers: https://pytorch.org/docs/stable/optim.html#algorithms

optimizer_kwargsdict or None, default = None
Additional keyword arguments to pass to the optimizer.
batch_sizeint, default = 1
The size of each mini-batch during training.
criterioncase insensitive str or None or an instance of a loss function

defined in PyTorch, default = “MSELoss” The loss function to be used in training the neural network. List of available loss functions: https://pytorch.org/docs/stable/nn.html#loss-functions

criterion_kwargsdict or None, default = None
Additional keyword arguments to pass to the loss function.
callbacksNone or str or a tuple of str, default = “ReduceLROnPlateau”

Currently only learning rate schedulers are supported as callbacks. If more than one scheduler is passed, they are applied sequentially in the order they are passed. If None, then no learning rate scheduler is used. Note: Since PyTorch learning rate schedulers need to be initialized with the optimizer object, we only accept the class name (str) of the scheduler here and do not accept an instance of the scheduler. As that can lead to errors and unexpected behavior. List of available learning rate schedulers: https://pytorch.org/docs/stable/optim.html#how-to-adjust-learning-rate

callback_kwargsdict or None, default = None
The keyword arguments to be passed to the callbacks.
metricsNone or str or Callable or tuple of str and/or Callable, default = None

Metrics to compute during training. If None, no metrics are computed beyond the loss. Metrics are computed from torchmetrics library. If a string/Callable is passed, it must be one of the metrics defined in https://lightning.ai/docs/torchmetrics/stable/ Examples: “MeanSquaredError”, “MeanAbsoluteError”, “R2Score”

lrfloat, default = 0.001
The learning rate to use for the optimizer.
verbosebool, default = False
Whether to print progress information during training.
random_stateint, default = 0
Seed to ensure reproducibility.

Beispiele

>>> from sktime.regression.deep_learning.rnn import SimpleRNNRegressorTorch
>>> from sktime.datasets import load_unit_test
>>> X_train, y_train = load_unit_test (split = "train")
>>> X_test, y_test = load_unit_test (split = "test")
>>> reg = SimpleRNNRegressorTorch (n_epochs = 50, batch_size = 2)
>>> reg. fit (X_train, y_train) SimpleRNNRegressorTorch(
... )