ForeTiS.model.lstm

Module Contents

Classes

LSTM

Implementation of a class for a Long Short-Term Memory (LSTM) network.

class ForeTiS.model.lstm.LSTM(optuna_trial, datasets, featureset_name, optimize_featureset, pca_transform=None, current_model_name=None, batch_size=None, n_epochs=None, target_column=None)

Bases: ForeTiS.model._torch_model.TorchModel

Implementation of a class for a Long Short-Term Memory (LSTM) network.

See BaseModel and TorchModel for more information on the attributes.

Parameters:
  • optuna_trial (optuna.trial.Trial) –

  • datasets (list) –

  • featureset_name (str) –

  • optimize_featureset (bool) –

  • pca_transform (bool) –

  • current_model_name (str) –

  • batch_size (int) –

  • n_epochs (int) –

  • target_column (str) –

define_model()

Definition of a LSTM network.

Architecture:
  • LSTM, Dropout, Linear

  • Linear output layer

Number of output channels of the first layer, dropout rate, frequency of a doubling of the output channels and number of units in the first linear layer. may be fixed or optimized.

Return type:

torch.nn.Sequential

define_hyperparams_to_tune()

See BaseModel for more information on the format.

See TorchModel for more information on hyperparameters common for all torch models.

Return type:

dict

train_val_loader(train, val)

Get the Dataloader with training and validation data

Poram train:

training data

Parameters:
  • val (pandas.DataFrame) – validation data

  • train (pandas.DataFrame) –

Returns:

train_loader, val_loader, val

predict(X_in)

Implementation of a prediction based on input features for PyTorch models. See BaseModel for more information

Parameters:

X_in (pandas.DataFrame) –

Return type:

numpy.array

get_dataloader(X, y=None, only_transform=None, predict=False, shuffle=False)

Get a Pytorch DataLoader using the specified data and batch size

Parameters:
  • X (numpy.array) – feature matrix to use

  • y (numpy.array) – optional target vector to use

  • only_transform (bool) – whether to only transform or not

  • predict (bool) – weather to use the data for predictions or not

  • shuffle (bool) – shuffle parameter for DataLoader

Returns:

Pytorch DataLoader

Return type:

torch.utils.data.DataLoader

create_sequences(X, y)

Create sequenced data according to self.seq_length

Returns:

sequenced data and labels

Parameters:
  • X (numpy.array) –

  • y (numpy.array) –

Return type:

tuple