## 3 Causes of Health in Public Transport Operations
### Random Forest Model Optimization and Evaluation  
(1) Category imbalance problem  
The decision tree algorithm was used to judge the bus operation health class of Foshan Bus 101 for a total of 431 trips from 21 November to 25 November 2016. The statistics are shown in Figure 10. \begin{table}
\begin{tabular}{l} \hline \hline
**Random Forest Algorithm** \\ \hline
1: Input: Dataset \(\text{D}=\{(\text{x}_{1},\text{y}_{1}),\cdots,(\text{x}_{m},\text{y}_{m})\}\), Feature set \(\text{T}=\{\text{t}_{1},\cdots,\text{t}_{\text{d}}\}\) \\
1: k-base learners (Decision Tree Learners) \\
2: Take 70\% of the data as training set \(\text{D}_{\text{tr}}\) and 30\% of the data as test set \(\text{D}_{\text{te}}\) randomly \\ \hline
2: for i = i to k do \\
3: N samples are taken from data set D as the training set \(\text{D}^{*}\) for the i decision tree randomly and with put-back \\
4: Specify the constant \(\text{m}<\text{M}\) and randomly select a subset of m features from M features to form the feature set \(\text{T}^{*}\) \\
5: Build a decision tree model, TreeGenerate \((\text{D}^{*},\text{T}^{*})\), where each tree is grown to the maximum extent possible \\
6: end for \\
7: Generate k decision tree models \\ \hline \hline \end{tabular}  
8: All k models make classification predictions for test set \(\text{D}_{\text{te}}\) and return the most classified classification labels  
\end{table} 
Table 6: Random forest algorithm flow. Figure 10: Statistical chart of 101 road health level judgment. It can be seen that the samples are very unevenly distributed under the four health class categories, and the category imbalance can produce a significant interference in the learning process of the model, thus affecting the performance of the model. In a multi-categorization task, if the number of samples in different categories differs significantly, it is difficult for the learner to learn effective information from the category with a small number of samples, which results in the category with a small number of samples being incorrectly predicted as the category with a larger number of samples. An improved SMOTE oversampling algorithm proposed by [PERSON] [32] is used to solve this problem. The algorithmic flow of the SMOTE algorithm for sampling the samples is as follows. (1) For a sample \(x_{i}\) in a few categories, calculate its Euclidean distance from the surrounding samples and find the \(k\) nearest neighbors at the distance. (2) Select a sample \(x_{n}\) from the \(k\) nearest neighbors randomly. (3) Synthesize a new sample according to \(x_{i}\) and \(x_{n}\) according to the following formula. \[x_{new}=x_{i}+random(0,1)*|x_{i}-x_{n}| \tag{7}\]  
In Formula (7), \(random(0,1)\) denotes the generation of random numbers between 0 and 1. Instead of sampling the original samples by simply copying them randomly, the SMOTE algorithm generates new samples based on the original data by a determined algorithm, thus effectively alleviating the overfitting problem. In this paper, the SMOTE algorithm is used to achieve a ratio of 1:1:1:1 for the four types of samples. (2) Optimization of algorithm parameters  
Random forest algorithm differs from decision tree algorithm in that the main parameter is the n_estimators of the decision tree, and other algorithms are the same as decision tree. The common order of parameter optimization is: n_estimators, max_depth, max_features, min_samples_leaf, min_impurity_decrease. (1) n_estimators: refers to the number of tree models in the random forest, this parameter determines the size of the forest. If the n_estimators value is too small, it is easy to under-fit. However, if the value of n_estimators is too large, the forest is too large, which will increase the training time of the model. Draw the learning curve of n_estimators in the range (0-200). It can be seen from Figure 11 that the results are better in the range (50,120), and the model accuracy does not change much beyond 120. Therefore, the grid search range is (50,120).