TapNetRegressorTorch
TapNet regressor in PyTorch.
Quickstart
from sktime.regression.deep_learning.tapnet import TapNetRegressorTorch
estimator = TapNetRegressorTorch(filter_sizes: tuple [int, ... ]=(256, 256, 128), kernel_size: tuple [int, ... ]=(8, 5, 3), layers: tuple [int, ... ]=(500, 300), dropout: float=0.5, lstm_dropout: float=0.8, dilation: int=1, activation: str | Callable | None=None, activation_hidden: str | Callable='LeakyReLU', use_rp: bool=True, rp_group: int=3, rp_alpha: float=2.0, use_att: bool=True, use_lstm: bool=True, use_cnn: bool=True, padding: str='same', init_weights: bool=True, fc_dropout: float=0.0, num_epochs: int=100, batch_size: int=1, optimizer: str | None | Callable='RMSprop', criterion: str | None | Callable='MSELoss', callbacks: None | str | tuple [str, ... ]='ReduceLROnPlateau', optimizer_kwargs: dict | None=None, criterion_kwargs: dict | None=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)Parameters(29)
- filter_sizestuple of int, default = (256, 256, 128)
Number of convolutional filters in each conv block. If
use_rpis True, the first conv layer is group-specific and all subsequent conv layers share parameters across groups.- kernel_sizetuple of int, default = (8, 5, 3)
- Specifying the length of the 1D convolution window.
- layerstuple of int, default = (500, 300)
- Sizes of dense layers in the mapping section. Any length >= 1 is allowed.
- dropoutfloat, default = 0.5
- Dropout rate for the convolutional layers.
- lstm_dropoutfloat, default = 0.8
- Dropout rate for the LSTM layer.
- dilationint, default = 1
- Dilation value.
- activationstr or Callable or None, default = None
- Activation function to use in the output layer. If callable, it must accept and return a torch tensor.
- activation_hiddenstr or Callable, default = “LeakyReLU”
- Activation function to use in the hidden layers.
- use_rpbool, default = True
- Whether to use random projections.
- rp_groupint, default = 3
- Number of random permutation groups g for random dimension permutation (RDP). Must be a positive integer.
- rp_alphafloat, default = 2.0
- Scale factor alpha used to compute the RDP group size: rp_dim = floor(n_dims * rp_alpha / rp_group). If rp_dim becomes 0, RDP is disabled with a warning (RDP requires multivariate inputs). Must be positive.
- use_attbool, default = True
- Whether to use self attention.
- use_lstmbool, default = True
- Whether to use an LSTM layer.
- use_cnnbool, default = True
- Whether to use a CNN layer.
- paddingstr, default = “same”
- Type of padding for convolution layers.
- init_weightsbool, default = True
- Whether to apply custom initialization.
- fc_dropoutfloat, default = 0.0
- Dropout rate before the output layer.
- num_epochsint, default = 100
- The number of epochs to train the model.
- batch_sizeint, default = 1
- The size of each mini-batch during training.
- optimizerstr 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
- 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
- callbacksNone or str or a tuple of str, default = “ReduceLROnPlateau”
Learning rate schedulers applied during training. 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
- optimizer_kwargsdict or None, default = None
- Additional keyword arguments to pass to the optimizer.
- criterion_kwargsdict or None, default = None
- Additional keyword arguments to pass to the loss function.
- 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.
Examples
>>> from sktime.regression.deep_learning.tapnet import TapNetRegressorTorch
>>> 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 = TapNetRegressorTorch (num_epochs = 20, batch_size = 4)
>>> reg. fit (X_train, y_train) TapNetRegressorTorch(
... )