# The Use of Machine Learning Methods in Road Safety Research in Poland
## 3 Analysis of Variables Describing Road Safety  
### The Selection of Variables for the Models  
Road safety is influenced by a wide range of factors that can contribute to hazardous events, often resulting in injuries or even fatalities among participants. The primary goal of this stage of the present study was to identify the variables with the most impact on road safety and select them for further analysis. To reduce the data dimensionality, a Random Forest model was employed to predict the variable representing the classification of injury severity. The model utilized 500 trees, and four variables were randomly selected at each split. The out-of-bag (OOB) error was 32.99%. This indicates that the model has difficulty in accurately predicting classes, especially for more complex categories, as shown by the confusion matrix (Table 2). \begin{table}
\begin{tabular}{c c c c c c} \hline
**Actual Class** & **No Injuries** & **Minor Injuries** & **Severe Injuries** & **Deaths** & **Class. Error [\%]** \\ \hline No injuries & 21,546 & 1811 & 106 & 13 & 8.22\% \\ Minor injuries & 4883 & 12,898 & 893 & 88 & 31.25\% \\ Severe injuries & 1677 & 5843 & 929 & 96 & 89.13\% \\ Deaths & 573 & 1245 & 266 & 164 & 92.70\% \\ \hline \end{tabular}
\end{table} 
Table 2: Confusion matrix for the Random Forest model. Based on the example of the category \"no injuries\", the values of the individual classification errors shown in Table 2 were calculated according to the following algorithm:  
\[Class.\ error=1-\frac{N_{11}}{\sum_{j=1}^{4}N_{1j}}\times 100\%, \tag{13}\]  
\[Class.\ error=1-\frac{21,546}{21,546+1811+106+13}\times 100\%=8.22\%. \tag{14}\]  
The model performs best with the \"no injuries\" category, achieving a low classification error rate of 8.22%. However, the results are less accurate for more severe categories of injuries. For the \"minor injuries\" category, the accuracy is moderate, with an error rate of 31.25%. In contrast, the error rates for the \"severe injuries\" and \"deaths\" categories are significantly higher, at 89.13% and 92.70%, respectively. The variables used in the model were ranked based on their mean decrease Gini values, as presented in Table 3.  
Nevertheless, the purpose of this stage of the present study was to extract the variables with the strongest impact, which are included later in this study (Section 4). A total of 11 predictors were selected, as illustrated in Figure 2.  
Using the extracted variables (Figure 2), a new Random Forest model was constructed with 500 trees. Three variables were randomly selected for each split. The estimated total error improved slightly to \(OOB=33.31\%\), indicating that approximately 33% of the observations were misclassified by the model. The confusion matrix for this model is presented in Table 4. \begin{table}
\begin{tabular}{c c c} \hline \hline
**No.** & **Variable** & **Mean Decrease Gini** \\ \hline
1 & Vehicle type & 3349.19403 \\
2 & Driver behavior & 3265.63861 \\
3 & Voivodeship & 2290.05636 \\
4 & Type of accident & 2161.99595 \\
5 & Type of accident & 2096.33577 \\  & participant & \\
6 & Day of the week & 1319.50264 \\
7 & Place of accident & 961.22562 \\
8 & Speed limit & 811.02891 \\
9 & Lighting & 671.76051 \\
10 & Sex & 601.05397 \\
11 & Pedestrian behavior & 466.14488 \\
12 & Type of road & 456.43282 \\
13 & Seat in the vehicle & 410.70926 \\
14 & Crossroad & 375.25493 \\
15 & Horizontal road marking & 313.85263 \\
16 & Type of area & 244.81922 \\
17 & Weekend day & 228.06105 \\
18 & Traffic light & 223.69613 \\
19 & Feast day & 137.43232 \\
20 & Other causes & 130.26838 \\
21 & Public road & 58.53400 \\
22 & Road surface & 44.12633 \\
23 & Traffic zone & 33.36683 \\
24 & Residential zone & 27.65299 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Mean decrease Gini for the studied variables. The classification errors shown in Table 4 were calculated in the same way as for the previous Random Forest model (Equations (13) and (14)).