epftoolbox.models.DNN

class epftoolbox.models.DNN(experiment_id, path_hyperparameter_folder='./experimental_files', nlayers=2, dataset='PJM', years_test=2, shuffle_train=1, data_augmentation=0, calibration_window=4)[source]

DNN for electricity price forecasting.

It considers a set of best hyperparameters, it recalibrates a DNNModel based on these hyperparameters, and makes new predictions.

The difference w.r.t. the DNNModel class lies on the functionality. The DNNModel class provides a simple interface to build a keras DNN model which is limited to fit and predict methods. This class extends the functionality by providing an interface to extract the best set of hyperparameters, and to perform recalibration before every prediction.

Note that before using this class, a hyperparameter optimization run must be done using the hyperparameter_optimizer function. Such hyperparameter optimization must be done using the same parameters: nlayers, dataset, years_test, shuffle_train, data_augmentation, and calibration_window

An example on how to use this class is provided here.

Parameters:
  • experiment_id (str) – Unique identifier to read the trials file. In particular, every hyperparameter optimization set has an unique identifier associated with. See hyperparameter_optimizer for further details
  • path_hyperparameter_folder (str, optional) – Path of the folder containing the trials file with the optimal hyperparameters
  • nlayers (int, optional) – Number of layers of the DNN model
  • dataset (str, optional) – Name of the dataset/market under study. If it is one one of the standard markets, i.e. "PJM", "NP", "BE", "FR", or "DE", the dataset is automatically downloaded. If the name is different, a dataset with a csv format should be place in the path_datasets_folder.
  • years_test (int, optional) – Number of years (a year is 364 days) in the test dataset. This is necesary to extract the correct hyperparameter trials file
  • shuffle_train (bool, optional) – Boolean that selects whether the validation and training datasets were shuffled when performing the hyperparameter optimization. Note that it does not select whether shuffling is used for recalibration as for recalibration the validation and the training datasets are always shuffled.
  • data_augmentation (bool, optional) – Boolean that selects whether a data augmentation technique for electricity price forecasting is employed
  • calibration_window (int, optional) – Number of days used in the training/validation dataset for recalibration

Methods

predict(X) Method that makes a prediction using some given inputs
recalibrate(Xtrain, Ytrain, Xval, Yval) Method that recalibrates the model.
recalibrate_and_forecast_next_day(df, …) Method that builds an easy-to-use interface for daily recalibration and forecasting of the DNN model
recalibrate_predict(Xtrain, Ytrain, Xval, …) Method that first recalibrates the DNN model and then makes a prediction.
predict(X)[source]

Method that makes a prediction using some given inputs

Parameters:X (numpy.array) – Input of the model
Returns:An array containing the predictions
Return type:numpy.array
recalibrate(Xtrain, Ytrain, Xval, Yval)[source]

Method that recalibrates the model.

The method receives the training and validation dataset, and trains a DNNModel model using the set of optimal hyperparameters that are found in path_hyperparameter_folder and that are defined by the class attributes: experiment_id, nlayers, dataset, years_test, shuffle_train, data_augmentation, and calibration_window

Parameters:
  • Xtrain (numpy.array) – Input of the training dataset
  • Xval (numpy.array) – Input of the validation dataset
  • Ytrain (numpy.array) – Output of the training dataset
  • Yval (numpy.array) – Output of the validation dataset
recalibrate_and_forecast_next_day(df, next_day_date)[source]

Method that builds an easy-to-use interface for daily recalibration and forecasting of the DNN model

The method receives a pandas dataframe df and a day next_day_date. Then, it recalibrates the model using data up to the day before next_day_date and makes a prediction for day next_day_date.

Parameters:
  • df (pandas.DataFrame) – Dataframe of historical data containing prices and N exogenous inputs. The index of the dataframe should be dates with hourly frequency. The columns should have the following names [‘Price’, ‘Exogenous 1’, ‘Exogenous 2’, …., ‘Exogenous N’]
  • next_day_date (TYPE) – Date of the day-ahead
Returns:

An array containing the predictions in the provided date

Return type:

numpy.array

recalibrate_predict(Xtrain, Ytrain, Xval, Yval, Xtest)[source]

Method that first recalibrates the DNN model and then makes a prediction.

The method receives the training and validation dataset, and trains a DNNModel model using the set of optimal hyperparameters. Then, using the inputs of the test dataset, it makes a new prediction.

Parameters:
  • Xtrain (numpy.array) – Input of the training dataset
  • Xval (numpy.array) – Input of the validation dataset
  • Xtest (numpy.array) – Input of the test dataset
  • Ytrain (numpy.array) – Output of the training dataset
  • Yval (numpy.array) – Output of the validation dataset
Returns:

An array containing the predictions in the test dataset

Return type:

numpy.array