Remaining useful life prediction of Lithium-ion batteries based on PSO-RF algorithm

Accurately predicting the Remaining Useful Life (RUL) of lithium-ion batteries is the key to the battery health management system. However, problems of unstable model output and extensive calculation limit the prediction accuracy. This article proposes a Particle Swarm Optimization Random Forest (PSO-RF) prediction method to improve the RUL prediction accuracy. First, the battery capacity extracted from the lithium-ion battery data set of the National Aeronautics and Space Administration (NASA) and the University of Maryland Center for Advanced Life Cycle Engineering (CALCE) is set as the battery life health factor. Then, a PSO-RF prediction model is established based on the optimal parameters for the number of trees and the number of random features to split by the PSO algorithm. Finally, the experiment is verified on the NASA and CALCE data sets. The experiment results indicate that the method predicts RUL with Mean Absolute Error (MAE) less than 2%, Root Mean Square Error (RMSE) less than 3%, and goodness of fit greater than 94%. This method solves the problem of parameter selection in the RF algorithm.

replacement to achieve preventative maintenance of the battery (Duong and Raghavan, 2018).
In recent years, people have conducted extensive research on the degradation mode of batteries and the RUL prediction , resulting in different prediction methods. These methods can be categorized into model-based methods (Chang et al., 2019) and data-driven methods . The model-based method mainly includes the electrochemical (Deng et al., 2018) and equivalent circuit models (Yang et al., 2020a).
The electrochemical model approach establishes a degradation model by analyzing the influence of the internal structure of the battery, material properties, and other conditions to achieve the RUL prediction. The equivalent circuit modelbased method uses the closed-loop format filter algorithm, in which the error between the predicted and the measured values will be fed back for correction. Duan (Duan et al., 2020) proposed a new Extended Kalman Particle Filter (EKPF) for the RUL prediction. The filter optimizes the PF algorithm with the Extended Kalman filter as the sampling density function. Li (Li et al., 2021) combined the least squares support vector machines (LSSVM) with the unscented particle filtering (UPF) to achieve the online prediction of RUL. Ma  used the autoregressive (AR) model to predict capacity. The predicted capacity was used to update the degradation model parameters of the particle filter algorithm to improve the prediction accuracy of RUL. However, such methods rely on accurate and complex battery capacity degradation models. In addition, due to the inherent characteristics of particle filtering, neither traditional particle filtering methods nor improved particle filtering methods can address the issues of particle degradation and impoverishment well. So it is difficult to predict the RUL of FIGURE 1 RF algorithm model structure.

FIGURE 2
The percentage of false nearest neighbors of different embedding dimensions.

Frontiers in Energy Research
frontiersin.org 02 batteries accurately. Moreover, the complex equivalent structure requires abundant professional knowledge and relevant experience. These reasons lead to the fact that model-based methods are not widely used.
The data-driven method does not need to consider the electrochemical reaction process. It extracts the hidden information from the historical data of the lithium-ion battery to predict the RUL. These methods are mostly based on machine learning and deep learning, including Artificial Neural Networks (ANN) (Bai et al., 2014;Kang et al., 2014), Random Forest (RF) (Yang et al., 2008), Relevance Vector Machine (RVM) (Liu and Jianbao ZhouHaitao LiaoYu PengXiyuanPeng, 2015), and Support Vector Machine (SVM) (Klass et al., 2014;Patil et al., 2015). Li  addressed an RF regression prediction algorithm for battery capacity estimation. This method analyzes various data sets measured by lithium-ion batteries in different working environments and extracts critical features from the current, voltage, and temperature curves. These features are used for model training to approach the lithium-ion battery RUL prediction. Ji (Ji et al., 2021) built a model combining monotonic echo state network (MESN) and self-adaptive differential evolution (SADE), and improves the prediction accuracy of

Frontiers in Energy Research
frontiersin.org 03 RUL and can achieve online prediction. Yang (Yang et al., 2020b) elaborated a complex nonlinear battery dynamics model based on the Gradient-enhanced regression tree (GBRT) and predicted the RUL by extracting various battery characteristics. Zhang  applied a mixed prediction algorithm that fuses Artificial Bee Colony (ABC), RF, and General Regression Neural Network (GRNN) to predict the RUL. The RF algorithm is used to calculate the importance of each feature in the feature space for ranking. Ardeshiri (Ardeshiri et al., 2022) employed the RF algorithm for optimal feature selection to filter unnecessary features. Then the combination of gated recurrent unit (GRU) and Least Squares Generative Adversarial Network (LSGAN) was used to improve the prediction accuracy. Lin (Lin et al., 2022) used constant current charging time (CCCT) to extract features and used RF to predict SOH. The result shows that prediction accuracy is improved but with reduced data utilization. However, the approach to selecting the optimal parameters of the RF algorithm still needs to be explored.
Long (Long et al., 2013) proposed a PSO algorithm and an improved AR model to predict the RUL of lithium-ion batteries with less error. Qin (Qin et al., 2015) expounded the PSO algorithm to obtain the Support Vector Regression (SVR) optimal parameters and established the PSO-SVR model. The model can reflect the global degradation trend and realize accurately RUL prediction. Mao (Mao et al., 2022) deduced the PSO algorithm to optimize the Back Propagation (BP) neural network to estimate the state of charge of the battery. The prediction result of this method is better than that of the BP neural network. Ren (Ren et al., 2021) applied the PSO algorithm to optimize the selection of parameters in the Long Short-term Memory (LSTM) neural network. The PSO algorithm is applied to optimize the hyper-parameters of LSTM. Yao (Yao et al., 2022) analyzed a PSO-ELM-RVM model to predict the RUL. The PSO algorithm was used to optimize the parameters of both the RVM and extreme learning machine (ELM) models.
The PSO algorithm is proven to exhibit good optimization ability. Therefore, this paper proposes a PSO-RF prediction method. This method uses the PSO algorithm to search the two optimal parameters of the RF algorithm (the number of trees and the number of random features for each split). The main contributions of this paper are: 1) The PSO algorithm is used to find the optimal parameters of the RF algorithm, which improves the accuracy of the prediction while ensuring robustness. 2) The PSO algorithm is introduced into the RF algorithm, which achieves the adaptive selection of parameters and improves the adaptability of the algorithm to different data sets. 3) Compared with the traditional RF algorithm and BP neural network algorithm, it is verified that the method proposed in this paper has higher accuracy and robustness for RUL prediction. The adaptability to different data sets has been improved simultaneously.
The following content of this paper is mainly divided into the following parts. Section 2 discusses the establishment process of the PSO-RF model in detail. Section 3 introduces the data source and processing method, verifies the feasibility of the PSO-RF algorithm, gives the prediction results, and compares the PSO-RF model with RF and BP neural networks. Section 4 completes a summary of the paper.   Comparison of inertial weights.

Frontiers in Energy Research
frontiersin.org 05 2 Establishment of PSO-RF model 2.1 PSO optimization principle PSO is a stochastic global optimization technique. The PSO algorithm discovers the optimal region in the complex search space through the interaction between particles. At the beginning of the calculation, PSO will randomly generate a group of particles that meet the requirements and then iterate continuously to find the optimal global particles according to the optimal historical particles.
The velocity of the ith particle at k iterations is: Where i = 1,2,3...m; d = 1,2,3...D, ω is the inertial parameter, c 1 and c 2 are learning factors, which are constants, r 1 and r 2 are random numbers, P i,d is the optimal local value of the d-dimensional component of the ith particle, and G d is the optimal global value of the d-dimensional component. The location update equation is: where x k id is the d-dimensional location component of k iterations of the ith particle, and v k+1 id is the d-dimensional velocity component of the ith particle k iterations.
This paper adopts two methods to prevent the traditional PSO algorithm from falling into the local optimum in the optimization process. First, the inertia weight adopts a linear differential decline method to enhance the ability of local optimization in the later stage, as shown in Eq 3. Second, the acceleration factor adopts a linear adjustment method to make full use of particle cognition ability and searchability, as shown in Eqs 4, 5.
Where ω max is the maximum iteration inertia weights, ω min is the minimum iteration inertia weights, k is the current number of iterations, T max is the maximum iteration number, c 1i , c 2i are the initial value of acceleration factors c 1 and c 2 respectively, c 1f and c 2f are the final value of acceleration factors c 1 and c 2 respectively.

FIGURE 8
Acceleration factor comparison chart.
Frontiers in Energy Research frontiersin.org

RF algorithm
RF is a new machine learning method combining ensemble learning and decision tree. RF algorithms have been successfully applied to many different fields of classification and regression, such as wind forecasting (Lahouar and Slama, 2017), wheat biomass estimation (Wang et al., 2016), and spatial prediction of soil organic carbon (Filho et al., 2016). The RF algorithm has the advantages of excellent classification performance, minor parameter adjustment, high training efficiency, and less overfitting (Sun et al., 2019). In recent years, the RF model has been extensively used in the health prediction of lithium-ion

FIGURE 9
Results and errors of B0005 prediction.

Frontiers in Energy Research
frontiersin.org 07 batteries and RUL prediction of batteries and has achieved remarkable results.
The fundamental idea of RF is the following. First, the Bootstrap sampling method randomly selects samples from the original data set and puts them back into the original data set. The extracted samples constitute the training set. Then use the Classification and Regression Trees (CART) method to build a classification tree or regression tree for each new sample set. Finally, the final prediction result is given based on the results of all the decision trees.
Let X stand for the input vector including m features with X {x 1 , x 2 , ..., x m }, Y the output scalar, and S n the training set

FIGURE 10
Results and errors of B0006 prediction.

Frontiers in Energy Research
frontiersin.org 08 including n predictive values, which can be represented as Figure 1. The steps are as follows: (1) Assuming that there are N samples in the training set data, the Bootstrap sampling method extracts n samples from them to form a training subset. The subset is considered as the training sample of a single regression tree.
(2) Assuming that there are M features in the training subset, randomly select m features as the split feature subset (m ≤ M), and then use the CART algorithm to split without pruning.

FIGURE 11
Results and errors of B0007 prediction.

PSO-RF algorithm
Li  considered the influence of the number of trees and the number of random features to split when using the RF algorithm to predict battery capacity. The results show that adding optimization parameters of RF does not affect the final results. Therefore, this paper used the PSO algorithm to select these two parameters on its basis. They directly determine the accuracy of the RF algorithm Table 1. However, there is a lack of effective methods to guide the selection of RF parameters for the time being. Therefore, this paper selects the PSO algorithm to optimize the RF parameters.
The main steps of the RF algorithm are as follows: (1) Data processing: First, the battery capacity data is preprocessed and standardized. Lithium-ion battery capacity degradation data is a one-dimensional time series. The embedding theory is used to reconstruct the data set. The phase space reconstruction process with dimension d is as follows.
In order to determine the value of d, the false nearest neighbors method is used for verification (Kennel et al., 1992). The results are shown in Figure 2. When d = 9 the percentage of false nearest neighbors is 0. Therefore, d = 9 is chosen as the dimension of the reconstruction space. Therefore, the battery capacity data of the kth~(k+8)-th cycle is used as input, and the battery capacity data of the k+9-th cycle is used as output.
(3) The RF model is established by the initialized particles. The training data is divided into n training sets, and m split features are extracted. The training sets are used to train to establish n regression tree models, and the test data is used to calculate n prediction results. The average of n predicted results is the final results. The root mean square error (RMSE) between the test samples and the results is the particle fitness. The fitness is defined as: Also, the fitness is the objective function.
(4) Iteratively update the position and velocity of the particles according to Eqs 1-5 to update n trees and m f eatures . Furthermore, calculate the corresponding particle fitness. After comparing with the particle fitness before the update: a. Update the optimal historical position of each particle; b. Find the optimal global particle position; c. Update the optimal global particle position to achieve the minimum RMSE. (5) The iteration loop is terminated when the iteration count is reached. Obtain the optimal parameters n trees and m f eatures and output the predicted values. Otherwise, return step (4).
This paper mainly adopts the RMSE to assess the selection of n trees and m features parameters in the RF model. RMSE is used to measure the deviation between predicted and real values and characterize the accuracy of prediction. The flow chart of PSO-RF algorithm is depicted in Figure 3.

Data set
In this study, the PSO-RF method is validated using two sets of the RUL of lithium-ion battery data sets.
The RUL data set I of lithium-ion battery packages is achieved from the NASA-Ames Prediction Center of Excellence (PCOE) data warehouse. Three battery packages, B0005, B0006, and B0007, were elected to verify the proposed method. The rated capacity of the corresponding battery packages was 2Ah. The battery aging experiments were carried out at room temperature. The process follows: First, the constant current of 1.5A was applied to charge the battery. When the battery voltage reaches 4.2V, the charging ends. At another cycles, the constant voltage mode was applied to charge the battery. When the charging current dropped to 20mA, the charging was completed. Then, the battery packages corresponding to B0005, B0006, and B0007 were discharged in a constant

FIGURE 12
Results and errors of CS2-33 prediction.
Frontiers in Energy Research frontiersin.org 11 current mode of 2A. The discharging ends when the battery voltage dropped to 2.7, 2.5, and 2.2V, respectively. The battery end-of-life (EOL) line is reached when the battery capacity degrades to 70% of the rated capacity. The correlation between the battery capacity, the number of cycles, and the end-of-life line are shown in Figure 4. Data set II is the RUL data set from the CALCE. CS2-33, CS2-34, CS2-35, and CS2-36 were selected to verify the proposed method. First, the CS2 battery package was charged at a constant current rate of 0.5C. When the voltage reached 4.2V, it was charged with a 4.2V constant voltage. When the charging current drops to 0.05A, the charging ends. Then, CS2-33 and CS2-34

FIGURE 13
Results and errors of CS2-34 prediction.

Frontiers in Energy Research
frontiersin.org were discharged at a constant discharge current of 0.5C. CS2-35 and CS2-36 were discharged at a constant discharge current of 1C. The battery EOL line is set as 70% of the rated capacity. The correlation between the battery capacity, the number of cycles, and the end-of-life line are shown in Figure 5.
The description of the data sets I and data sets II is shown in Table 2.
The RUL refers to the number of cycles that the battery can carry out from the current moment to the end of life. In this paper, the battery reaches the end of life when the maximum

FIGURE 14
Results and errors of CS2-35 prediction.

Frontiers in Energy Research
frontiersin.org 13 usable capacity drops to 70% of the rated capacity. The calculation of RUL is shown in Eq 8: where C EOL is the number of cycles required at the end of life, C i is the current number of cycles of the battery.

PSO-RF model analysis
It is necessary to consider the effect of the number of iterations, the effect of the inertia weight, and the effect of the acceleration factor of the PSO algorithm. This paper analyzes the influence of the above factors in the data set AAA when the prediction starting point is 80.

FIGURE 15
Results and errors of CS2-36 prediction.

Frontiers in Energy Research
frontiersin.org 14

The influence of the number of iterations
If the iteration count is too small, the accuracy of the battery life prediction will be affected. In contrast, a large number of iterations will increase calculation. Figure 6 shows the change of RMSE with the number of iterations as the independent variable. The RMSE of the data sets has stabilized within 50 generations and almost no longer decreased after that. Therefore, in this work, the iteration count of the PSO-RF model is selected to be 100.

The advantage of linear differential decreasing in inertia weight
The inertia weight reflects the ability of a new generation of particles to inherit the speed of the previous generation. Through the analysis of the PSO algorithm, it can be concluded that it is helpful for global search when the inertia weight is more prominent. In contrast, a smaller inertia weight is helpful for local search. Compared with fixed inertial weight, linear differential decreasing inertial weight has a larger inertial weight in the early stage of the search, strengthening the global search ability and avoiding falling into the optimal global solution. In the later search stage, the linear differential decreasing inertia weight has a smaller inertia weight, which can enhance the local search ability. On the premise of finding the optimal global range, the optimal solution is more likely to be locked.
When the inertia weight adopts linear differential decrease and fixed weight ω = 0.65, the RMSE changes are shown in Figure 7. It can be obtained from the figure that the linear differential decreasing inertia weight can rapidly reduce the RMSE in the early search stage, and the final result is better than the fixed weight search method. Therefore, the linear differential decreasing inertia weight can seek the optimal solution and avoid falling into the optimal global so that the prediction has accurate results.

Advantages of linear adjusted acceleration factor
The acceleration factor c 1 controls the individual historical experience to update the individual velocity. A large acceleration factor c 1 will make the particles linger too much locally. The acceleration factor c 2 controls the group shared experience to renewal the individual velocity. A considerable c 2 will prematurely make the particles converge to the optimal local solution with a large acceleration factor. The particles should fly across the entire search space as far as possible to obtain the diversity of the particles at the initial stage of the search. At the end of the search, the particles should maintain a certain speed to eliminate the interference of local extremes as much as possible. Therefore, the linear adjusted acceleration factors should have a large acceleration factor c 1 and a small acceleration factor c 2 in the  early stage. In contrast, a small acceleration factor c 1 and a large acceleration factor c 2 are required at the later search stage. When the acceleration factor adopts a linear adjusted acceleration factor and fixed acceleration factors (c 1 = c 2 = 1.5), the RMSE changes are shown in Figure 8. It can be obtained from the figure that the linear adjusted acceleration factor can find the optimal solution more quickly. Therefore, the linear adjusted acceleration factor can strengthen the optimization efficiency and reduce the iteration count to reduce the calculation cost.

FIGURE 16
Prediction results comparison of NASA data set when prediction starting point is 80.

Frontiers in Energy Research
frontiersin.org 16

Performance evaluation tools
Three metrics are used in this work to evaluate the accuracy of PSO-RF model-generated predictions.
(1) Mean Absolute Error (MAE) The MAE is the mean of absolute errors between predicted and observed values. It is defined by Eq 9: The smaller the MAE values, the more accurate the prediction result.

MAE
1 n n i 1 where n is the number of predicted samples,y i is the experimental values andy i ∧ is the predicted values.
(2) RMSE The RMSE is used to describe the difference between prediction and observation value. RMSE is similar to MAE. But it punishes a greater absolute value by giving more weight than MAE. The variance of individual errors becomes more prominent with the increase in the difference between MAE and RMSE. RMSE is defined as (3) Goodness-of-fit (R 2 ) R 2 is another indicator that measures the degree of matching between the predicted value and the real value. The ideal R 2 value of the model is 1, which indicates that the model can demonstrate all the variations in the target class. R 2 is defined as where n is the number of predicted samples, y i is the experimental values, y − is the mean value and y i ∧ is the predicted values.

Analysis of PSO-RF model prediction results
The change in battery capacity directly represents the degradation degree of the battery during the charge-discharge cycle. Consequently, capacity can be used as an input value for evaluating battery performance degradation to predict the RUL. To verify the feasibility of the proposed method in the RUL prediction of the lithium-ion battery, the battery degradation data sets in Section 3.1 are used for testing. To verify the effectualness of the method at different starting points, the prediction starting points of the model are selected as 40, 60, and 80 cycles. The cycle times of B0005, B0006, and B0007 in data set I are all 168. After reconstructing the vector space, they are 160. The prediction starting points for data set Ⅱ are selected as 250, 350, and 450 cycles. The cycle times of  in data set Ⅱ are all 700. After reconstructing the vector space, they are 692.
For data set I, graphs (A), (C), and (E) in Figures 9, 10, 11 show that the PSO-RF algorithm exhibits a better convergence  Table 3 illustrates that as the prediction starting point moves backward, the data used for training continues to increase. The MAE and RMSE of the prediction results continue to decrease, but the results are not much different. The consistency of results shows that the PSO-RF algorithm has splendid long-term prediction accuracy. When the prediction starting point is 80 cycles, the average MAE and RMSE of the predicted values for the three types of battery packages are 0.0113 and 0.0168, respectively. Figures 12-15 show the prediction results of the PSO-RF algorithm for data set II when the prediction starting point is 250, 350, and 450 cycles. The PSO-RF algorithm shows a good convergence effect for all four types of battery packages. When the prediction starting point is 450 cycles, the average MAE and RMSE of the predicted values of the four types of battery packages are 0.0034 and 0.0056, respectively. The rest of the data are shown in Table 4.

Comparative analysis
In this paper, we first compared our prediction results with the existing work by taking the NASA data set as an example, as shown in Table 5. And we compared with random forest algorithm and BP neural network algorithm.

Compare with RF algorithm
The PSO-RF algorithm is an optimized RF algorithm. The PSO algorithm is applied to search for the optimal parameters of the RF algorithm. Therefore, to verify the feasibility of the PSO-RF algorithm, the RF algorithm selects general parameters for comparison, that is, n trees = 500, and m f eatures is the default value. The default value of m features is one-third of the total number of features. As shown in Figure 16, the average MAE and RMSE of the predicted values of the RF algorithm in the NASA data set are 0.0129 and 0.0180, respectively, when the prediction starting point is 80 cycles. As shown in Figure 17, the average MAE and RMSE of the predicted values of the RF algorithm in the CALCE data set are 0.0039 and 0.0061, respectively, when the prediction starting point is 450 cycles. Tables 6, 7 list the comparison results of the prediction errors of the PSO-RF and RF algorithms. The results show that the PSO-RF algorithm can predict the capacity more accurately, thereby reducing the prediction error of RUL. In addition, different battery packages have various capacity changes during the aging process of charge and discharge. General parameters of RF algorithms may not be able to obtain relatively optimal solutions for different types of battery packages. After the optimization by the PSO algorithm, the ability of PSO-RF to find the optimal solution is enhanced, and its adaptability to different data is improved.

Compared with BP neural network
The BP neural network is a multi-layer feedforward network according to the error back propagation training. Its fundamental idea is to minimize the average variance of the real and expected output value of the network by the gradient descent method. Since the BP neural network has robust nonlinear mapping capabilities and flexible network structures, it is used in the URL prediction of lithium-ion batteries. As shown in Figure 16, the average MAE and RMSE values of the predicted values of the three types of battery packages in the NASA data set by the BP neural network are 0.0196 and 0.0258, respectively. The average MAE and RMSE of the predicted value of the BP neural network are larger than that of the predicted value of the PSO-RF algorithm. Figure 17 shown that the average MAE and RMSE values of the BP neural network for the predicted values in the CALCE data set are 0.0088 and 0.0112. The prediction error comparison results of PSO-RF and BP neural network are listed in Tables 6,7. It is demonstrated that the PSO-RF

Conclusion
Accurate RUL prediction is essential to ensure the reliability and stability of lithium-ion batteries in the application process. This paper proposes a PSO-RF algorithm to predict the RUL, effectively solving the problem of parameter selection in the RF algorithm. The performance of the proposed method is validated using original battery degradation data sets from NASA and CALCE. The prediction results of the proposed method are compared with the prediction results of the RF method and the BP neural network method to verify the effectiveness of the PSO-RF method. The comparison shows that the PSO algorithm can optimize two parameters of the RF model. The extracted battery capacity data are arranged according to the number of cycles to form a capacity decay curve. Moreover, the curve conforms to the time series and has prominent nonlinear characteristics, which follow the characteristics of the RF solution. The simulation experiment results show that the PSO-RF algorithm can accurately predict the capacity of aging batteries and has a good convergence effect. Therefore, the algorithm is suitable for predicting the RUL.

Author contributions
Full-paper design, JW, XC, and LZ; writing-review and editing, XC, HH, and JW; funding acquisition, JX and JW; software, LZ, and CF; formal analysis, LZ, JX, and JW; data curation, XZ; writing-original draft preparation, JW and LZ; supervision, JW and LZ; All authors have read and agreed to the published version of the manuscript.

Funding
This work is supported by the scientific research fund of Hainan University (No. kyqd (ZR)1934 and No. RZ2100003112).

Conflict of interest
Author XZ was employed by the Hainan Curium Technology Co., Ltd.
The remaining authors declare that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.