## 2 Experiment and Methods
### Prediction Method
#### 2.3.3 Hybrid RF Model Based on GA Optimization  
RF model parameters were optimized based on GA, including trees and leaves. The Tree Bagger algorithm in MATLAB was used to build the random forest model. In the running stage of the model, the initial number of trees was set to the default value of 500 [49], the initial number of leaves of each tree was set to 5 [50], and the initial default parameter value was used to input the importance analysis of indicator variables.  
In general, if the number of trees in the forest and the number of leaves per tree are less than the optimal number, underfitting may occur, resulting in a high model error rate. Overfitting occurs when the model is larger than the optimal number. Therefore, GA was proposed to optimize the number of trees and leaves to improve the prediction performance of RF model and reduce the error rate. The algorithm optimizes the number of trees and leaves by searching all possible optimal values of the objective function in the solution space. Figure 7 shows the GA-RF prediction flow chart for predicting oxygen concentration in the corner of return air.  
Figure 6: GA flow chart.  
Figure 7: Flow chart of random forest mixing model based on GA optimization.  
The process of the GA optimized RF hybrid model used to predict the oxygen concentration in the return air corner is as follows:  
Part 1: According to the collected samples, the data are divided into training samples and test samples. Through the importance analysis of the characteristic input indexes of the training samples, the input indexes are re-determined to improve the calculation efficiency and accuracy of the model.  
1. Determine training samples and test samples. Set RF model input, namely samples, and indicators.
2. Determine the number of trees and leaves in the forest. The recommended default number of trees is 500. The developers of the Tree Bagger algorithm suggested 5 leaves per tree as the default. Therefore, in this study, the initial trees in the forest and the number of leaves per tree are 500 and 5, respectively.
3. Use the \"Tree Bagger algorithm\" developed by MATLAB to train the RF algorithm. In this process, analyze the importance of indicator variables and screen out which input indicators will have a great impact on the output. Variable importance analysis is used to improve algorithm performance and reduce simulation time.
4. Modify the RF algorithm input according to the importance analysis results of indicator variables. Part 2: Based on the optimization of input variables and samples, GA was used to optimize the number of trees and leaves in RF to improve the accuracy of the prediction model.  
1. Determine the objective function. In this study, the objective function is to minimize the RMSE value between the sample predicted data and the actual data in the training stage. The objective function is:  
\[RMSE=\sqrt{\frac{1}{n}{\sum_{i=1}^{n}(f_{i}-y_{i})^{2}}} \tag{3}\]  
where \(n\) is the sample number, \(f_{i}\) is the actual value, and \(y_{i}\) is the predicted value.  
\[\begin{array}{c}f=\min(RMSE)\\ s.t.\left\{\begin{array}{l}1\leq leaf\leq 10\\ 1\leq\textit{ntrees}\leq 500\end{array}\right.\\ \end{array} \tag{4}\]
2. Initialize the genetic population
3. Evaluate the fitness of the initial population, select evolutionary individuals through roulette, carry out crossover and mutation operations, and update the fitness of the population.
4. Run Tree Bagger algorithm in GA training mode to optimize the number of trees and leaves based on \(f=\min(RMSE)\).
5. Update the population fitness to check whether it reaches the global optimal value. If so, go to the next step; otherwise, return the third step to make it reach the global optimal solution.
6. Determine the amount of trees and the number of leaves when the target function is optimal.
7. Stop the optimization process and transfer the optimal parameter values to the Tree Bagger algorithm. Part 3: Finally, the RF model is trained and tested using the corrected variable indicators and optimized parameters.