# An Integrated DQN and RF Packet Routing Framework for the V2X Network
## 3 Design of the IDRF System
### Offline Phase
#### 3.1.4. Utilizing Random Forests for the Prediction Unit  
The following rules are given to classify the dataset into sufficient and insufficient data and partition them into training, validation, and test sets. The corrected vehicle trajectory data, categorized as sufficient data, are used to train the RF prediction and DQN models. 1. On the rectified vehicle trajectories from the last seven days, taxis with a total timestamp count of fewer than 50 entries are categorized as vehicles with insufficient data. Other vehicles are classified as vehicles with sufficient data. 2. Sufficient data recorded on 2-5 February 2008 are assigned to the training set. 3. Sufficient data for 6-7 February 2008 are assigned to the validation set. 4. Sufficient data recorded on 8 February 2008 are assigned to the test set. In this study, for the prediction unit, regression RF, a supervised learning method, was employed. RF comprises decision trees and the bagging algorithm [34]. The decision tree uses a greedy approach to obtain distinct classification outcomes for each group. A tree is generated based on training data, and predictions are made for new samples according to the learned rules. The distance between the predicted result \(\hat{V}_{x}\) and the original target \(V_{x}\) is computed as the mean squared error (Equation (4)). \[Avg_{error}=\frac{1}{n}\sum_{i=1}^{n}\left(V_{x}-\ \hat{V}_{x}\right)^{2} \tag{4}\]  
The bagging algorithm is applied to a training set \(\text{S}=[V_{1},V_{2},\ldots\ldots,V_{x}]\). For a training set with \(V_{x}\) data points, each datum is sampled with a probability of \(\frac{1}{V_{x}}\), and the likelihood of not being sampled is \(1-\frac{1}{V_{x}}\). The probability of a datum not being selected during \(V_{x}\) sampling times is \((1-\frac{1}{V_{x}})^{V_{x}}\). As \(V_{x}\rightarrow\infty\), \(\left(1-\frac{1}{V_{x}}\right)^{V_{x}}\rightarrow\frac{1}{c}\cong 0.368\), meaning that approximately 36.8% of the data in the training set S remain unsampled after undergoing random sampling. Since these data points were not involved in the training process, they are used to assess the model's generalization capability. This study obtained  
Figure 12: Estimation of the average vehicle speeds for road segments. M independent training sets by repeatedly sampling N training data points in M rounds. The prediction approach is based on decision trees. By placing the M independent training sets into decision trees separately, the structure of the RF can be formed (Figure 13). The dataset was used in conjunction with the RF method. Trajectories typically lack regularity after the passenger gets in the taxi, increasing the prediction difficulty. However, given the characteristics of RF, which reduce inter-dataset correlations, a majority voting approach to predicting taxi movement trajectories is better suited for the dataset used in this study. From Figure 11, we can obtain the times at which vehicles enter intersections or road segments. The road segments are set as predictive targets. The rectified vehicle trajectory dataset, vehicle movement direction, and the set of target intersections are denoted as \(X=[(V_{1},\,S_{1},\,speed_{1},\,angle_{1}),\,(V_{2},\,S_{2},\,speed_{2},\,angle _{2}),\,\ldots,\,(V_{n},\,S_{n},\,speed_{n},\,angle_{n})],\,\,Y=[0]\) (_forward_), 1 (_left turn_), 2 (_right turn_)], and \(Z=[I_{1},\,I_{2},\,\ldots,\,I_{72}]\), respectively. The RF works as follows: Initially, the training set X is divided into M independent training sets using the bagging algorithm. Then, these M independent training sets are processed within decision trees. Based on each independent training set at every node, a splitting threshold is chosen from the designated label Y. This threshold is employed to partition the data at each node. We can obtain M decision trees and train with these M decision trees. After the completion of training, the mean squared error (MSE) is computed separately for M decision trees. For the training set X, predictions can be made through a majority vote by M decision trees.