# Optimizing Energy Forecasting Using ANN and RF Models for HVAC and Heating Predictions
## 2 Methodology
### Optimization Procedures
\begin{table}
\begin{tabular}{c c c} \hline \hline
**Component** & **Equation** & **NO. Equation** \\ \hline Root Mean Square Percentage Error (RMSPE) & RMSPE \(=\)\(\sqrt{\frac{1}{N}\sum\limits_{i=1}^{N}{(y_{i}-\widehat{y}_{i})}^{2}}\times 100\) & (12) \\ Root Mean Square Relative Percentage Error (RMSPE): & RMSRPE \(=\)\(\sqrt{\frac{1}{N}\sum\limits_{i=1}^{N}{\left(\frac{(y_{i}-\widehat{y}_{i})}{y_{i}} \right)}^{2}}\times 100\) & (13) \\ Mean Absolute Percentage Error (MAPE) & MAPE \(=\)\(\frac{1}{N}\sum\limits_{i=1}^{N}{\left|y_{i}-\widehat{y}_{i}\right|}\times 100\) & (14) \\ Mean Absolute Relative Percentage Error (MARPE) & MAPPE \(=\)\(\frac{1}{N}\sum\limits_{i=1}^{N}{\left|\frac{y_{i}-\widehat{y}_{i}}{y_{i}} \right|}\times 100\) & (15) \\ Kling–Gupta Efficiency (KGE) & KGE \(=\)\(1-\sqrt{\left(r-1\right)^{2}+\left(\frac{\sigma_{\text{model}}}{\sigma_{\text{ obs}}}-1\right)^{2}+\left(\frac{\mu_{\text{model}}}{\mu_{\text{obs}}}-1\right)^{2}}\) & (16) \\ Nash–Sutcliffe Efficiency (NSE) & NSE \(=\)\(1-\frac{\sum\limits_{i=1}^{N}{\left(y_{i}-\widehat{y}_{i}\right)}^{2}}{\sum \limits_{i=1}^{N}{\left(y_{i}-\widehat{y}\right)}^{2}}\) & (17) \\ Coefficient of Determination (R\({}^{2}\)) & R\({}^{2}\)\(=\)\(1-\frac{\sum\limits_{i=1}^{N}{\left(y_{i}-\widehat{y}_{i}\right)}^{2}}{\sum \limits_{i=1}^{N}{\left(y_{i}-\widehat{y}\right)}^{2}}\) & (18) \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Evaluation metrics equation. Error (MSE) for regression tasks, helps minimize prediction variance, making it effective for continuous targets. Additionally, using the 'Bag' method in fitensemble implements bootstrap aggregating, which enhances model stability by averaging predictions from multiple trees built on different samples of the data, further reducing the risk of overfitting. The block diagram focused on the complex relationship between these elements and their collective impact on energy demand trends, as shown in Figure 3. The Levenberg-Marquardt (LM) algorithm is a popular optimization technique used in Artificial Neural Networks (ANNs) for training due to its efficiency in minimizing the error function. It combines the advantages of gradient descent and the Gauss-Newton method, making it particularly effective for nonlinear least squares problems. By adapting the learning rate dynamically, LM accelerates convergence and is especially useful when dealing with small-to-medium-sized datasets, where it can outperform other methods in terms of speed and accuracy. In contrast, Random Forest with Bayesian inference enhances model robustness by leveraging the strengths of ensemble learning and probabilistic modeling. This approach allows for the integration of uncertainty into predictions, making it ideal for complex datasets with high dimensionality and noise. The Bayesian framework provides a way to quantify uncertainty and improves the interpretability of model predictions, which is crucial in applications requiring reliable decision making. The steps for the optimization procedure method are given below [58,59]:  
1. Split the dataset into three parts: 70% for training, 15% for validation, and 15% for testing. 2. Choose the network architecture and set the training parameters. 3. Train the model with the training dataset. 4. Validate the model's performance using the validation dataset. 5. Iterate steps 2 to 4, experimenting with various architectures and training settings. 6. Identify the optimal network architecture based on validation results. 7. Evaluate the selected final model using the test dataset to assess its performance. Figure 3: Block diagram for analyzing energy demand: ANN vs. Random Forest.