epftoolbox.models.DNNModel

class epftoolbox.models.DNNModel(neurons, n_features, outputShape=24, dropout=0, batch_normalization=False, lr=None, verbose=False, epochs_early_stopping=40, scaler=None, loss='mae', optimizer='adam', activation='relu', initializer='glorot_uniform', regularization=None, lambda_reg=0)[source]

Basic DNN model based on keras and tensorflow.

The model can be used standalone to train and predict a DNN using its fit/predict methods. However, it is intended to be used within the hyperparameter_optimizer method and the DNN class. The former obtains a set of best hyperparameter using the DNNModel class. The latter employes the set of best hyperparameters to recalibrate a DNNModel object and make predictions.

Parameters:
  • neurons (list) – List containing the number of neurons in each hidden layer. E.g. if len(neurons) is 2, the DNN model has an input layer of size n_features, two hidden layers, and an output layer of size outputShape.
  • n_features (int) – Number of input features in the model. This number defines the size of the input layer.
  • outputShape (int, optional) – Default number of output neurons. It is 24 as it is the default in most day-ahead markets.
  • dropout (float, optional) – Number between [0, 1] that selects the percentage of dropout. A value of 0 indicates no dropout.
  • batch_normalization (bool, optional) – Boolean that selects whether batch normalization is considered.
  • lr (float, optional) – Learning rate for optimizer algorithm. If none provided, the default one is employed (see the keras documentation for the default learning rates of each algorithm).
  • verbose (bool, optional) – Boolean that controls the logs. If set to true, a minimum amount of information is displayed.
  • epochs_early_stopping (int, optional) – Number of epochs used in early stopping to stop training. When no improvement is observed in the validation dataset after epochs_early_stopping epochs, the training stops.
  • scaler (epftoolbox.data.DataScaler, optional) – Scaler object to invert-scale the output of the neural network if the neural network is trained with scaled outputs.
  • loss (str, optional) – Loss to be used when training the neural network. Any of the regression losses defined in keras can be used.
  • optimizer (str, optional) –

    Name of the optimizer when training the DNN. See the keras documentation for a list of optimizers.

  • activation (str, optional) –

    Name of the activation function in the hidden layers. See the keras documentation for a list of activation function.

  • initializer (str, optional) –

    Name of the initializer function for the weights of the neural network. See the keras documentation for a list of initializer functions.

  • regularization (None, optional) – Name of the regularization technique. It can can have three values 'l2' for l2-norm regularization, 'l1' for l1-norm regularization, or None for no regularization .
  • lambda_reg (int, optional) – The weight for regulization if regularization is 'l2' or 'l1'.

Methods

clear_session() Method to clear the tensorflow session.
fit(trainX, trainY, valX, valY) Method to estimate the DNN model.
predict(X) Method to make a prediction after the DNN is trained.
clear_session()[source]

Method to clear the tensorflow session.

It is used in the DNN class during recalibration to avoid RAM memory leakages. In particular, if the DNN is retrained continuosly, at each step tensorflow slightly increases the total RAM usage.

fit(trainX, trainY, valX, valY)[source]

Method to estimate the DNN model.

Parameters:
  • trainX (numpy.array) – Inputs fo the training dataset.
  • trainY (numpy.array) – Outputs fo the training dataset.
  • valX (numpy.array) – Inputs fo the validation dataset used for early-stopping.
  • valY (numpy.array) – Outputs fo the validation dataset used for early-stopping.
predict(X)[source]

Method to make a prediction after the DNN is trained.

Parameters:X (numpy.array) – Input to the DNN. It has to be of size [n, n_features] where n can be any integer, and n_features is the attribute of the DNN representing the number of input features.
Returns:Output of the DNN after making the prediction.
Return type:numpy.array