ResNetRegressorTorch
ResNetRegressorTorch
- class ResNetRegressorTorch(n_filters: tuple[int, ...] = (64, 128, 128), kernel_size: tuple[int, ...] = (8, 5, 3), activation: str | Callable | None = None, activation_hidden: str | Callable = 'ReLU', init_weights: bool = True, 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)[source]
Residual neural network regressor in PyTorch, as described in [1].
Adapted from the implementation from source code https://github.com/hfawaz/dl-4-tsc/blob/master/classifiers/resnet.py
- Parameters:
- n_filterstuple of int, default = (64, 128, 128)
Number of convolutional filters in each residual block. The length of this tuple determines the number of residual blocks. Any length >= 1 is allowed.
- kernel_sizetuple of int, default = (8, 5, 3)
Length of the 1D convolution window for the conv layers within a residual block, shared across all residual blocks. Any length >= 1 is allowed.
- 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 intorch.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 validtorch.nnactivation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearitytorch.nn.Module: an instance of atorch.nn.Modulesubclass, for exampletorch.nn.ReLU(). Arbitrary callables are not supported.
- activation_hiddenstr, Callable, or None, default=”ReLU”
Activation applied to the hidden layers, and after each residual connection.
Permitted values:
None: no activation is applied to the hidden layers.str: name of a class intorch.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 validtorch.nnactivation; see https://pytorch.org/docs/stable/nn.html#non-linear-activations-weighted-sum-nonlinearitytorch.nn.Module: an instance of atorch.nn.Modulesubclass, for exampletorch.nn.ReLU(). Arbitrary callables are not supported.
- init_weightsbool, default = True
Whether to apply custom initialization to the weights.
- 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.
- Attributes:
is_fittedWhether
fithas been called.
References
[1]Wang et al, Time series classification from scratch with deep neural
networks: A strong baseline, International joint conference on neural networks (IJCNN), 2017.
Examples
>>> from sktime.regression.deep_learning.resnet import ResNetRegressorTorch >>> 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 = ResNetRegressorTorch(num_epochs=20, batch_size=4) >>> reg.fit(X_train, y_train) ResNetRegressorTorch(...)
Methods
check_is_fitted([method_name])Check if the estimator has been fitted.
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
fit(X, y)Fit time series regressor to training data.
get_class_tag(tag_name[, tag_value_default])Get class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
get_fitted_params([deep])Get fitted parameters.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get a dict of parameters values for this object.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params([parameter_set])Return testing parameter settings for the estimator.
is_composite()Check if the object is composed of other BaseObjects.
load_from_path(serial)Load object from file location.
load_from_serial(serial)Load object from serialized memory container.
predict(X)Predicts labels for sequences in X.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
score(X, y[, multioutput])Scores predicted labels against ground truth labels on X.
set_config(**config_dict)Set config flags to given values.
set_params(**params)Set the parameters of this object.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.

