# A New SDN-Based Routing Protocol for Improving Delay in Smart City Environments
## 3 Machine Learning Algorithms
### DataSet Generation and Processing  
To collect the vehicle data, we simulate the traffic in a real-life scenario on a testbed built using the SUMO simulator and a real map of downtown Montreal extracted via the OpenStreetMap framework [38, 39, 40].  
The most important information that helps us in the creation of the dataset is the configuration of the road network with the identification of roads and trails, traffic infrastructure (e.g., traffic lights) and traffic demand discussed in [39], which provides the number of vehicles present at each intersection of the road network, as shown in Figure 2. We simulate the scenario several times and calculate the statistical data using the Traci and Calibrator package provided by SUMO [41].  
As indicated in [41], we count the number of vehicles passed over a road segment by implementing a calibrator object at each intersection. The calibrator controls and calculates crossing vehicles at the junction. If the computed value reaches a specified amount by Montreal's openData portal, the calibrator framework removes the fleet exceeding the specified target level. Besides, if the traffic request does not match the specified value, the calibrator inserts new vehicles.  
We save the data simulation in CSV file to clean and process the dataset, as shown in Figure 3, then we extract the necessary features used in our solution. We label each column of the CSV file, and we remove non-valid values, then we erase columns to reduce unnecessary data. We label the columns to identify the features by: node_id: Vehicle_id, TT: travel_time, RSTh: historical road segment travel, CT: current time, RT: trajectory time on the segment of road, TD: trajectory direction, ST: speed travel, XP: X-axis position, YP: Y-axis position, AN: Area number and RSU-Addr: roadside unit address. It should be noted that the Naive Bayes algorithm is based on strong (naive) independence assumptions among the various features. For this reason, we review and assess each feature pair's correlation matrix, including Pearson's correlation coefficients, as illustrated in Figure 4. The matrix correlation shows the level of dependency between the attributes to keep only the most independent.  
Figure 3: Dataset processing and Model testing stages [42].  
Figure 2: Montreal Real Scenario Testbed built using Sumo and OpenStreetMap.  
Pearson's correlation coefficients show mainly that the features are closer to zero, which means that no linear relationship is present in the data. Besides, the negative values indicate that one variable tends to decrease as the other increases. On the other hand, the positive coefficients highlight that as one feature value increases, the other tends to increase. By the end of dataset processing that contains more than 1,000,000 instances, we test the ML model to evaluate its accuracy by varying the number of occurrences fed to the train part and validation part. The obtained results in Table 1 help us choosing the percentage of splitting the dataset. We observe that the accuracy of the model is advantageous and is over 90% for all dataset size variation. The efficiency for 70%-30% splitting and 80%-20% are close, but the third column is suitable for the choice of dividing the dataset while it shows the best accuracy results.  
The ML algorithm works is a very dynamic environment, which induces a high variance of the data, and herby, after some time, the model's performance may deteriorate. Therefore, the ML algorithm must be retrained. Still, excessive retraining generates more computation time and adds complexity to the model implementation by including new modules such as that monitors the performance of the system. While, at each time a new routing request is received, the controller retrained the Naive Bayes method to maintain its efficiency; thus, it must use fewer resources.