# Optimizing Energy Forecasting Using ANN and RF Models for HVAC and Heating Predictions
## 4 Conclusions  
The research gap was addressed through this study as it compared the performance of Artificial Neural Network (ANN) and Random Forest (RF) models with the nature of their building energy predictions for HVAC and heating demand levels in near-zero-energy buildings (nZEB) and traditional buildings across a range of regional climates in Spain to meet the demands of predicting energy levels in nZEBs in Spain. It was evidenced that \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Metric** & **Lucia ANN** & **Lucia RF** & **FUHEM ANN** & **FUHEM RF** \\ \hline Mean Absolute Percentage Error (MAPE) & 3.6727\% & 4.3733\% & 0.0207\% & 0.5426\% \\ \hline Root Mean Squared Error Percentage (RMSPE) & 11.4334\% & 14.1956\% & 0.1004\% & 2.0903\% \\ \hline Mean Absolute Relative Percentage Error (MARPE) & 3.562\% & 6.1\% & 0.0033\% & 0.0468\% \\ \hline Root Mean Squared Relative Error (RMSRE) & 20.12\% & 24.56\% & 0.0055\% & 0.00796\% \\ \hline Correlation with Actual Demand & 0.9627 & 0.9445 & 1 & 0.9948 \\ \hline KGE & 0.9373 & 0.7501 & 0.9872 & 0.7401 \\ \hline NSE & 0.9267 & 0.8870 & 0.9998 & 0.9316 \\ \hline R-Squared (R\({}^{2}\)) & 0.9267 & 0.8870 & 0.9998 & 0.9316 \\ \hline Training Set R-Value & 0.9774 & - & 1 & - \\ \hline Validation Set R-Value & 0.97171 & - & 1 & - \\ \hline Test Set R-Value & 0.96979 & - & 1 & - \\ \hline Training Time & 40 s & 2.8 s & 1.1 s & 0.3 s \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Evaluation of ANN and Random Forest models in energy demand forecasting. the ANN consistently outperformed the RF in predicting energy demand for nZEBs and heating demands whilst the RF advertently underestimated peak demands. The prediction performance of the ANN turned out to be more consistent with real demand levels and showed a high correlation with real demand (R\({}^{2}\approx 1.0\)) with low error metrics like MAPE and RMSPE to demonstrate the superiority of its accuracy. However, this comes at the cost of longer training times; the Lucia ANN required 40 s compared to Lucia RF's 2.8 s, and the FUHEM ANN took 1.1 s versus FUHEM RF's 0.3 s. Despite the computational trade-off, the ANN's precision makes it a more reliable choice for high-stakes forecasting in energy management. This advancement of the ANN in predicting energy demands for nZEBs now helps support a framework for using AI-driven predictions in Industry 5.0 and complements the sustainability goals of energy performance and efficiency focused on improving energy performance in residential buildings. By implementing a MATLAB-based framework with real-world data from Spanish case studies (LUCIA, FUHEM), this work fills a critical gap in the energy forecasting literature. This study not only validates the ANN's robustness across diverse climates and building characteristics, but also highlights its adaptability for practical energy management applications. The comprehensive evaluation, including metrics such as KGE, NSE, and R\({}^{2}\), reinforces the ANN's reliability in capturing complex nonlinear demand patterns. In contrast, the RF, while competent, shows limitations in peak demand prediction and slight overfitting during validation, making the ANN the preferred choice for high-accuracy forecasting tasks. The results have significant implications for energy management in Spanish households, particularly in optimizing HVAC systems for nZEBs. The ANN's ability to model real demand behavior with minimal error makes it a valuable tool for policymakers and energy managers seeking to enhance efficiency and reduce environmental impact. Using datasets for AI modeling comes with notable challenges, such as the quality of the data itself, decisions related to normalization that can produce distortion, and computational complexity and explainable limitations.