## 2 Method
### Parameter Optimization Based on Particle Swarm Optimization  
The particle swarm optimization (PSO) is a swarm intelligence optimization algorithm, introduced by [PERSON] and [PERSON] in 1995. The basic principle is to mimic the behavior of a group of birds (particle swarm) in a forest (search space) seeking food based on the quantity of food (fitness value), to find the location with the most food (group best position) [46]. Each particle in the swarm is characterized by three attributes: position, velocity, and fitness value. Position represents a solution to the problem being solved, velocity indicates the direction and distance the particle will move in the next iteration, and fitness value is calculated based on the fitness function. Initially, particle position and velocity are updated based on individual best position and group best position. At each generation update, fitness value is calculated, compared with the individual best position and group best position, and the process iterates until predetermined iteration times are reached, yielding the combined best position for the particle swarm [47]. All particles should find the best position in the search space. Each particle position and velocity can be calculated as follows:  
\[v_{i}^{k+1}=wv_{i}^{k}+c_{1}r_{1}(p_{i}^{k}-x_{i}^{k})+c_{2}r_{2}(p_{g}^{k}-x_{ i}^{k}) \tag{3}\]  
\[x_{i}^{k+1}=x_{i}^{k}+v_{i}^{k+1} \tag{4}\]  
where \(x_{i}^{k}\) is the position of the \(i\)th particle at the current moment, \(v_{i}^{k}\) is the velocity of the \(i\)th particle at the current moment, \(x_{i}^{k+1}\) is the position of the \(i\)th particle at the next moment, \(v_{i}^{k+1}\) is the velocity of the \(i\)th particle at the next moment; \(r_{1}\) and \(r_{2}\) are random numbers in the interval [0, 1], \(c_{1}\) and \(c_{2}\) are cognitive weight and social weight respectively, and \(w\) is inertia weight; \(p_{i}^{k}\) is the best position obtained from the search of the \(i\)th particle at the current moment, and \(p_{g}^{k}\) is the best position in the whole particle population at the current moment. The parameter values of the RF model, whether too large or too small, can lead to issues such as poor model fitting, increased computational complexity, and inappropriate feature selection, ultimately affecting the accuracy of SOH prediction. Given the advantages of simplicity and fast convergence offered by PSO, it can be applied to optimize the parameters of machine learning models. Therefore, we establish a PSO algorithm for optimizing the parameters of an RF model. Initially, we define a particle as a combination of five parameters to be optimized within the RF model: max_depth, n_estimators, max_features, min_samples_split, and min_samples_leaf. This is equivalent to particles in a five-dimensional space searching for the best solution within the specified ranges for these five parameters. The ranges for the five parameters can be empirically set as [2, 20], [1, 100], [0.01, 1], [2, 20], and [1, 20], respectively. This is equivalent to defining the search space for each dimension. Next, we initialize the position and velocity of the particles and use the out-of-bag error as the fitness function to compute the fitness values of each particle within the RF model. We then determine whether the current iteration time has reached the predefined value. If it has not, we compare fitness values to obtain group best position and individual best position. We use Equations (3) and (4) to iteratively update the position and velocity of each particle and recalculate their fitness values. This process continues until the iteration times reach the predefined value. At that point, we output the best position of the particle swarm, which represents the best parameter combination. Finally, we decode the best parameter combination to obtain the best solution for the five parameters. The specific steps are shown in Figure 2.  
To implement the PSO algorithm for parameter optimization in the RF model using Python, follow the development process outlined below. 1.