# The Use of Machine Learning Methods in Road Safety Research in Poland
## 4 Mathematical Modeling of Road Safety in Poland
### RPart Classification with Cross-Validation  
The final proposed model is RPart classification with cross-validation. In this model, the present study began by selecting the \(cp\) complexity parameter, which controls the level of pruning in the decision tree. The higher the value of \(cp\), the more simplified the tree, which reduces the risk of overlearning but can lead to underlearning. Various \(cp\) values were tested, with the results summarized in Table 9.  
The optimal \(cp\) value, providing the highest accuracy and Kappa, was 0.0396, and therefore, this value was adopted for the model. The confusion matrix for the RPart classification with cross-validation is presented in Table 10.  
For RPart, the value of [PERSON]'s test statistic was very low (\(\chi^{2}\) < 2.2 \(\times\) 10\({}^{-16}\)), which indicates that similar to KNN and RF, this model makes classification errors in an asymmetric manner. The accuracy of this model is 62.86%, meaning it is moderate. Similar to the KNN and RF models, RPart performs well for certain classes but struggles to equally identify all of them.  
The results for each class are as follows:  
1. \"No injuries\": * Sensitivity: 97.13%--the model excels in identifying this class, likely due to its high representation in the dataset; * Specificity: 56.18%--the model struggles to distinguish this class from others, particularly \"minor injuries\"; * Balanced accuracy: 76.66%--while the majority of predictions for this class are correct, the model frequently misclassifies other classes as \"no injuries\".
2. \"Minor injuries\":  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Actual Class** & **No Injuries** & **Minor Injuries** & **Severe Injuries** & **Deaths** \\ \hline No injuries & 3420 & 1235 & 527 & 180 \\ Minor injuries & 101 & 1579 & 754 & 157 \\ Severe injuries & 0 & 0 & 0 & 0 \\ Deaths & 0 & 0 & 0 & 0 \\ \hline \hline \end{tabular}
\end{table}
Table 10: Confusion matrix for the RPart classification model with cross-validation for \(cp\) = 0.0396.  
\begin{table}
\begin{tabular}{c c c} \hline \hline
**cp** & **Accuracy** & **Kappa** \\ \hline
0.03964495 & 0.6369 & 0.3835 \\
0.06416431 & 0.6028 & 0.3172 \\
0.26971301 & 0.5315 & 0.1763 \\ \hline \hline \end{tabular}
\end{table}
Table 9: Results for different \(cp\) values.  
* Sensitivity: 56.11%--the model correctly identifies slightly more than half of the cases in this class;
* Specificity: 80.31%--the model is effective at recognizing when observations do not belong to \"minor injuries\" class;
* Balanced accuracy: 68.21%--most of the instances assigned to this class are correct.
3. \"Severe injuries\": * Sensitivity: 0%--the model completely fails to identify this class, with no cases correctly classified as \"severe injuries\";
* Specificity: 100%--no observations are misclassified into this class, but at the cost of completely ignoring this class;
* Balanced accuracy: 50.00%.
4. \"Deaths\": * Sensitivity: 0%--similar to the \"severe injuries\" class, the model does not identify any instances of this class;
* Specificity: 100%--the model never misclassifies other observations as \"death\";
* Balanced accuracy: 50.00%.