# In-Vehicle Data for Predicting Road Conditions and Driving Style Using Machine Learning
## 5 ML Algorithms Implementation  
The used ML algorithms in this work are common and widely used in classification problems. Decision trees is a flowchart-like tree structure, where each internal node denotes a test on an attribute, each branch represents an outcome of the test and each leaf node (terminal node) holds a class label. A decision tree typically starts with a single node, which branches into possible outcomes. Each of those outcomes leads to additional nodes, which branch off into other possibilities. This gives it a treelike shape. More information about decision trees can be found in [26].  
Random forests is an ML algorithm constructed from many decision trees. The random forests algorithm establishes the outcome based on the predictions of the decision trees. It predicts by taking the average or mean of the output from various trees. More information about random forests can be found in [27].  
The support vector machine is an algorithm that tries to find a hyperplane to separate the data based on the classes. SVM finds boundaries that maximize the distance between the support vector data of each class. More information about SVM can be found in [28].  
As mentioned in the previous sections, three ML algorithms were implemented to classify the CAN data. The implementation was done in Python using Sklearn, Pandas,  
\begin{table}
\begin{tabular}{c c c c} \hline \hline \multirow{2}{*}{**Features**} & **Output 1: Road** & \multirow{2}{*}{**Output 2: Road**} & \multirow{2}{*}{**Output 3: Driving**} \\  & **Surface** & & \\  & **Conditions** & & **Style** \\ \hline AltitudeVariation & Smooth & Low traffic & Normal style \\ VehicleSpeedInstantaneous & Full of holes & Normal traffic & Aggressive style \\ VehicleSpeedAverage & Even condition & High traffic & \\ VehicleSpeedVariance & & & \\ VehicleSpeedVariation & & & \\ LongitudinalAcceleration & & & \\ EngineLoad & & & \\ EngineCoalComTemperature & & & \\ ManifoldAbsolutePressure & & & \\ EngineRFM & & & \\ MassAirFlow & & & \\ IntakeAirTemperature & & & \\ VerticalAcceleration & & & \\ FuelConsumptionAverage & & & \\ \hline \hline \end{tabular}
\end{table}
Table 1: The dataset input features and the output classes for the road conditions, traffic conditions and the driving style.  
Figure 2: The distribution of each class in the dataset: (**a**) Label distribution as a percentage for the road surface conditions. (**b**) Label distribution as percentage for the road traffic conditions. (**c**) Labels distribution as a percentage for the driving style.  
Scipy, Numpy and Matplot packages [29; 30; 31; 32]. The packages were used for ML implementation, results analysis and visualization. The dataset was divided to 80% for training and 20% for testing. This yields 19,965 samples for training and 4992 for testing.  
In the decision trees implementation, the minimum number of samples to split to an internal node is set to 2, while the minimum number of samples per leaf is set to 1. In total, 200 trees were used in the random forests implementation.  
SVM was implemented with radial basis function (RBF) kernel as the dataset is highly non linear, and the Kernel is needed to create accurate boundary conditions. The scaling parameter (\(\gamma\)) and the cost parameter were adjusted to achieve the best classification accuracy.