# A Data-Driven Forecasting Strategy to Predict Continuous Hourly Energy Demand in Smart Buildings
## 3 Methodology and Approach
### Forecasting Models Training, Tunning, and Execution  
The dataset used to train and test the models was split into the years 2016 to 2018 for training and the year 2019 for testing. The models sought to forecast in a 24 h window, so in the training phase, the dataset was prepared to meet this requirement by using a strategy that would allow performing a forecast for each 24 h.  
Before running the models for the 2019 forecast, the calibration of the models was performed which consisted of using the years 2016 and 2017 for training and 2018 for backtesting. This backtesting process was achieved by splitting the year 2018 into fivefold and testing a multi-step strategy using different hours to train the model. After performing this backtesting, the best parameters and architectures were used to train the final model. During the model's training phase, based on the correlation analysis of the climatic variables and the use of the mean decrease impurity (MDI) technique of the RF. Figure 5 shows the results of the RF MDI technique, which was used to analyze which of the selected variables were significant for the models based on the score obtained. Several test runs were performed, which gave the results that the T2M, T2M_MAX, and ALLSKY variables were the ones that showed a slight improvement in the models during the backtesting. For this reason, we only decided to work with the climatic variables that contribute the most to the models. For the tunning process, the following architectures, and individual hyper-parameters (see Table 1) were tested using different Python libraries:  
Figure 5: Random forest feature importance. \begin{table}
\begin{tabular}{c c c c} \hline \hline
**Model** &
\begin{tabular}{c} **Python** \\ **Library** \\ \end{tabular} & \multicolumn{2}{c}{**Architectures and Hyper-Parameters**} \\ \hline MLR & Scikit-learn & \(\bullet\) & Does not have any hyper-parameters. \\  & & \(\bullet\) & hidden\_layer\_sizes = (60, 30) \\ ANN & Scikit-learn & \(\bullet\) & learning\_rate\_init = 0.01 \\  & & \(\bullet\) & learning\_rate = adaptive \\  & & \(\bullet\) & max\_iter = 5000 \\  & & \(\bullet\) & max\_depth = 45 \\ RF & Scikit-learn & \(\bullet\) & n\_estimators = 200 \\  & & \(\bullet\) & min\_samples\_leaf = 1 \\  & & \(\bullet\) & n\_estimators = 200 \\  & & \(\bullet\) & eta = 0.1 \\ XGBoost & Scikit-learn XGBoost & \(\bullet\) & max\_depth = 5 \\  & & \(\bullet\) & colsample\_bytree = 0.8 \\  & & \(\bullet\) & subsample = 0.8 \\  & & \(\bullet\) & gamma = 1 \\  & & & \(\bullet\) & Two LSTM layers with 640 units and linear activation functions. \\  & & \(\bullet\) & batch size = 5 \\ LSTM & TensorFlow & \(\bullet\) & loss function = mean squared error. \\  & & \(\bullet\) & optimizer = adam \\  & & & learning rate = 0.0001 \\  & & & The model with the best epoch in the loss function was selected. \\  & & & \(\bullet\) & Three convolutional hidden layers. \\  & & & First layer: 1D convolution with 512 filters, kernel size = 4, linear activation function, MaxPooling1D of size 2. \\  & & & Second layer: 1D convolution with 256 filters, kernel size = 4, linear activation function, MaxPooling1D of size 2. \\  & & & Third layer: 1D convolution with 256 filters, kernel size = 4, linear activation function. \\ CNN & TensorFlow & \(\bullet\) & One fully connected layer with 200 units and linear activation function. \\  & & & Output layer with 24 units. \\  & & & loss function = mean squared error \\  & & & optimizer = adam \\  & & & learning rate = 0.001 \\  & & & batch size = 5 \\  & & & The model with the best epoch in the loss function was selected. \\  & & & filters = 400 \\  & & & kernel\_size = 4 \\  & & & dilations = [1,2,4,8,16,32] \\  & & & batch size = 5 \\ TCN & TensorFlow & \(\bullet\) & activation function = linear \\  & & & loss function = mean squared error \\  & & & optimizer = adam. \\  & & & learning rate = 0.0001. \\  & & & The model with the best epoch in the loss function was selected. \\ \hline \hline \end{tabular}
\end{table}