MLPRegressorTorch
Multi Layer Perceptron Network (MLP), as described in [1].
Quickstart
from sktime.regression.deep_learning.mlp import MLPRegressorTorch
estimator = MLPRegressorTorch(hidden_dim: int=500, n_layers: int=4, activation: str | Callable | None=None, activation_hidden: str | Callable | None='ReLU', bias: bool=True, dropout: float | tuple [float, ... ]=(0.1, 0.2, 0.2, 0.3), fc_dropout: float=0.0, num_epochs: int=100, optimizer: str | None | Callable='Adam', optimizer_kwargs: dict | None=None, batch_size: int=1, criterion: str | None | Callable='MSELoss', criterion_kwargs: dict | None=None, callbacks: str | tuple [str ] | None='ReduceLROnPlateau', 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(19)
- hidden_dimint, default = 500
- Dimensionality of the hidden layers.
- n_layersint, default = 4
- Number of hidden layers.
- activationstr or None or an instance of activation functions defined in
- torch.nn, default = None Activation function used in the fully connected output layer. Recommended Callable instance of ‘Sigmoid’, ‘Softmax’, ‘LogSoftmax’, ‘LogSigmoid’, None If None, then no activation function is applied.
- activation_hiddenstr or None or an instance of activation functions defined in
- torch.nn, default = None The activation function applied inside the hidden layers of the MLP. Recommended Callable instance of ‘ReLU’, ‘LeakyReLU’, ‘ELU’, ‘PReLU’, ‘GELU’, ‘SELU’, ‘RReLU’, ‘CELU’, ‘Tanh’, ‘Hardtanh’, None
- biasbool, default = True
- If False, then the layer does not use bias weights.
- dropoutfloat or tuple of floats, default = (0.1, 0.2, 0.2, 0.3)
- If dropout is a non-zero float, it introduces a Dropout layer on the outputs of each hidden layer of the MLP, with dropout probability equal to dropout. If dropout is a tuple of floats, it must have length equal to n_layers, and each element specifies the dropout probability in the corresponding hidden layer of the MLP.
- 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.
- 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 = “Adam” 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 = “CrossEntropyLoss” 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.
Examples
>>> from sktime.regression.deep_learning.mlp import MLPRegressorTorch
>>> 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")
>>> clf = MLPRegressorTorch (n_epochs = 50, batch_size = 2)
>>> clf. fit (X_train, y_train) MLPRegressorTorch(
... )References
- [1 ] (1, 2) Network originally defined in: @inproceedings{wang2017time, title={Time series classification from scratch with deep neural networks: A strong baseline}, author={Wang, Zhiguang and Yan, Weizhong and Oates, Tim}, booktitle={2017 International joint conference on neural networks (IJCNN)}, pages={ 1578–1585}, year={2017}, organization={IEEE} }.. [Ra6642a4e6bf6-2] Deep learning for time series classification: a review Fawaz et al. 2019.. [Ra6642a4e6bf6-3] source code for
- [2] https://github.com/hfawaz/dl-4-tsc/blob/master/classifiers/mlp.py