## 2 Short-Term Traffic Flow Prediction Model Construction
### Construction of SVR Short-Time Traffic Flow Prediction Model Based on Associated Roads
#### 2.2.4 Parametric Optimization  
In this paper, the selection of the kernel parameter \(\gamma\) and the penalty parameter C is optimized by grid search combined with cross-validation. The specific steps are as follows:  
1. Dataset preparation and division: Data preprocessing: The traffic flow data collected by the Xi'an ITS is preprocessed, including filling missing values, removing outliers, and normalization. The specific methods are as follows: Filling missing values: the interpolation method is used to fill the missing traffic flow data. Figure 5: SVR model prediction flowchart. Remove outliers: the outliers are identified and removed by the Z-score method. Normalization: all eigenvalues are normalized in the range of [0, 1] with the formula:  
\[\mathrm{z}=\frac{x-\mathrm{min}(x)}{\mathrm{max}(x)-\mathrm{min}(x)} \tag{17}\]  
Data division: The preprocessed dataset is divided into training set (80%) and test set (20%). From the training set, it is further divided into five mutually exclusive subsets for five-fold cross validation. 1. Parameter candidate value setting: Nuclear parameter \(\gamma\): the candidate value of \(\gamma\) is set to [0.1, 0.2,..., 10]. Penalty parameter C: the candidate value range of C is set to [0.1, 0.2,..., 200]. 2. Grid search and cross-validation: Parameter combinations: generate all possible (\(\gamma\), C) parameter combinations, a total of 100 \(\times\) 2000 = 200,000 parameter combinations need to be evaluated. Performance metrics: root mean square error (RMSE), mean absolute error (MAE) and mean relative error (MRE) are selected as performance evaluation metrics. Cross-validation cycle: for each pair of (\(\gamma\), C) parameter combinations, five-fold cross-validation is performed. The specific steps are as follows:  
Initialize the performance metrics: the variables should be set as follows: total_rmse = 0, total_mae = 0, and total_mre = 0. Iterate through each subset: For each subset, i (i = 1, 2,..., 5): Training and validation set division: the ith subset is used as a validation set, and the remaining four subsets are merged to form a training set. Model training: the training set data are used to train the SVR model and set the current \(\gamma\) and C parameters. Model validation: the validation set data are used to validate the trained model, and the performance metrics (RMSE, MAE, MRE) of the model are calculated. Record performance metrics: the performance metrics of the current validation set can result in the total performance metrics:  
\[ \begin{array}{l}total\_rmse+=rmse_{i}\\ total\_mae+=mae_{i}\\ total\_mre+=mre_{i}\end{array}  \tag{18}\]  
Calculate average performance indicator: the cumulative performance indicator is divided by 5 to obtain the average performance indicator for the current parameter combination:  
\[ \begin{array}{l}avg\_rmse=\frac{total\_rmse}{5}\\ avg\_mae=\frac{total\_mae}{5}\\ avg\_mre=\frac{total\_mre}{5}\end{array}  \tag{19}\]  
Selection of optimal parameter combinations: After iterating through all parameter combinations, the parameter combinations with the best average performance index (e.g., the smallest RMSE) are selected as the final kernel parameter \(\gamma\) and penalty parameter C. The optimal parameter combinations and their corresponding average performance indexes are recorded. Final model training and testing:  
Final model training: The SVR model is retrained using the entire training set data and the selected optimal combination of parameters. This step is to ensure that the model achieves the best performance on all available data. Test set evaluation: The final trained model is tested using the test set data to evaluate the performance of the model on unseen data. Performance metrics such as RMSE, MAE, and MRE are calculated for the test set. Result analysis: The performance of the model on the test set is analyzed to verify the generalization ability and prediction accuracy of the model.