# Research on Grain Moisture Model Based on Improved SSA-SVR Algorithm
## 4 Results  
### Improved SSA-SVR Training Model Results  
To begin, choose the radial basis function with the kernel set to 'rbf' [33, 34]. For parameter settings, utilize the GridSearchCV function to define the range of parameters. This includes the penalty parameter C, the width of the radial basis function gamma, and parameter \(\varepsilon\) for the epsilon-insensitive loss function. First, initialize the SSA parameters. Since there is no ready-made Python library for the SSA, configure a detailed class to implement the details of the Sparrow Search Algorithm [35, 36]. Set the initial population size to 45, the maximum number of iterations to 60, and include parameters for Circle chaotic mapping and the reverse learning mechanism. Apply reverse learning every 10 iterations, ensuring not to exceed the search space. The following is part of the SSA implementation configuration code:  
The code \"self.fitness[i] = self.obj_func(self.position[i])\" is used to calculate fitness, the code \"best_idx = np.argmin(self.fitness)\" is used to find the best position, the code \"self.update_producers(best_idx)\" is the update producer location, the code \"self.update_scuters(best_idx)\" is the update alert location, the code \"self.position = np.clip(self.position, self.lb, self.nb)\" is to ensure that the search space is not exceeded, the code \"best_idx = np.argmin(self.fitness), return self.position[best_idx], self.fitness[best_idx]\" is to ensure that the search space is not exceeded, and the code \"ssa = DetailedSSA(obj_func = objective_function, lb = -10, ub = 10, dim = 2, population_size = 45, max_iter = 60)\" uses the SSA for optimization. The fitness function formula is as follows:  
\[\text{F}=\text{min}\big{(}\text{MSE}_{\text{TrainingSet, TestingSet}}\big{)} \tag{15}\]  
In the formula, TrainingSet refers to the training set samples, and TestingSet refers to the test set samples. After using the sparrow search optimization algorithm, the fitness function becomes smaller, resulting in a decrease in the mean square error and an increase in the training accuracy of the model [37]. Set param_grid = {'C': [0.1, 1, 10], 'epsilon': [0.01, 1], 'gamma': [1, 10, 100]}, with 5-fold cross-validation [38, 39], and the SSA will search for the optimal parameters within these ranges. Use the SSA parameters as described above; plot a two-dimensional scatter plot of voltage values and moisture values. When param_grid = {'C': [0.1, 1, 10, 100], 'epsilon': [0.01, 1], 'gamma': [0.001, 0.1, 1]}, add a random seed in the code, run the SSA-SVR model multiple times, meaning each run of the algorithm will start in a different initial state, generating different search paths and results. We calculate the average performance metrics of each run to obtain a general estimate of the model's performance. By optimizing the SSA, the parameter combination obtained is the C penalty parameter as 72.3, the radial basis function width gamma as 0.75, and the epsilon insensitive loss as 0.2 [40], and with 5-fold cross-validation, the training model is relatively optimal, as shown in Figure 3a. Taking the average values, the correlation coefficient is 0.987, the coefficient of determination is 0.992, the root mean square error is 0.65, and the Best accuracy is 0.584. The \"Best accuracy\" reflects the highest average R\({}^{2}\) score configuration obtained during the cross-validation process, where the dataset is divided into several small groups or \"folds\". The model is trained using one fold as the test set and the rest as the training set in a rotating manner. This process is repeated multiple times, each time selecting a different fold as the test set. The average R\({}^{2}\) score is based on the model's performance on different subsets, providing a more robust estimate of the model's generalization ability. Therefore, the actual Best accuracy is obtained through cross-validation, while the separately calculated R\({}^{2}\) score is based on the model's prediction of a specific dataset.