# Research on Grain Moisture Model Based on Improved SSA-SVR Algorithm
## 4 Results
### Other Model Training Results
#### 4.2.3 Random Forest Model Results  
To make the output model more accurate in the use of random forest models, grid search has been added. Although this increases the code execution time and affects efficiency, grid search can try different parameter combinations to find the best model parameters. It also avoids the tedious process and subjectivity of manually adjusting parameters.  
The parameter grid param_grid contains some important parameters of the random forest model and their corresponding value ranges. A search is conducted within this grid to find the optimal parameter combination for building the random forest model. The random forest model utilizes the RandomForestRegressor from scikit-learn. The initial code for this section is as follows:  
param_grid = {  
'n_estimators': [50, 100, 200, 300],  
'max_depth': [None],  
'min_samples_split': [2, 5, 10],  
Figure 9: (**a**) Shows MLP model training; (**b**) training the optimized MLP model.  
'min_samples_leaf': [1; 2; 4] }  
'n_estimators' refers to the number of decision trees.'max_depth' refers to the maximum depth of the decision trees, where None means there is no limit to the depth of the trees.'min_samples_split' refers to the minimum number of samples required to split an internal node.'min_samples_leaf' refers to the minimum number of samples required at a leaf node [46; 47]. In training, these parameters are exhaustively searched in combination to construct the random forest model and estimate its performance. Ultimately, the optimal model parameters are selected as the best performing parameter combination.  
Iterate through different max_features options (which impact the number of features considered for each split in the tree) to evaluate model performance, using cross-validation (cross_val_score) to obtain average scores. Select the best performing max_features value and retrain the model. Setting max_features = 'auto' means considering all features at each split. To ensure the reliability of the results, use different random seed values to help evaluate the model [48]. Train several different models and compare how different max_features values affect model performance.  
Figure 10a-c correspond to the cases where max_features are 'auto','sqrt', and 'log2', respectively. In the model trained with max_features = 'auto', although the correlation coefficient and determination coefficient both reached 0.96 and the root mean square error was 1.98, the Best accuracy was between \(-7\) and \(-9\), which is relatively poorer compared to that of the improved SSA-SVR.  
Figure 10: (**a**) Shows the training model with max_features = ‘auto’; (**b**) shows the training model with max_features = ‘sqrt’; and (**c**) shows the training model with max_features = ‘log2’.  
The reasons for selecting random forest as a comparative algorithm to establish the model are as follows:  
(1) Resistance to overfitting ensemble method: Random forest builds multiple decision trees and makes final decisions through voting. This ensemble learning method effectively resists overfitting, enhancing the stability and accuracy of the model.  
(2) Feature selection: random forest evaluates the importance of features during training, providing insights into understanding how the model makes predictions and which features are more important.  
(3) Strong adaptability: random forest can handle high-dimensional data without the need for feature scaling, making it suitable for various types of data, including classification and regression problems.