Electric vehicle energy consumption prediction method for optimizing XGBoost parameters based on improved whale algorithm
By improving the whale algorithm to optimize the parameters of the XGBoost model, and combining nonlinear time-varying convergence factor, Cat chaotic mapping and cross-sectional strategy, the problem of parameter setting for electric vehicle energy consumption prediction model is solved, achieving high-precision prediction and interpretable analysis, and providing guidance for energy-saving driving.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-24
- Publication Date
- 2026-04-07
AI Technical Summary
Existing electric vehicle energy consumption prediction models are difficult to set parameters, have high computational costs, insufficient generalization ability, and lack interpretability, making it difficult to provide intuitive guidance for energy-saving driving.
An improved whale algorithm is used to optimize the parameters of the XGBoost model. By using a nonlinear time-varying convergence factor, Cat chaotic mapping initialization and cross-sectional strategy, combined with SHAP interpretability analysis, the hyperparameter combination is optimized and the impact of driving characteristics is quantified.
It improves the model's prediction accuracy and robustness, balances global and local search capabilities, and provides intuitive guidance for energy-saving driving.
Smart Images

Figure CN121808253A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of electric vehicle energy consumption management technology, and specifically to an electric vehicle energy consumption prediction method based on an improved whale algorithm to optimize XGBoost parameters. Background Technology
[0002] With the rapid development of green transportation, electric vehicles have become the core of the industry. For electric vehicles, accurate prediction of battery energy consumption is not only a core function of the battery management system (BMS), but also a key foundation for achieving accurate range estimation, rational planning of charging facilities, and efficient operation of intelligent traffic scheduling systems. Among numerous prediction methods, the XGBoost model demonstrates significant advantages due to its powerful nonlinear fitting capabilities and efficient parallel computing performance.
[0003] However, the predictive performance of the XGBoost model is highly parameter-sensitive, and its generalization ability and prediction accuracy largely depend on the combination of hyperparameters such as the learning rate, maximum tree depth, and subsampling rate. To obtain the optimal parameter configuration, existing techniques often employ strategies such as grid search, random search, or introduce swarm intelligence algorithms such as the standard Whale Optimization (WOA) to assist in optimization, replacing manual experience-based settings.
[0004] While the aforementioned methods alleviate the parameter setting challenges to some extent, significant bottlenecks remain: grid search is computationally too expensive when dealing with high-dimensional spaces; random search lacks directionality and struggles to guarantee solution quality; and the standard WOA algorithm suffers from insufficient global exploration capabilities and premature convergence in later iterations, limiting further improvements in model accuracy. More critically, existing prediction models are largely "black boxes," lacking interpretability and failing to clearly define the nonlinear impact mechanisms of specific driving characteristics such as idling and rapid acceleration on energy consumption, thus failing to provide users with intuitive and quantifiable guidance for energy-saving driving. Summary of the Invention
[0005] The purpose of this invention is to provide an electric vehicle energy consumption prediction method based on an improved whale algorithm to optimize XGBoost parameters. This method can effectively balance the global exploration and local exploitation capabilities of the WOA algorithm, thereby efficiently searching for the optimal hyperparameter combination of the XGBoost model and improving the accuracy and robustness of the electric vehicle energy consumption prediction model. At the same time, this method can clearly quantify the nonlinear influence of driving behavior characteristics on energy consumption, solve the problem of lack of interpretability in traditional models, and provide intuitive decision support for guiding energy-saving driving behavior and formulating energy management strategies.
[0006] To achieve the above objectives, the specific technical solution adopted in this method is as follows:
[0007] In a first aspect, the present invention provides a method for predicting the energy consumption of electric vehicles based on an improved whale algorithm to optimize XGBoost parameters, the method comprising:
[0008] S01, acquire the original driving data of the electric vehicle and preprocess it, and divide the preprocessed original driving data into multiple working condition segments.
[0009] S02, extract key driving features for each driving condition segment as model input features, and calculate the energy consumption per unit mileage for each driving condition segment as model output label; divide the constructed model input feature data and model output label data into training set and test set according to a preset ratio;
[0010] S03 uses a nonlinear time-varying convergence factor to replace the linear decreasing factor in the standard whale optimization algorithm, uses Cat chaotic mapping to initialize the population and sets a cross-sectional strategy to construct an improved whale optimization algorithm.
[0011] S04, using multiple core parameters of the basic XGBoost model as optimization variables for the improved whale optimization algorithm, training the basic XGBoost model using the training set, using the model prediction accuracy as the fitness function, and obtaining the hyperparameter combination with optimal fitness through iterative search.
[0012] S05, Based on the training set and the hyperparameter combination obtained in S03, train the basic XGBoost model to construct the final XGBoost energy consumption prediction model; use the test set to verify the performance of the XGBoost energy consumption prediction model.
[0013] S06: Collect real-time driving data of electric vehicles, generate real-time model input feature data, input it into the XGBoost energy consumption prediction model after performance verification, and output the energy consumption prediction results of electric vehicles.
[0014] As a preferred embodiment of the present invention, in S01, the preprocessing operation includes outlier handling and missing value imputation; the specific strategy for missing value imputation is as follows:
[0015] For data segments with consecutive missing times of less than or equal to 3 seconds, Lagrange interpolation is used for filling; for adjacent missing segments with insufficient reference points, linear interpolation is used for supplementation.
[0016] As a preferred embodiment of the present invention, the method further includes an interpretability analysis step, specifically:
[0017] The SHAP method was used to perform interpretability analysis on the XGBoost energy consumption prediction model, quantify the influence of each key driving feature on the energy consumption prediction results, and output the analysis results.
[0018] As a preferred embodiment of the present invention, in S04, the multiple core parameters specifically include: learning rate, upper limit of tree depth, sample sampling rate, and number of trees.
[0019] As a preferred embodiment of the present invention, in S02, the key driving characteristics specifically include: average speed, maximum speed, speed standard deviation, and idling time ratio; the calculation method for energy consumption per unit mileage is specifically as follows: , Where E is the energy consumption per unit mileage; N is the duration of the operating segment; U i and I i Let t be the battery output voltage and output current at time i; i+1 -t i S is the time interval between time i+1 and time i; N This represents the driving distance corresponding to the Nth working condition segment.
[0020] As a preferred embodiment of the present invention, in S03, the calculation formula of the nonlinear time-varying convergence factor is based on the cosine function, with an initial weight value of 0 and a minimum weight value of 2.
[0021] As a preferred embodiment of the present invention, in S03, the iterative formula for the Cat chaotic mapping initialization population is: , in, For the system in the first The state variables of the next iteration; This represents the system's state value at the next moment. Operations are used to ensure that variables always remain within a range. Inside.
[0022] As a preferred embodiment of the present invention, in S03, the cross-sectional strategy includes a horizontal cross-sectional operation and a vertical cross-sectional operation, wherein the formula for the horizontal cross-sectional operation is: , in, and They represent individuals and The d-th dimensional offspring generated through horizontal crossover. and It is a random number within the range [0,1]. and It is a random number in the range [-1, 1].
[0023] The formula for the vertical crossover operation is: , in, It is an individual The peacekeeping Offspring individuals generated through vertical crossover. .
[0024] In a second aspect, the present invention also provides an electronic device, including a processor and a memory;
[0025] The processor is connected to the memory;
[0026] Memory, used to store executable program code;
[0027] The processor reads the executable program code stored in memory and runs the program corresponding to the executable program code to perform the steps of the electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters.
[0028] Thirdly, the present invention also provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the above-described method for predicting the energy consumption of electric vehicles based on the improved whale algorithm to optimize XGBoost parameters.
[0029] In summary, the present invention has the following beneficial effects:
[0030] This invention effectively balances the global exploration and local exploitation capabilities of the whale optimization algorithm by introducing a nonlinear time-varying convergence factor, Cat chaotic mapping initialization, and a cross-cutting strategy, thus avoiding premature convergence. This enables the algorithm to find better hyperparameter combinations for the XGBoost model, resulting in faster convergence speed and stronger ability to escape local optima in benchmark tests, ensuring the stability and efficiency of the parameter optimization process.
[0031] This method is built based on real vehicle operation data that has undergone outlier filtering and kinematic segmentation, resulting in a stronger model generalization ability. At the same time, this method combines SHAP interpretability analysis to clearly quantify the nonlinear impact of key driving characteristics such as idling time ratio and maximum speed on energy consumption, solving the problem of lack of interpretability in traditional machine learning models. It provides an intuitive and quantitative scientific basis for guiding energy-saving driving behavior and formulating energy management strategies, achieving an organic unity of high-precision prediction and deep mechanism analysis. Attached Figure Description
[0032] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0033] Figure 1 This is a flowchart of the method of the present invention;
[0034] Figure 2 This is a comparison chart of the changing trends of the nonlinear time-varying convergence factor in the embodiments;
[0035] Figure 3 This is a SHAP analysis diagram from an example;
[0036] Figure 4 The images show the fitting plots of each model in the embodiments;
[0037] Figure 5 The graph shows the performance results of each model in the examples. Detailed Implementation
[0038] The subject matter described herein will now be discussed with reference to exemplary embodiments. It should be understood that these embodiments are discussed merely to enable those skilled in the art to better understand and implement the subject matter described herein, and are not intended to limit the scope, applicability, or examples set forth in the claims. The function and arrangement of the elements discussed may be changed without departing from the scope of this specification. Various processes or components may be omitted, substituted, or added as needed in the various examples. For example, the described methods may be performed in a different order than described, and steps may be added, omitted, or combined. Furthermore, features described in some examples may be combined in other examples.
[0039] like Figure 1 As shown in the figure, this embodiment provides a method for predicting the energy consumption of electric vehicles based on the improved whale algorithm to optimize XGBoost parameters. The specific implementation steps of the method are as follows.
[0040] First, real electric vehicle operation data is obtained from the National Basic Science Public Science Data Center as the raw driving data of electric vehicles. The data fields include time, GPS vehicle speed, three-axis acceleration, latitude and longitude, cumulative distance, total voltage, total current, SOC, and the highest / lowest value of battery cell voltage.
[0041] Preprocessing is performed to clean the raw data based on logical relationships (such as SOC change patterns and battery voltage relationships), physical limits (such as speed not exceeding 120km / h and absolute acceleration thresholds), and behavioral patterns (such as continuous low speed and long-term parking) to remove outliers. For data segments with consecutive missing times of less than or equal to 3 seconds, Lagrange interpolation is used to fill them. For adjacent missing segments with insufficient reference points, linear interpolation is used to supplement them.
[0042] The driving process of a vehicle from the start of one idle to the start of the next idle is defined as a kinematic segment. The driving data is divided into multiple operating condition segments using a fixed step size method (set to 300 seconds in this embodiment). Feature parameters are extracted from each segment, including: average speed, maximum speed, speed standard deviation, maximum acceleration, average acceleration, maximum deceleration, acceleration time ratio, deceleration time ratio, and idle time ratio.
[0043] Through characteristic analysis, four characteristic parameters—average speed, maximum speed, speed standard deviation, and idling time ratio—are used as key driving features. The energy consumption per unit mileage, E, for each driving condition segment is calculated and used as the model output label. The specific calculation method for energy consumption per unit mileage is as follows: , Where E is the energy consumption per unit mileage; N is the duration of the operating segment; U i and I i Let t be the battery output voltage and output current at time i; i+1 -t i S is the time interval between time i+1 and time i; N This represents the driving distance corresponding to the Nth working condition segment.
[0044] The input feature data and output label data of the constructed model are divided into training set and test set according to a preset ratio.
[0045] Next, a nonlinear time-varying convergence factor was used to replace the linear decreasing factor in the standard whale optimization algorithm. The population was initialized using Cat chaotic mapping and a cross-cutting strategy was set to construct an improved whale optimization algorithm.
[0046] Specifically, the purpose of the three core improvements mentioned above is to enhance its global and local search capabilities.
[0047] Nonlinear Time-Varying Convergence Factor: The linearly decreasing convergence factor a(t) in the standard WOA is improved into a nonlinear decreasing form based on the cosine function. , in, The initial weight value is set to 0 in this embodiment; The minimum weight value is set to 2 in this embodiment; Cosine mapping is used to produce nonlinear, slowly varying effects.
[0048] Improved The decay trend exhibits a "fast-slow-fast" nonlinear decay trend with iteration, such as... Figure 2 As shown, it can maintain a stronger global exploration capability in the early stages of the search, maintain steady changes in the middle stages, and quickly enter a convergence state in the later stages, thereby improving development efficiency.
[0049] Cat chaotic map initialization: The initial population is generated using the Cat chaotic map, which improves the diversity and uniformity of the population in the search space. The iterative formula for initializing the population using the Cat chaotic map is as follows: , in, For the system in the first The state variables of the next iteration; This represents the system's state value at the next moment. Operations are used to ensure that variables always remain within a range. Inside.
[0050] The cross-sectional strategy includes horizontal cross-sectional operations and vertical cross-sectional operations. The formula for the horizontal cross-sectional operation is as follows: , in, and They represent individuals and The d-th dimensional offspring generated through horizontal crossover. and It is a random number within the range [0,1]. and It is a random number in the range [-1, 1].
[0051] The formula for the vertical crossover operation is: , in, It is an individual The peacekeeping Offspring individuals generated through vertical crossover. Similar to horizontal crossover, the offspring produced by vertical crossover need to compete with their parents, and individuals with higher fitness are selected for preservation.
[0052] During the iteration process, if a certain dimension of an individual escapes the local optimum through vertical crossover operation, it will quickly be merged into the entire population through horizontal crossover operation, consolidating the dimension of the new solution. This will give other dimensions trapped in local optima more opportunities to escape the local optimum. By combining horizontal and vertical crossover operations, the convergence efficiency and solution accuracy of the algorithm in escaping local optima can be effectively improved.
[0053] Then, for the four core parameters that significantly affect the basic XGBoost model classifier—learning rate, maximum tree depth, subsample rate, and number of trees (n_estimators)—the basic XGBoost model is trained using the training set. The model prediction accuracy is used as the fitness function, and the optimal combination of hyperparameters is obtained through iterative search.
[0054] The specific iterative process is as follows:
[0055] Step 1: Start the whale optimization algorithm framework and configure the basic running parameters: set the population size to N and the maximum number of iterations to T; since the XGBoost parameters to be optimized include four items, the search space dimension is defined as four-dimensional.
[0056] Step 2: Initialize the Cat chaotic mapping, clarify the value boundaries of the parameters to be optimized, limit the fluctuation of each parameter within a reasonable range, and generate the initial whale pod location distribution accordingly;
[0057] Step 3: Evaluate the fitness values of each member in the current whale pod and mark the current optimal solution; at this time, each whale position vector corresponds to a set of parameter combinations, and its position change is mapped to the parameter value change;
[0058] Step 4: Dynamically update the convergence factor a according to the iteration rules, and then adjust the parameter A; simultaneously update the weight coefficient w and the values of random variables l, c, and p.
[0059] Step 5: During the iteration process, adjust the whale pod distribution using the position update formula, and recalculate the optimal fitness after each iteration; when the probability value p is less than 0.5, if |A|>1, perform global exploration to update the position, otherwise use a local encirclement mechanism to update the position; when p≥0.5, use a bubble net predation strategy to adjust the position.
[0060] Step 6: First, perform a horizontal crossover operation. In the newly generated population, randomly pair individuals in pairs and exchange information on the same dimension to produce "offspring" individuals MSx_i and MSx_j with new gene combinations. Then, perform a vertical crossover operation. For the new individuals generated by the horizontal crossover, exchange information between different dimensions within themselves.
[0061] Step 7: Check if the number of iterations has reached the termination threshold; if the termination condition is met, output the XGBoost parameter configuration corresponding to the current optimal position and end the process; otherwise, return to Step 3 to continue execution.
[0062] Furthermore, the basic XGBoost model is trained based on the hyperparameter combination obtained from the training set and S03 to construct the final XGBoost energy consumption prediction model; the performance of the XGBoost energy consumption prediction model is verified using the test set.
[0063] Finally, real-time driving data of electric vehicles is collected, real-time model input feature data is generated and input into the XGBoost energy consumption prediction model after performance verification, and the energy consumption prediction results of electric vehicles are output.
[0064] In another possible embodiment, the method further includes an interpretability analysis step, specifically:
[0065] The SHAP method was used to perform interpretability analysis on the XGBoost energy consumption prediction model, quantify the influence of each key driving feature on the energy consumption prediction results, and output the analysis results.
[0066] like Figure 3 The SHAP integrated impact diagram of four key driving features is presented, revealing the key features that the model relies on most and the direction of their influence as a whole.
[0067] Combination Figure 4 and 5 It is evident that the other three existing algorithms, compared with this improved whale optimization algorithm, exhibit significant performance differences in energy consumption prediction accuracy.
[0068] Figure 4 The fitting performance of grid search, particle swarm optimization, traditional whale optimization, and the improved whale optimization algorithm on the training and test sets is shown, and error histograms are provided to further reflect the distribution characteristics of the prediction residuals.
[0069] like Figure 5 As shown, the performance comparison results of the four algorithm models mentioned above are presented under four metrics: mean absolute error (MAE), mean squared error (MSE), root mean square error (RMSE), and coefficient of determination (R²). It is evident that the hyperparameter optimization strategy proposed by the improved whale optimization algorithm exhibits the best performance across all four metrics in terms of its impact on the XGBoost model's performance.
[0070] In addition, the following embodiments also provide an electronic device, including a processor and a memory;
[0071] The processor is connected to the memory;
[0072] Memory, used to store executable program code;
[0073] The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, in order to execute the steps of the electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters in the above embodiment.
[0074] In addition, the following embodiments also provide a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters in the above embodiments.
[0075] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this specification are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in or transmitted through a computer-readable storage medium. The computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., Digital Versatile Discs (DVDs)), or semiconductor media (e.g., Solid State Disks (SSDs)).
[0076] Several embodiments of this disclosure have been described above. These descriptions are exemplary and not exhaustive, and are not limited to the disclosed embodiments. Many modifications and variations will be apparent to those skilled in the art without departing from the scope and spirit of the described embodiments. The terminology used herein is chosen to best explain the principles, practical applications, or technological improvements to the embodiments in the market, or to enable others skilled in the art to understand the embodiments disclosed herein.
Claims
1. A method for predicting the energy consumption of electric vehicles based on an improved whale algorithm to optimize XGBoost parameters, characterized in that, The methods include: S01, acquire the original driving data of the electric vehicle and preprocess it, and divide the preprocessed original driving data into multiple working condition segments. S02, extract key driving features for each driving condition segment as model input features, and calculate the energy consumption per unit mileage for each driving condition segment as model output label; divide the constructed model input feature data and model output label data into training set and test set according to a preset ratio; S03 uses a nonlinear time-varying convergence factor to replace the linear decreasing factor in the standard whale optimization algorithm, uses Cat chaotic mapping to initialize the population and sets a cross-sectional strategy to construct an improved whale optimization algorithm. S04, using multiple core parameters of the basic XGBoost model as optimization variables for the improved whale optimization algorithm, training the basic XGBoost model using the training set, using the model prediction accuracy as the fitness function, and obtaining the hyperparameter combination with optimal fitness through iterative search. S05, Based on the training set and the hyperparameter combination obtained in S03, train the basic XGBoost model to construct the final XGBoost energy consumption prediction model; use the test set to verify the performance of the XGBoost energy consumption prediction model. S06: Collect real-time driving data of electric vehicles, generate real-time model input feature data, input it into the XGBoost energy consumption prediction model after performance verification, and output the energy consumption prediction results of electric vehicles.
2. The electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters according to claim 1, characterized in that, In S01, the preprocessing operation includes outlier handling and missing value imputation; the specific strategy for missing value imputation is as follows: For data segments with consecutive missing times of less than or equal to 3 seconds, Lagrange interpolation is used for filling; for adjacent missing segments with insufficient reference points, linear interpolation is used for supplementation.
3. The electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters according to claim 1, characterized in that, The method also includes an interpretability analysis step, specifically: The SHAP method was used to perform interpretability analysis on the XGBoost energy consumption prediction model, quantify the influence of each key driving feature on the energy consumption prediction results, and output the analysis results.
4. The electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters according to claim 1, characterized in that, In S04, several of the core parameters specifically include: learning rate, upper limit of tree depth, sample sampling rate, and number of trees.
5. The electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters according to claim 2, characterized in that, In S02, the key driving characteristics specifically include: average speed, maximum speed, speed standard deviation, and idling time ratio; the calculation method for energy consumption per unit mileage is as follows: , Where E is the energy consumption per unit mileage; N is the duration of the operating segment; U i and I i Let t be the battery output voltage and output current at time i; i+1 -t i S is the time interval between time i+1 and time i; N This represents the driving distance corresponding to the Nth working condition segment.
6. The electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters according to claim 1, characterized in that, In S03, the calculation formula for the nonlinear time-varying convergence factor is based on the cosine function, with an initial weight value of 0 and a minimum weight value of 2.
7. The electric vehicle energy consumption prediction method based on the improved whale algorithm for optimizing XGBoost parameters according to claim 1, characterized in that, In S03, the iterative formula for initializing the population using the Cat chaotic mapping is: , in, For the system in the first The state variables of the next iteration; This represents the system's state value at the next moment. Operations are used to ensure that variables always remain within a range. Inside.
8. The electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters according to claim 1, characterized in that, In S03, the cross-sectional strategy includes lateral cross-sectional operations and longitudinal cross-sectional operations, wherein the formula for the lateral cross-sectional operation is: , in, and They represent individuals and The d-th dimensional offspring generated through horizontal crossover. and It is a random number within the range [0,1]. and It is a random number in the range [-1, 1]. The formula for the vertical crossover operation is: , in, It is an individual The peacekeeping Offspring individuals generated through vertical crossover. .
9. An electronic device, comprising a processor and a memory; characterized in that, The processor is connected to the memory; Memory, used to store executable program code; The processor runs a program corresponding to the executable program code by reading the executable program code stored in the memory, in order to perform the steps of the electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters as described in any one of claims 1-8.
10. A computer-readable storage medium, characterized in that, It stores a computer program, which, when executed by a processor, implements the steps of the electric vehicle energy consumption prediction method based on the improved whale algorithm to optimize XGBoost parameters as described in any one of claims 1-8.