:py:mod:`ForeTiS.model._torch_model` ==================================== .. py:module:: ForeTiS.model._torch_model Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: ForeTiS.model._torch_model.TorchModel .. py:class:: TorchModel(optuna_trial, datasets, featureset_name, optimize_featureset, pca_transform = None, current_model_name = None, batch_size = None, n_epochs = None, target_column = None) Bases: :py:obj:`ForeTiS.model._base_model.BaseModel`, :py:obj:`abc.ABC` Parent class based on :obj:`~ForeTiS.model._base_model.BaseModel` for all PyTorch models to share functionalities. See :obj:`~ForeTiS.model._base_model.BaseModel` for more information. *Attributes* *Inherited attributes* See :obj:`~ForeTiS.model._base_model.BaseModel`. *Additional attributes* - batch_size (*int*): Batch size for batch-based training - n_epochs (*int*): Number of epochs for optimization - num_monte_carlo (*int*): Number of monte carlo iteration for the bayesian neural networks - optimizer (*torch.optim.optimizer.Optimizer*): optimizer for model fitting - loss_fn: loss function for model fitting - early_stopping_patience (*int*): epochs without improvement before early stopping - early_stopping_point (*int*): epoch at which early stopping occured - device (*torch.device*): device to use, e.g. GPU - X_scaler (*sklearn.preprocessing.StandardScaler*): Standard scaler for the X data :param optuna_trial: Trial of optuna for optimization :param datasets: all datasets that are available :param current_model_name: name of the current model according to naming of .py file in package model :param batch_size: batch size for neural network models :param n_epochs: number of epochs for neural network models :param target_column: the target column for the prediction .. py:method:: train_val_loop(train, val) Implementation of a train and validation loop for PyTorch models. See :obj:`~ForeTiS.model._base_model.BaseModel` for more information .. py:method:: train_val_loader(train, val) Get the Dataloader with training and validation data :poram train: training data :param val: validation data :return: train_loader, val_loader, val .. py:method:: train_one_epoch(train_loader, scaler) Train one epoch :param train_loader: DataLoader with training data .. py:method:: validate_one_epoch(val_loader) Validate one epoch :param val_loader: DataLoader with validation data :return: loss based on loss-criterion .. py:method:: retrain(retrain) Implementation of the retraining for PyTorch models. See :obj:`~ForeTiS.model._base_model.BaseModel` for more information .. py:method:: update(update, period) Implementation of the retraining for PyTorch models. See :obj:`~ForeTiS.model._base_model.BaseModel` for more information .. py:method:: predict(X_in) Implementation of a prediction based on input features for PyTorch models. See :obj:`~ForeTiS.model._base_model.BaseModel` for more information .. py:method:: get_loss(outputs, targets) Calculate the loss based on the outputs and targets :param outputs: outputs of the model :param targets: targets of the dataset :return: loss .. py:method:: get_dataloader(X, y = None, only_transform = None, predict = False, shuffle = False) Get a Pytorch DataLoader using the specified data and batch size :param X: feature matrix to use :param y: optional target vector to use :param only_transform: whether to only transform or not :param predict: weather to use the data for predictions or not :param shuffle: shuffle parameter for DataLoader :return: Pytorch DataLoader .. py:method:: common_hyperparams() :staticmethod: Add hyperparameters that are common for PyTorch models. Do not need to be included in optimization for every child model. Also See :obj:`~ForeTiS.model._base_model.BaseModel` for more information .. py:method:: get_torch_object_for_string(string_to_get) :staticmethod: Get the torch object for a specific string, e.g. when suggesting to optuna as hyperparameter :param string_to_get: string to retrieve the torch object :return: torch object