Skip to main page content
U.S. flag

An official website of the United States government

Dot gov

The .gov means it’s official.
Federal government websites often end in .gov or .mil. Before sharing sensitive information, make sure you’re on a federal government site.

Https

The site is secure.
The https:// ensures that you are connecting to the official website and that any information you provide is encrypted and transmitted securely.

Access keys NCBI Homepage MyNCBI Homepage Main Content Main Navigation
. 2025 Aug 8;15(1):29065.
doi: 10.1038/s41598-025-14129-2.

Optimizing electric vehicle energy consumption prediction through machine learning and ensemble approaches

Affiliations

Optimizing electric vehicle energy consumption prediction through machine learning and ensemble approaches

Izhar Hussain et al. Sci Rep. .

Abstract

Accurately predicting energy consumption in electric vehicles (EVs) is essential for enhancing energy efficiency and improving infrastructure planning. However, this task remains challenging due to the complex interplay of driving conditions, vehicle specifications, and environmental factors. This study proposes a novel data-driven approach that utilizes machine learning (ML) techniques, supported by an extensive real-world dataset derived from Colorado. The research aims to extract meaningful insights from the data using advanced analytical methodologies. This research makes three key advances: (1) systematic comparison of four hyperparameter optimization methods (GridSearchCV, RandomizedSearchCV, Optuna, PSO) for KNN regression, (2) development of a stacking hybrid ensemble combining KNN with tree-based models, and (3) comprehensive validation on real-world data with novel temporal feature engineering. The K-Nearest Neighbors (KNN) algorithm is employed as the base model, with hyperparameter optimization performed using GridSearchCV, RandomizedSearchCV, Optuna, and Particle Swarm Optimization (PSO). Additionally, a stacking hybrid ensemble model is developed to combine the strengths of multiple base models. The results show that the stacking hybrid ensemble model achieves the best performance, with the lowest prediction errors (MAE = 0.645880, RMSE = 1.788540) and the highest accuracy score R² (0.960078). Among the optimization techniques, Optuna proves to be the most effective for tuning the KNN model. This study emphasizes the capabilities of ensemble learning and advanced optimization methods in enhancing the prediction of energy consumption. These results demonstrate that temporal feature extraction and optimized ensemble modeling significantly enhance prediction accuracy, providing EV manufacturers and policymakers with deployable tools for sustainable energy management.

Keywords: Electric vehicles; Energy consumption prediction; Ensemble hybrid models; Hyperparameter tuning; KNN.

PubMed Disclaimer

Conflict of interest statement

Declarations. Competing interests: The authors declare no competing interests. Consent for publication: The authors have full consent for publication. Software and packages used: The SciPy package in Python is used for statistical techniques, including hypothesis testing, probability distributions, and correlation analysis. Additionally, statistical modelling, data analysis, and manipulation, as well as handling dates and times, are accomplished using the statsmodels, NumPy, and pandas packages, along with the DateTime package in Python. This comprehensive data preprocessing and model implementation is conducted using VS Code software.

Figures

Fig. 1
Fig. 1
Schematic overview of the research workflow.
Fig. 2
Fig. 2
Schematic of the stacking ensemble: Base models (KNN, Random Forest, Extra Trees) feed predictions into a meta-learner (Linear Regression).
Fig. 3
Fig. 3
(a) Comparison of actual vs. predicted energy consumption for baseline KNN model showing significant deviations at higher consumption values. (b) Scatter plot reveals systematic under-prediction (slope = 0.82) for values > 15 kWh, with predictions falling outside ± 10% error bounds.
Fig. 4
Fig. 4
(a) Time-series comparison of measured vs. GridSearchCV-tuned KNN predictions showing 34% error reduction versus baseline (b) Scatter plot demonstrates tighter clustering along the y = x line (slope = 0.94) with only 12% outliers beyond ± 7% error bounds.
Fig. 5
Fig. 5
Energy prediction using randomizedSearch-KNN (a) temporal accuracy, (b) scatter validation.
Fig. 6
Fig. 6
Optuna-KNN energy prediction performance (a) Time-series comparison, (b) Measured vs. predicted scatter plot.
Fig. 7
Fig. 7
(a) Measured vs. PSO-tuned predictions revealing limited improvement over baseline. (b) Scatter plot confirming similar performance to baseline KNN.
Fig. 8
Fig. 8
(a) Stacking hybrid ensemble model predictions demonstrate closer alignment with actual values than baseline KNN, particularly for high-consumption cases (> 20 kWh). (b) Near-perfect clustering along the y = x line (slope = 0.98) with only 5% outliers beyond ± 5% error bounds.
Fig. 9
Fig. 9
(a) Residual distribution of KNN. (b) Residual Distribution of GridSearch-KNN. (c) Residual Distribution of RandomizedSearch-KNN. (d) Residual Distribution of Optuna-KNN. (e) Residual Distribution of PSO-KNN. (f) Residual Distribution of Stacking hybrid ensemble model.

Similar articles

References

    1. Lakshmipriya, N., Ayyappan, S. & Gokul, C. Sustainable charging infrastructure for electric vehicles: Harnessing solar and wind energy. Eng. Headw.16, 57–68 (2025).
    1. Dluhopolskyi, O., Kolinets, L., Ivashuk, Y., Lotysh, O. & Sovira, Y. Development of the electric vehicle market with a focus on sustainability. Socio-economic Relations Digit. Soc.4 (54), 5–15 (2024).
    1. Ahmadi, S., Tack, G., Harabor, D., Kilby, P. & Jalili, M. T energy-optimal path planning for electric vehicles. Preprint at https://arXiv.org/abs/2411.12964. (2024).
    1. Zubair, M., Chen, S., Ma, Y., Ping Ong, G. & Pang, Q. Explore driving factors to energy consumption of electric vehicles based on structural equation modeling. International J. Green. Energy, 1–11. (2024).
    1. Skuza, A., Szumska, E. M., Jurecki, R. & Pawelec, A. modeling the impact of traffic parameters on electric vehicle energy consumption. Energies, 17(21), 5423. (2024).

LinkOut - more resources