## 3 Methodology
### Tuning Algorithms and Machine Learning Models
#### 3.3.2 Sparrow Search Algorithm (SSA) and Improved Sparrow Search Algorithm (ISSA)  
The SSA seeks the optimal solution within a dataset by simulating the survival behavior of a population of sparrows. In captive sparrow populations, there are two distinct roles: discoverers and entrants. The main job of the discoverers is to find the optimal solution from the data space, which is the source of food, and provide other sparrows with specific information about the location of food. Entrants rely on this information to obtain food resources. Additionally, when confronted with a predator, one or more members of the group emit warning signals, prompting the entire group to move away from danger and search for food in a new area. These individuals who issue warnings are referred to as alerts [28; 29]. The location of the discoverer changes as the number of iterations is updated. \[x_{i,j}(t+1)=\left\{ \begin{matrix}x_{i,j}(t)\cdot exp\Big{(}-\frac{j}{\alpha \cdot item_{max}}\Big{)},&R_{2}<ST\\ x_{i,j}(t)+Q\cdot L,R_{2}\geq ST\end{matrix} \right. \tag{9}\]  
The t in the formula represents the current iteration number of the model, and the accuracy of the model also changes with the increase in the iteration number. \(item_{max}\) is a constraint on the model created by humans and represents the maximum number of iterations the model can run. We can then reduce the time wasted by excessive model iteration. The information provided by \(x_{i,j}(t)\) is the sparrow's current position in the data space. \(\alpha\) is a random number that prevents the model from falling into a locally optimal solution. \(R_{2}\) and ST are warning values and safety values, respectively, which are used to evaluate the safety degree of the current area where the sparrow is, so as to judge the next action. L is a matrix of 1 \(\times\) d, and the contents of the matrix are all 1. When the discoverers find the food, the position of the entrants is updated, as follows:  
\[x_{ij}(t+1)= \begin{cases}Q\cdot exp\left(\frac{x_{\textit{target}}-x_{ij}(t)}{i^{2 }}\right),\ i>\frac{n}{2}\\ x_{p}(t+1)+\left|x_{ij}(t)-x_{p}(t+1)\right|\cdot A^{+}\cdot L,\ i\leq\frac{n}{2} \end{cases}  \tag{10}\]  
\(x_{p}\) is the local best position found by the discoverer, and \(x_{\textit{inrost}}\) is the global worst position. A is a \(1\times\) d matrix where each element is randomly assigned to either \(1\) or \(-1\), \(A^{+}=A^{\mathsf{T}}\big{(}AA^{\mathsf{T}}\big{)}^{-1}\). When b, this indicates that i entrant with low fitness has not obtained food and needs to update its position again to find new food. \(x_{p}\) and \(x_{\textit{inrost}}\) represent the best and worst positions found by the finder. A is a \(1\times\) d matrix randomly assigned \(1\) or \(-1\). The alert's location is updated below. \[x_{ij}(t+1)= \begin{cases}x_{\textit{bestj}}(t)+\beta\Big{|}x_{i,j}(t)-x_{ \textit{bestj}}(t)\Big{|},\ f_{i}>f_{g}\\ x_{i,j}(t)+K\Big{(}\frac{\left|x_{ij}(t)-x_{\textit{inrost}}(t)\right|}{(f_{i} -f_{w})+\epsilon}\Big{)},f_{i}=f_{g}\end{cases}  \tag{11}\]  
Although the SSA model has the ability to search relatively quickly, it may fall into the local optimal solution due to lacking the ability to jump out of the local limit value when facing large datasets. To solve this problem, the algorithm is improved and the levy flight strategy is introduced into the formula. This increases the global search capability of the model [30]. \[x_{ij}(t+1)= \begin{cases}\textit{Levy}(d)\cdot x_{\textit{bestj}}(t)+\beta \Big{|}x_{i,j}(t)-\textit{Levy}(d)\cdot x_{\textit{bestj}}(t)\Big{|},\ f_{i}>f_{g}\\ x_{i,j}(t)+K\Big{(}\frac{\left|x_{ij}(t)-x_{\textit{inrost}}(t)\right|}{(f_{i }-f_{w})+\epsilon}\Big{)},f_{i}=f_{g}\end{cases}  \tag{12}\]  
\[\textit{Levy}(d)=0.01\cdot\frac{r_{1}\cdot\sigma}{\left|r_{2}\right|^{\frac{1 }{g}}} \tag{13}\]  
\[\sigma= \begin{cases}\frac{\Gamma(1+\beta)\cdot\sin\left(\frac{\pi\beta}{2} \right)}{\Gamma\Big{(}\Big{(}\big{(}\frac{1+\lambda}{2}\Big{)}\beta\cdot 2^{ \frac{(\beta-1)}{2}}\Big{)}\Bigg{\}}\end{cases}