Modeling and forecasting of electricity energy consumption using an optimized Stacking ensemble machine learning model based on particle swarm optimization

Document Type : Original Article

Authors

1 PhD Candidate, Department of Energy Conversion, Faculty of 1 M.Sc. Student in Energy Systems Engineering, Department of Energy Engineering and Physics, Amirkabir University of Technology, Tehran, Iran

2 Master of Business Administration, Department of Management and Accounting, Allameh Tabataba’i University, Tehran, Iran

3 Assistant Professor, Department of Renewable Energy Engineering, Faculty of Energy Engineering, Shahid Beheshti University, Tehran, Iran

10.22059/ses.2026.412276.1222

Abstract

In this study, a data-driven framework is developed to model  and forecast electricity energy consumption (EEC) in countries with diverse economic, social, and climate characteristics. Five input variables including population (POP), gross domestic product (GDP), energy imports (IMP), energy exports (EXP), and annual average air temperature (TEMP) are used to model EEC. Annual data from 1991 to 2020 are employed for training and evaluation. Four machine learning algorithms, namely ANN, Ridge, Stack, and Stack-PSO, are implemented and assessed using MSE, MAE, R2, and MAPE. The results show that while the standalone ANN and Ridge models achieve acceptable accuracy, they exhibit lower stability and weaker generalization compared with ensemble-based approaches. The Stack model, constructed by combining the outputs of ANN and Ridge, yields noticeable improvements across the error metrics. The results demonstrated that the Stack-PSO model consistently outperformed the other models across the majority of cases. The R2 values for this model ranged from 0.974 to 0.997 across the surveyed countries. The lowest MSE was recorded for China at 0.00015, while for Iran, the Stack-PSO model achieved an MSE of 0.00042 and an R2 of 0.996. Furthermore, the lowest MAPE was observed in the United States at 2.5%, underscoring the high precision of the proposed model in minimizing forecasting errors. Subsequently, the superior model was employed to forecast electrical energy consumption up to the 2035 horizon. The findings indicate a generally increasing consumption trend in most countries; however, growth intensity varied significantly, with some cases exhibiting a moderate growth pattern or approaching relative stability.

Keywords

Main Subjects


  • A. Hamedani, P. Khodaparast, E. Hosseini, T. Mahmudy, and A. B. Yajloo, "A mini-review of energy hub: Concept, components, classifications, and applications," Energy Reports, vol. 15, p. 108886, 2026, doi: https://doi.org/10.1016/j.egyr.2025.12.023.
  • Gajdzik, R. Wolniak, R. Nagaj, B. Žuromskaitė-Nagaj, and W. W. Grebski, "The influence of the global energy crisis on energy efficiency: A comprehensive analysis," Energies, vol. 17, no. 4, p. 947, 2024, doi: https://doi.org/10.3390/en17040947.
  • Abbasian Hamedani, A. Bahrami Yajloo, and S. Talebi, "A comprehensive review on carbon capture, transportation, storage, and utilization technologies; part Ⅰ: Carbon capture technologies," Advances in Energy Sciences and Technologies, vol. 1, no. 1, pp. 119–132, 2025, doi: https://doi.org/10.22060/aest.2025.5755.
  • Mokhtari, N. Mirzaei, S. Ebrahimi Zaker, and M. Abdoos, "Multi-Criteria GIS Analysis of Solar Energy Deployment in Alborz Province: A Case Study on 10 MW PV Plant Siting and Environmental Impact," Journal of sustainable Energy Systems, vol. 5, no. 1, pp. 107–119, 2026, doi: 10.22059/ses.2025.394064.1138.
  • B. Yajloo and E. A. Hamedani, "Simulation of a solar-based small-scale green hydrogen production unit in Iran: A techno-economic-feasibility analysis," Results in Engineering, p. 106734, 2025, doi: https://doi.org/10.1016/j.rineng.2025.106734.
  • Köse and S. Kutlu Kaynar, "Energy Demand Forecasting and Policy Development in Turkey," Energies, vol. 18, no. 13, p. 3301, 2025, doi: https://doi.org/10.3390/en18133301.
  • B. Yajloo, S. Setayeshi, M. Hosseinpour, and M. Fakhroleslam, "Superstructure optimization of sustainable formic acid synthesis from hydrogen and carbon dioxide: a scenario-based approach," Journal of Cleaner Production, vol. 555, p. 148048, 2026, doi: https://doi.org/10.1016/j.jclepro.2026.148048.
  • "IEA (2024), Electricity 2024, IEA, Paris https://www.iea.org/reports/electricity-2024, Licence: CC BY 4.0." (accessed.
  • "IEA (2025), Electricity Mid-Year Update 2025, IEA, Paris https://www.iea.org/reports/electricity-mid-year-update-2025, Licence: CC BY 4.0."
  • A. Hamedani, A. R. Araghi, A. Hajinezhad, and H. Yousefi, "A Scenario-Based Techno-Economic Optimization Framework for Power-to-X Residential Energy Hubs Across Diverse Climate Conditions," Energy, p. 141155, 2026.
  • Gulaydin and M. Mourshed, "Machine learning for subnational residential electricity demand forecasting to 2050 under shared socioeconomic pathways: Comparing tree-based, neural and kernel methods," Energy, p. 138195, 2025, doi: https://doi.org/10.1016/j.energy.2025.138195.
  • M. Alam, S. Aryal, and Q. K. Hassan, "Shifting Electricity Demand Under Temperature Extremes in Bangladesh," Earth, vol. 6, no. 4, p. 127, 2025, doi: https://doi.org/10.3390/earth6040127.
  • Hasan et al., "A state-of-the-art comparative review of load forecasting methods: Characteristics, perspectives, and applications," Energy Conversion and Management: X, p. 100922, 2025, doi: https://doi.org/10.1016/j.ecmx.2025.100922.
  • W. Chan and C. K. Yeo, "A transformer based approach to electricity load forecasting," The Electricity Journal, vol. 37, no. 2, p. 107370, 2024, doi: https://doi.org/10.1016/j.tej.2024.107370.
  • Eren and İ. Küçükdemiral, "A comprehensive review on deep learning approaches for short-term load forecasting," Renewable and Sustainable Energy Reviews, vol. 189, p. 114031, 2024, doi: https://doi.org/10.1016/j.rser.2023.114031.
  • Rezaeifard and Y. Noorollahi, "A Forecast on Natural Gas Consumption in Iran until 2042 Utilizing the ARIMA Model," Journal of sustainable Energy Systems, vol. 4, no. 2, pp. 197–211, 2025, doi: 10.22059/ses.2025.389042.1116.
  • Zhou, "The effect of smart meter penetration on dynamic electricity pricing: Evidence from the United States," The Electricity Journal, vol. 34, no. 3, p. 106919, 2021, doi: https://doi.org/10.1016/j.tej.2021.106919.
  • Tarmanini, N. Sarma, C. Gezegin, and O. Ozgonenel, "Short term load forecasting based on ARIMA and ANN approaches," Energy Reports, vol. 9, pp. 550–557, 2023, doi: https://doi.org/10.1016/j.egyr.2023.01.060.
  • A. M. Cruz, L. A. H. Armenta, and M. Badaoui, "Seasonal Forecasting of Peak Electricity Demand Using Spectral Analysis," Results in Engineering, p. 107338, 2025, doi: https://doi.org/10.1016/j.rineng.2025.107338.
  • Kamani and M. Ardehali, "Long-term forecast of electrical energy consumption with considerations for solar and wind energy sources," Energy, vol. 268, p. 126617, 2023, doi: https://doi.org/10.1016/j.energy.2023.126617.
  • H. A. Kaboli, J. Selvaraj, and N. Rahim, "Long-term electric energy consumption forecasting via artificial cooperative search algorithm," Energy, vol. 115, pp. 857–871, 2016, doi: https://doi.org/10.1016/j.energy.2016.09.015.
  • H. Wolpert, "Stacked generalization," Neural networks, vol. 5, no. 2, pp. 241–259, 1992, doi: https://doi.org/10.1016/S0893-6080(05)80023-1.
  • D. Mienye and Y. Sun, "A survey of ensemble learning: Concepts, algorithms, applications, and prospects," Ieee Access, vol. 10, pp. 99129–99149, 2022, doi: 10.1109/ACCESS.2022.3207287.
  • Wood, T. Mu, A. M. Webb, H. W. Reeve, M. Luján, and G. Brown, "A unified theory of diversity in ensemble learning," Journal of machine learning research, vol. 24, no. 359, pp. 1–49, 2023.
  • G. Dietterich, "An experimental comparison of three methods for constructing ensembles of decision trees: Bagging, boosting, and randomization," Machine learning, vol. 40, no. 2, pp. 139–157, 2000, doi: https://doi.org/10.1023/A:1007607513941.
  • Shi, C. Li, and X. Yan, "Artificial intelligence for load forecasting: A stacking learning approach based on ensemble diversity regularization," Energy, vol. 262, p. 125295, 2023, doi: https://doi.org/10.1016/j.energy.2022.125295.
  • Abbas, Y. Che, and I. U. Khan, "A Novel Stacked Ensemble Framework with the Kolmogorov-Arnold Network for Short-Term Electric Load Forecasting," Energy, p. 137216, 2025, doi: https://doi.org/10.1016/j.energy.2025.137216.
  • Reddy, S. Akashdeep, R. Harshvardhan, and S. Kamath, "Stacking Deep learning and Machine learning models for short-term energy consumption forecasting," Advanced Engineering Informatics, vol. 52, p. 101542, 2022, doi: https://doi.org/10.1016/j.aei.2022.101542.
  • A. Khairalla, X. Ning, N. T. Al-Jallad, and M. O. El-Faroug, "Short-term forecasting for energy consumption through stacking heterogeneous ensemble learning model," Energies, vol. 11, no. 6, p. 1605, 2018, doi: https://doi.org/10.3390/en11061605.
  • Mohan and N. Pachauri, "An ensemble model for the energy consumption prediction of residential buildings," Energy, vol. 314, p. 134255, 2025, doi: https://doi.org/10.1016/j.energy.2024.134255.
  • Zupan, "Introduction to artificial neural network (ANN) methods: what they are and how to use them," Acta Chimica Slovenica, vol. 41, no. 3, p. 327, 1994.
  • M. Haddadi and H. Hamidi, "A hybrid model for improving customer lifetime value prediction using stacking ensemble learning algorithm," Computers in Human Behavior Reports, vol. 18, p. 100616, 2025, doi: https://doi.org/10.1016/j.chbr.2025.100616.
  • A. Hamedani and S. Talebi, "Modeling and long-term forecasting of CO2 emissions in Asia: An optimized Artificial Neural Network approach with consideration of renewable energy scenarios," Energy Conversion and Management: X, vol. 26, p. 101030, 2025, doi: https://doi.org/10.1016/j.ecmx.2025.101030.
  • Bahrami Yajloo, E. Abbasian Hamedani, P. Maleki, and M. Hosseinpour, "Optimization of economic dispatch for distributed generation-based power networks," Advances in Energy Sciences and Technologies, vol. 1, no. 3, pp. 266–279, 2025.
  • Liu, W. Jiao, Z. Huang, J. Yu, X. Zhang, and L. Li, "A short-term load forecasting framework for air conditioning system based on model stacking," Scientific Reports, vol. 15, no. 1, p. 36892, 2025, doi: https://doi.org/10.1038/s41598-025-20929-3.
  • K. Paul et al., "Wavelet decomposition and machine learning technique for predicting occurrence of spiders in pigeon pea," Agronomy, vol. 12, no. 6, p. 1429, 2022, doi: https://doi.org/10.3390/agronomy12061429.
  • Şener, M. A. Koç, and K. Ermiş, "Hybrid ANFIS-PSO algorithm for estimation of the characteristics of porous vacuum preloaded air bearings and comparison performance of the intelligent algorithm with the ANN," Engineering Applications of Artificial Intelligence, vol. 128, p. 107460, 2024, doi: https://doi.org/10.1016/j.engappai.2023.107460.
  • Nouri, A. Lachheb, and L. El Amraoui, "Optimizing efficiency of Vehicle-to-Grid system with intelligent management and ANN-PSO algorithm for battery electric vehicles," Electric Power Systems Research, vol. 226, p. 109936, 2024.