wuframeworkrealtimetraffic2025.md 114 KB


category: literaturenote citekey: wuframeworkrealtimetraffic2025 title: A framework for real-time traffic risk prediction incorporating cost-sensitive learning and dynamic thresholds authors: "Wu, Dan; Xing, Lu; Li, Ye; Wong, Yiik Diew; Lee, Jaeyoung Jay; Dong, Changyin" year: 2025 date: 2025-00-00 2025 doi: 10.1016/j.aap.2025.108087 publication: "Accident Analysis & Prevention" url: "https://doi.org/10.1016/j.aap.2025.108087" zotero_key: F5U3IR7B zotero_storage: E2QSNH45 collections: transpordi_planeerimine folder: 001_artiklid firstAuthor: "Wu, Dan"

status: converted

Contents lists available at ScienceDirect

Accident Analysis and Prevention

journal homepage: www.elsevier.com/locate/aap

A framework for real-time traffic risk prediction incorporating cost-sensitive learning and dynamic thresholds

Dan Wu a,b , Lu Xing c,d,e,\* , Ye Li a , Yiik Diew Wong b , Jaeyoung Jay Lee a,f , Changyin Dong g,h

  • a School of Traffic and Transportation Engineering, Central South University, Changsha, Hunan 410075, China
  • b School of Civil and Environmental Engineering, Nanyang Technological University, 639798, Singapore
  • c School of Automation, Central South University, Changsha, China
  • d Department of Automation, Tsinghua University, Beijing, China
  • e Hunan Key Laboratory of Smart Roadway and Cooperative Vehicle-infrastructure Systems, Changsha University of Science &Technology, China
  • f Department of Civil, Environmental & Construction Engineering, University of Central Florida, Orlando, FL 32816, USA
  • g School of Aeronautics, Northwestern Polytechnical University, Xi'an 710072, China
  • h National Key Laboratory of Aircraft Configuration Design, Xi'an 710072, China

ARTICLE INFO

Keywords: Traffic safety Risk prediction Cost-sensitive learning Dynamic thresholds Genetic algorithm

ABSTRACT

In recent years, researchers have explored an innovative approach that leverages real vehicle trajectory data to simultaneously derive traffic state and risk level for real-time risk prediction, which is crucial for traffic safety. However, existing studies largely overlook the costs associated with incorrect predictions and the varying consequences of different misclassifications, which undermines the reliability of the obtained prediction results. To address these gaps, this study refined traffic risk classification into four levels (i.e., no, low, medium, and high risks) and incorporated misclassification costs into the prediction process through cost-sensitive learning (CSL). Furthermore, considering that multi-class prediction tasks often face performance degradation and increased risk level granularity worsens class imbalance, further amplifying this degradation, this study introduced dynamic thresholds (DTs) to improve model performance. The aforementioned cost coefficients and thresholds were pinpointed using a genetic algorithm (GA). Furthermore, the employed data, comprising variables related to traffic state and associated risk data, were sourced from the HighD dataset. Subsequently, CSL-DTs-based models were built by integrating CSL and DTs with four distinct baseline machine/deep learning models, and the prediction performance (e.g., precision) and computation time of these models were compared. Results show that, compared to the corresponding baseline models, the proposed models perform better for multi-class prediction tasks. Additionally, the computation time of the CSL-DTs-based models is found to be acceptable for real-time prediction purposes. Finally, to ensure the reliability of the results obtained through the GA optimization (e. g., avoiding local optima), convergence curves were plotted, confirming the robustness of the optimization process. A robustness analysis also demonstrates that the models are highly stable under slight perturbations of cost coefficients and thresholds, with minimal impact on performance. Findings of this study are expected to enhance the reliability of real-time traffic risk prediction, holding the promise of significantly promoting proactive traffic safety management.

1. Introduction

Roadway crashes are one of the leading contributors of death worldwide, resulting in significant fatalities, injuries, and property damage (Yan et al., 2021; Wu and Wu, 2024a,b; Wu et al., 2024a,b). The World Health Organization (2023) reports that globally about 1.19 million people die annually in roadway crashes, making traffic safety a critical global issue. As traffic volumes continue to increase with economic growth, investigating crash risks becomes essential for improving traffic safety (Hu et al., 2022; Wu et al., 2024c,d).

E-mail addresses: danwucsu@163.com (D. Wu), luxing@csu.edu.cn (L. Xing), yelicsu@csu.edu.cn (Y. Li), CYDWONG@ntu.edu.sg (Y.D. Wong), jaeyoung@ knights.ucf.edu (J.J. Lee), dongcy@nwpu.edu.cn (C. Dong).

https://doi.org/10.1016/j.aap.2025.108087

Received 28 January 2025; Received in revised form 7 April 2025; Accepted 28 April 2025

Available online 5 May 2025

0001-4575/© 2025 Elsevier Ltd. All rights are reserved, including those for text and data mining, AI training, and similar technologies.

* Corresponding author.

In recent years, researchers have conducted numerous studies to improve traffic safety and reduce roadway crashes (Abdel-Aty and Pemmanaboina, 2006; Dong et al., 2018; Rahim and Hassan, 2021; Rashidi et al., 2022), including crash prediction based on historical crash data and risk prediction based on microscopic trajectory data. However, both data types have limitations. To address this, it is crucial to establish a clear link between traffic state and risk variables, which holds significant practical advantages for predicting risk in real time. Herein, this research area requires further exploration to advance realtime risk prediction and improve safety.

The remainder of this study is organized as follows: Section 2 presents a comprehensive literature review, which includes a detailed discussion of the research objectives derived from the reviewed literature. Section 3 describes the procedures for data preparation, traffic safety evaluation, and the development of risk prediction methods and associated models. Section 4 provides the results of risk prediction before and after considering the costs associated with erroneous predictions and the dynamic thresholds, aiming to validate the superiority and reliability of the results obtained by the proposed model. Finally, Section 5 concludes with key findings and outlines potential directions for future research.

2. Literature review

The importance of real-time prediction for traffic safety enhancement is widely recognized (Slikboer et al., 2020; Yu et al., 2021; Mohanty et al., 2023; Huang et al., 2024). As a result, substantial research has been invested in exploring real-time prediction of traffic crashes and risks.

The main objective of traffic crash prediction is to predict the occurrence of crashes, with studies also exploring crash severity, frequency, types, underlying crash mechanisms and potential intervention strategies (Kim et al., 2006; Xu et al., 2015; Abdulhafedh, 2016; Iranitalab and Khattak, 2017; Berhanu et al., 2023; Thapa et al., 2024). Indicators of traffic state variables such as averages, standard deviations, and other statistical measures related to speed, flow, and occupancy, serve as key inputs to crash prediction models (Lord et al., 2005; Abdulhafedh, 2017; Yang et al., 2022). Non-traffic factors, including road geometry, weather, lighting, and social characteristics, are also integrated into some models (Rafael et al., 2018; Gutierrez-Osorio and Pedraza, 2020). Crash prediction models primarily utilize machine learning, deep learning, and statistical approaches. Common machine learning techniques include Random Tree (RT), Bayesian Networks (BN), among others (Gholamzadeh et al., 2022). For deep learning, popular models include Convolutional Neural Networks (CNN), Recurrent Neural Networks (RNN), among others (Tian et al., 2018; Balderas et al., 2019). However, these methods are often criticized for their limited interpretability, as they function as "black boxes" with insufficient insight into the influence of selected variables on crash outcomes. On the other hand, statistical models allow for a more explicit understanding of causality between traffic/non-traffic variables and crashes. Common statistical models include Multinomial Logistic Regression (MLR), Bayesian Logistic Regression (BLR), Poisson Regression (PR), among others (Araldi, 2020; Kenntemich et al., 2024).

For traffic risk prediction, it is advantageous because risks occur more frequently than crashes, with theoretical foundations dating back to the 1970 s (Hayward, 1972). The "Haddon Matrix" provides a structured framework for understanding traffic risk levels and their association with crash likelihood (Aghayari et al., 2021), making traffic risk a logical focus for safety analysis. Regarding risk measurement, Mahmud et al. (2019) reviewed alternative safety indicators for traffic risk assessment and discussed methods for calibration and validation. Shi et al. (2018) proposed critical risk indicators for assessing risk severity and the likelihood of occurrence, while Ismail et al. (2011) examined risk severity through different thresholds of risk assessment indicators. Some studies also assessed risks at signalized intersections by

considering both the probability and severity of risk events (Alhajyaseen, 2014). Furthermore, Oh and Kim (2010) developed a realtime rear-end risk assessment method based on vehicle-following interactions. Trajectory data-driven methods have also gained attention in traffic risk prediction. These data are often collected via traffic monitoring systems or video processing technology and provide insights into vehicle motion that can enhance traffic risk analysis. For example, Xing et al. (2019) used traffic video data to obtain vehicle trajectories and introduced the Extended Time-to-Collision (ETTC) index to evaluate single-vehicle collision risk. Similarly, Formosa et al. (2020) utilized ADAS technology and deep neural networks to predict traffic risk from in to vehicle sensor data and traffic detection systems. Additionally, Yu et al. (2021) analyzed HighD vehicle trajectory data to explore the impact of traffic flow on the likelihood of high-risk events in individual vehicles. Simulated platforms such as the Surrogate Safety Assessment Model (SSAM) combined with VISSIM simulation are also frequently used for risk analysis (Fan et al., 2013). Katrakazas et al. (2017) created a real-time risk prediction model utilizing vehicle-level traffic data from VISSIM and risk data generated by SSAM. Moreover, Charly and Mathew (2019) explored interactions between different vehicle types by combining data from the Federal Highway Administration's Next Generation Simulation (NGSIM) project and VISSIM simulation data. Much like crash prediction, real-time traffic risk prediction often involves machine/deep learning and statistical methods. While these methods have inherent limitations regarding interpretability and prediction accuracy, integrating these approaches has been proposed as a more robust solution (Hu et al., 2022; Wu et al., 2024a,b).

As mentioned above, researchers have conducted a series of studies to enhance traffic safety in recent years, including traffic crash and risk prediction. By analyzing historical crash data, a correlation between traffic conditions and crashes can be established, thereby enabling more accurate crash prediction. However, the crash data have several limitations, such as under-reporting, inconsistent data collection, and potential misjudgment of crash risks at specific locations (Li et al., 2020,2021). An example of this is that a location may exhibit no recorded crashes within a given period, yet it may still pose a risk. Moreover, collecting sufficient crash data is challenging due to the infrequency of crashes (Schmidt and Vega-Westhoff, 2019). To overcome the mentioned limitations of the historical crash data, researchers have investigated supplementary data sources, such as vehicle trajectory data, to predict traffic risk and improve traffic safety (Lin et al., 2015; Zheng et al., 2018; Park and Hong, 2022). Nevertheless, collecting and analyzing trajectory data is time-intensive and lacks real-time feedback. Furthermore, the large volume of characteristics and superfluous information makes practical implementation of remediation measures challenging.

To address the aforementioned challenges, it is crucial to establish a clear link between traffic state and risk variables, which holds significant practical advantages for predicting risk in real time (Hu et al., 2022; Yuan et al., 2022; Wu et al., 2024a,b). Specifically, risk data are more readily obtainable than crash data due to their higher frequency, while traffic state information can be efficiently collected through detectors, such as loop detectors, over short time intervals. The easily accessible data are crucial for real-time predictions. Recognizing the limitations of existing road sensors in simultaneously capturing both traffic state and risk data within a short timeframe (Wan et al., 2017), a few studies extracted these two types of data from trajectory datasets. By aggregating trajectory data to extract both traffic state and corresponding risk information, a clear relationship can be established for offline training of the risk prediction model. Once trained, real-time traffic state data from detectors can be input into the model to predict near-term risks within specific spatial and temporal contexts.

To the best of the authors' knowledge, only a limited number of studies have investigated the relationship between traffic risk and state variables for predicting risk in real time (Hu et al., 2022; Yuan et al., 2022; Wu et al., 2024a,b). Furthermore, from a practical application

Fig. 1. Research framework.

perspective, these existing studies have not considered the costs associated with erroneous predictions or the varying costs in different misprediction scenarios. For instance, predicting a high-risk state as safe could pose a significant threat to traffic safety, whereas predicting a safe state as risky would primarily impact traffic efficiency. Besides, given that the negative safety implications of prediction errors vary significantly across different levels of risk, the present study would further refine traffic risk levels and incorporate the costs associated with different types of prediction errors, thereby enhancing the reliability of prediction outcomes.

In the context of multi-class prediction tasks, model performance tends to be lower (Jurman and Furlanello, 2010; Theissler et al., 2022; Aguilar-Ruiz and Michalak, 2024). Therefore, as traffic risk is disaggregated into several classes in this study, the issue of class imbalance is likely to lead to weaker prediction results. This would pose lead to degraded performance in real-time risk prediction. Consequently, the introduction of dynamic thresholds becomes essential, as they can optimize the decision thresholds for each class, thereby enhancing prediction performance. It is worth noting that data balancing methods, such as over-sampling and under-sampling, commonly used to address class imbalance, inherently influence the decision thresholds. This is because the model's default threshold is typically influenced by the class distribution (Kim and Kim, 2020; Esposito et al., 2021). However, these methods can alter the distribution of the training data, which may, in turn, affect the learned feature representations of the model. Therefore, this study proposes the dynamic thresholds to address the class

imbalance issue. By dynamically adjusting the thresholds based on the characteristics of the actual samples, it is expected that a more significant improvement in model performance can be achieved.

Overall, this study aims to fill the aforementioned research gap by addressing the following three key issues: (1) comparing the prediction performance before and after the introduction of costs associated with prediction errors and dynamic thresholds, to validate the superiority of the proposed model in risk prediction; (2) conducting a thorough evaluation of the model's suitability for real-time risk prediction applications, taking into account factors such as prediction accuracy and computation time; and (3) verifying the reliability of the obtained prediction results.

3. Methodology

This study proposes an innovative research framework that incorporates cost-sensitive learning to account for the varying costs of prediction errors in different scenarios, while introducing dynamic thresholds to enhance the performance of traffic risk prediction. Fig. 1 depicts the proposed research framework, comprising two main components:

(a) Data preparation. Short-term vehicle trajectory data can be collected during a specific time interval, which include traffic state and corresponding risk data calculated based on selected safety evaluation indicators. Besides, the risk data were further

Table 1 Classification scenarios for traffic risk prediction.

| True class | Predicted class | | | | | | | | |------------|-----------------|----|----|----|--|--|--|--| | | NR | LR | MR | HR | | | | | | NR | √ | × | × | × | | | | | | LR | × | √ | × | × | | | | | | MR | × | × | √ | × | | | | | | HR | × | × | × | √ | | | | |

Note: The checkmarks and crosses in the table represent correct and incorrect predictions, respectively.

  • defined as multi-classes: No Risk (NR), Low Risk (LR), Medium Risk (MR), and High Risk (HR).
  • (b) Modelling methods. To improve the reliability of risk prediction results using machine learning models, this study employed a cost-sensitive learning approach that accounts for the varying costs of prediction errors in different scenarios. Specifically, the mentioned misprediction scenarios encompass 12 distinct types, as highlighted in the shaded areas of Table 1. This approach as proposed in this study allows the prediction model to better balance the impact of misclassification errors, leading to more accurate and reliable prediction outcomes. Additionally, given that the prediction target in this study involves multi-class variables, the prediction performance is often suboptimal (Jurman and Furlanello, 2010; Theissler et al., 2022; Aguilar-Ruiz and Michalak, 2024). To address this, dynamic thresholds were introduced to enhance the prediction results. Furthermore, to better determine the cost values associated with the cost-sensitive learning and the dynamic thresholds used in this study, a genetic algorithm (GA) was employed.

3.1. Data processing and safety evaluation

HighD dataset, known for its comprehensive traffic coverage and low vehicle positioning error, has been widely used in traffic safety analysis (Kruber et al., 2019; Mahajan et al., 2020; Chen et al., 2022; Wang et al., 2023). This study used vehicle trajectory data extracted from the HighD dataset, which includes information on 110,000 vehicles within a collection of 60 individual datasets. These data were gathered at six distinct freeway locations near Cologne, Germany, in weather conditions characterized by clarity and calm winds, spanning the hours of 8:00 am to 5:00 pm throughout 2017 and 2018. The drone-based measurements, with an average recording duration of 17 min, cover approximately 420 m of freeway. Additionally, vehicle trajectories were extracted using computer vision techniques, supplemented by manually annotated road markings. The dataset includes frame timestamps (captured at 25 frames per second), vehicle type, longitudinal (x) and lateral (y) positions, velocities, driving direction, surrounding vehicles' IDs, and lane positions. Further details can be found on the HighD website (RWTH, 2018).

In this study, short-term vehicle data were collected at lane level, specifically excluding on– and off-ramps. The data processing procedure is illustrated in Fig. 2. As shown in the figure, the lanes were classified into three types: inner, middle, and outer lanes. This classification of lanes is intended to provide a more accurate and detailed understanding of traffic flow. Subsequently, traffic state variables at upstream and downstream locations were extracted utilizing a 10-second time aggregation interval. As shown in Table 2, these extracted variables served as the independent variables in the adopted prediction model, including traffic flow, average speed, density, and average width of vehicles at both upstream and downstream positions. Besides, Table 2 also presents the descriptive statistical analysis results of these variables, including the mean, standard deviation, maximum, and minimum values for all the selected variables. The dependent variable, which represents risk

data, is a four-class variable (further details can also be found in Table 2), indicating the presence of risk state within the designated time interval in the study area. More detailed procedure for the risk level classification is provided in Algorithm 1, with a summary outlined as follows:

(1) Safety evaluation using the Time-to-Collision (TTC) indicator: The TTC value for each time node was calculated based on Eq. (1), with TTC being the most commonly used measure for safety evaluations (Vogel, 2003; Meng and Qu, 2012; Huang et al., 2013; Li et al., 2020,2021; Hu et al., 2022; Xing et al., 2023; Wu and Wu, 2024a,b; Wu et al., 2024a,b,c). The TTC represents the time it would take for a following vehicle to collide with the vehicle ahead, assuming both vehicles continue to travel along their current speed and trajectories. The TTC for a following vehicle i at time step t relative to the leading vehicle i − 1 can be calculated as follows:

$$TTC{i}(t) = \begin{cases} \frac{x{i-1}(t) - x{i}(t) - L{i-1}}{\nu{i}(t) - \nu{i-1}(t)}, & \text{if } \nu{i}(t) > \nu{i-1}(t) \ \nu{i}(t) - \nu{i-1}(t) \leq \nu_{i-1}(t) \end{cases}$$

$$(1)$$

where xi− 1, vi− 1 and Li− 1 are the position, speed and length of the leading vehicle, respectively; and xi and vi denote the position and speed of the following vehicle, respectively.

  • (2) Weight assignment based on TTC values: To demarcate between safe and risky situations, a predefined threshold for TTC values should be applied. Any TTC value between zero and the threshold is considered risky, while values outside this range are regarded as safe. Furthermore, different threshold values help assess the severity of the risk. Previous studies have utilized diverse TTC thresholds, typically spanning from 1 to 4 s (Vogel, 2003; Wu and Wu, 2024a,b; Wu et al., 2024a,b,c). Accordingly, this study adopted different TTC thresholds to classify risk levels. Specifically, based on the TTC values calculated in Step (1), the risk levels and corresponding weights were assigned as follows (Ma et al., 2025):
    • 1. A TTC value greater than 4 was classified as NR, with a weight of 0.
    • 2. A TTC value between 3 and 4 was classified as LR, with a weight of 1.
    • 3. A TTC value between 2 and 3 was classified as MR, with a weight of 2.
    • 4. A TTC value between 0 and 2 was classified as HR, with a weight of 3.
  • (3) Total and average weight calculation: The weight for each time node was calculated based on its corresponding TTC value obtained in Step (2). The total weight was then determined by summing the weights over the entire 10-second interval. Furthermore, the cumulative total weight was divided by the total number of time nodes in the 10-second interval to compute the average weight.
  • (4) Risk classification: The average weight calculated in Step (3) was used to classify the overall traffic risk level within the selected time interval (i.e., 10 s) as follows:
    • 1. An average weight of 0 indicates "NR", assigned a value of 0 for the model's dependent variable.
    • 2. An average weight between 0 and 1 was classified as "LR", assigned a value of 1 for the model's dependent variable.
    • 3. An average weight between 1 and 2 was classified as "MR", assigned a value of 2 for the model's dependent variable.
    • 4. An average weight between 2 and 3 was classified as "HR", assigned a value of 3 for the model's dependent variable.

Fig. 2. Process of data extraction. Note: For the definitions of the abbreviations in the figure, please refer to Table 2.

Table 2 Definitions and descriptive statistics of extracted variables.

Variable Description (Unit) Inner lane Middle lane Outer lane
Mean Std Min Max Mean Std Min Max Mean Std Min Max
Explanatory
variable
UF Number of vehicles identified upstream
(veh/10 s)
1.60 0.90 1.00 6.00 1.56 0.84 1.00 6.00 1.38 0.66 1.00 5.00
UD UAS Average speed of vehicles identified
upstream (m/s)
Vehicle density identified upstream
(veh/10 m)
7.89 4.18 44.20 24.29 7.40 1.66 36.93 20.03 6.43 1.46 35.66
0.06 0.02 0.48 0.08 0.08 0.03 0.72 0.09 0.08 0.03 0.68
UAW Average length of vehicles detected
upstream (m)
4.75 0.46 3.64 7.28 5.38 2.28 2.93 19.10 9.59 5.12 3.44 20.11
DF Number of vehicles identified
downstream (veh/10 s)
1.92 1.14 1.00 9.00 1.82 1.03 1.00 9.00 1.45 0.74 1.00 5.00
DAS Average speed of vehicles identified
downstream (m/s)
29.13 7.71 3.09 44.47 27.41 6.41 2.79 41.31 23.25 5.40 2.52 39.92
DD Vehicle density identified downstream
(veh/10 m)
0.08 0.09 0.02 0.93 0.08 0.08 0.02 0.81 0.07 0.06 0.03 0.49
DAW Average length of vehicles detected
downstream (m)
4.72 0.44 2.83 7.28 4.93 1.50 2.83 21.93 8.21 4.91 2.83 21.93
Dependent
variable
Risk 0, 1, 2 and 3 stand for NR, LR, MR and
HR, respectively.
0.45 0.73 0.00 3.00 0.47 0.77 0.00 3.00 0.48 0.79 0.00 3.00
Sample size 11,780 13,031 8,770

Algorithm 1. Pseudocode for identifying traffic risk classification.

Input: A list of TTC values for each time node over 10 s (TTC_list). 
  Output: A risk classification (NR, LR, MR, HR) 
  1: Define weight ranges based on TTC values: 
    4 < TTC → weight = 0 (NR) 
    3 < TTC ≤ 4 → weight = 1 (LR) 
    2 < TTC ≤ 3 → weight = 2 (MR) 
    0 < TTC ≤ 2 → weight = 3 (HR) 
  2: Initialize total_weight = 0 
  3: Initialize total_time_nodes = Length (TTC_list) 
  4: for each TTC_value in TTC_list do 
  5: if 4 < TTC_value then 
  6: weight = 0 
  7: else if 3 < TTC_value ≤ 4 then 
  8: weight = 1 
  9: else if 2 < TTC_value ≤ 3 then 
  10: weight = 2 
  11: else if 0 < TTC_value ≤ 2 then 
  12: weight = 3 
  13: end if 
  14: total_weight += weight 
  15: end for 
  16: Calculate the average_weight = total_weight / total_time_nodes 
  17: if average_weight == 0 then 
  18: risk = "NR" 
  19: else if 0 < average_weight ≤ 1 then 
  20: risk = "LR" 
  21: else if 1 < average_weight ≤ 2 then 
  22: risk = "MR" 
  23: else if 2 < average_weight ≤ 3 then 
  24: risk = "HR" 
  25: end if 
  26: Return the risk classification (NR, LR, MR, HR)

3.2. Traffic risk prediction

Predicting traffic risk using machine learning models is essential for enhancing traffic safety. In this study, six categories of models were employed, including four machine learning models — K-Nearest Neighbors (KNN), Random Forest (RF), Decision Tree (DT), and Support Vector Machine (SVM) — which are widely used in traffic research and are well-suited to the objectives of this study, involving a four-class classification task (Boulesteix et al., 2012; Imandoust and Bolandraftar, 2013; Huang et al., 2018). Additionally, two deep learning models were also incorporated: Long Short-Term Memory (LSTM) and eXtreme Gradient Boosting (XGBoost), chosen for their advanced capabilities in handling complex, multi-class classification problems and

enhancing prediction performance (Charbuty and Abdulazeez, 2021). Besides, the decision to limit the models to these six, excluding more complex approaches like transformer-based models, is driven by the primary objective of this study, i.e., to assess whether incorporating cost-sensitive learning and dynamic thresholds into baseline models can significantly improve prediction performance (e.g., precision) while maintaining a manageable computational burden. In other words, the proposed research framework is valuable for real-time traffic risk prediction as it balances both performance and computational efficiency. Accordingly, the newly proposed models in this study are extensions of the selected baseline models (i.e., KNN, RF, DT, SVM, LSTM and XGBoost) with additional considerations (i.e., cost-sensitive learning and dynamic thresholds). The resulting models are termed CSL-DTs-KNN, CSL-DTs-RF, CSL-DTs-DT, CSL-DTs-SVM, CSL-DTs-LSTM and CSL-DTs- XGBoost, where "CSL" stands for cost-sensitive learning and "DTs" for dynamic thresholds. More details of these proposed models can be found in the Appendix A.

To evaluate and compare the performance of the employed prediction models, three metrics were utilized. The first metric is the Area Under the Receiver Operating Characteristic Curve (AUC), which provides a comprehensive evaluation of the model prediction performance. Given that the target variable is a four-class classification and more emphasis should be placed on the minority class, which represents risky scenarios characterized by a limited number of samples and where erroneous classification tends to result in higher traffic risks, the Macroaverage AUC (MA-AUC) was further employed for evaluation. This metric aggregates the AUC scores for each class, giving equal weight to each class regardless of sample size, thus highlighting the model's performance on less represented classes (Mortaz, 2020). Similarly, this study applied the Macro-average F1-score (MA-F1-score), which extends the standard F1-score (as defined by Eq. (2)) by calculating a weighted average of F1-scores across different classes, providing a more nuanced evaluation in multi-class settings. Lastly, a confusion matrix bar chart was used to visualize the prediction performance of the four-class classification. Each bar represents the prediction precision for a specific class (as defined in Eq. (3)). Consequently, the bar chart clearly delineates the model's ability to distinguish between different classes.

$$F1-\textit{score}_i = \left(2 \bullet \frac{\textit{TP}_i}{\textit{TP}_i + \textit{FP}_i} \bullet \frac{\textit{TP}_i}{\textit{TP}_i + \textit{FN}_i}\right) \bigg/ \left(\frac{\textit{TP}_i}{\textit{TP}_i + \textit{FP}_i} + \frac{\textit{TP}_i}{\textit{TP}_i + \textit{FN}_i}\right) \tag{2}$$

$$Precision_i = \frac{TP_i}{TP_i + FP_i} \tag{3}$$

Fig. 3. Process of optimizing the prediction results Note: The green, yellow, and blue lines in the figure represent the following processes: data processing, initial model prediction process, and prediction process based on the optimized model, respectively. (For interpretation of the references to colour in this figure legend, the reader is referred to the web version of this article.)

where Precisioni refers to the precision of Class i, TPi and FPi represent the number of true positive and false positive samples for Class i, respectively. FNi denotes the number of positive samples that were incorrectly predicted as negative.

Furthermore, to determine the optimal cost and threshold values for the proposed models, this study proposed using GA to optimize both the mentioned values, thereby ensuring the model performance. An explanation of how a GA can be utilized to identify the optimal solution is outlined below.

First of all, the cost of different types of prediction errors can be represented using a cost matrix:

$$C{ij} = \begin{bmatrix} C{00} & C{01} & C{02} & C{03} \ C{10} & C{11} & C{12} & C{13} \ C{20} & C{21} & C{22} & C{23} \ C{30} & C{31} & C{32} & C_{33} \end{bmatrix}$$ (4)

where each element Cij represents the cost of predicting Class i as j. It should be noted that the specific circumstances corresponding to Cij are in one-to-one correspondence with the positions of the classification scenarios in Table 1. The definition rules for the coefficients in this cost matrix will be elaborated in detail in the subsequent section on the GA's fitness function.

Secondly, to define the decision boundaries for the predicted probabilities of each class in a multi-class classification problem, a threshold vector ( *T0, T1, T2, T*3 ) was introduced. Specifically, Ti (for Class , i = 0, 1, 2, 3) mean the threshold for the NR, LR, MR and HR. Adjusting these thresholds can impact the model's prediction accuracy, especially near the decision boundaries between classes.

The optimization parameters of the GA are the cost weight Cij and threshold Ti in this study, as shown in Fig. 3. This figure illustrates the process of optimizing these parameters to enhance the prediction outcomes. The initial parameter values are selected randomly, and they can then be generated, crossed over, and mutated to produce new generations of parameters, allowing the population to evolve towards better solutions. The fitness value for each parameter combination in the current generation is computed, typically based on the objective function of the optimization problem. If the stopping criteria are met, i.e., the optimal fitness value is achieved, the iteration process terminates. Otherwise, the algorithm continues to generate new parameter populations.

For the model developed for the inner, middle, and outer lanes, the

aforementioned parameters of the genetic algorithm, such as the initial population size, maximum iteration count, crossover probability, and mutation rate, were set as follows: (1) 180, 450, 0.6, and 0.25; (2) 150, 450, 0.6, and 0.2; and (3) 120, 400, 0.6, and 0.18, respectively. The fitness function, as shown in Eq. (5), plays a crucial role in determining the optimal parameter values. The primary optimization objectives are to minimize prediction errors and maximize prediction performance.

$$F(\theta) = \sum{m=1}^{M} C{ij} \bullet L(y_i, \hat{y_i}(\theta, T_i))$$ (5)

$$0 < T_i < 1 \tag{6}$$

$$0 \le C_{ij} < 1 \tag{7}$$

$$C_{ij} = \begin{cases} k_1 \bullet (|i-j| + A(i,j)), & \text{if } j \ k_2 \bullet (|i-j| + B(i,j)), & \text{if } j \ 0, & \text{if } i = j \end{cases}$$ (8)

where M denotes the number of studied samples; Cij represents the cost of predicted Class j when the true class is i for the m-th sample; yi is the true label; *y*̂i(θ, Ti) is the predicted result based on the current model parameters θ and threshold Ti. The loss function *L yi, y*̂i(θ, Ti) measures the difference between the true label and the predicted one. 0 ≤ Cij < 1 ensures that each cost coefficient lies within the range of 0 and 1. This is because the cost coefficient reflects relative costs, typically represented in a normalized form, ensuring model operability and interpretability (Kukar and Kononenko, 1998). Additionally, all cost coefficients must be non-negative, as the cost of any prediction error cannot be negative (Crone et al., 2005). Finally, correct predictions incur no cost. *k*1 and k2 are constant parameters that represent the rate at which Cij increases as the difference between Classes i and j. For instance, predicting HR as MR should incur a lower cost than predicting high risk as NR, as the latter poses a higher safety risk. This arrangement reflects the severity of prediction errors. In other words, the cost of certain prediction errors should increase or decrease based on the difference in prediction levels (Zadrozny et al., 2003; Crone et al., 2005). A(i, j) and B(i, j) are functions that further adjust the cost based on the pair of classes being considered and ensure that Cij is greater when i > j than when i < j. In other words, they ensure that the cost coefficient for prediction errors related to safety should be higher than that for efficiency-related errors, highlighting that underestimating the risk level is more detrimental than

Table 3 Comparing the prediction results (MA-AUC and MA-F1-score) between the baseline and proposed models, with corresponding improvement rates (in brackets).

Testing set ratio Lane type Model type MA-AUC MA-F1-score Model type MA-AUC MA-F1-score
20 % Inner lane KNN 0.38 0.39 CSL-DTs-KNN 0.65 (73.72 %) 0.63 (59.90 %)
RF 0.47 0.51 CSL-DTs-RF 0.86 (81.97 %) 0.72 (42.22 %)
DT 0.40 0.43 CSL-DTs-DT 0.68 (71.21 %) 0.67 (57.76 %)
SVM 0.44 0.48 CSL-DTs-SVM 0.80 (83.60 %) 0.71 (48.28 %)
LSTM 0.46 0.50 CSL-DT-LSTM 0.86 (88.48 %) 0.77 (54.88 %)
XGBoost 0.44 0.49 CSL-DT-XGBoost 0.85 (95.13 %) 0.80 (63.76 %)
Middle lane KNN 0.45 0.46 CSL-DTs-KNN 0.79 (76.98 %) 0.74 (63.15 %)
RF 0.45 0.48 CSL-DTs-RF 0.81 (79.83 %) 0.73 (50.59 %)
DT 0.43 0.46 CSL-DTs-DT 0.77 (77.79 %) 0.73 (57.55 %)
SVM 0.39 0.42 CSL-DTs-SVM 0.71 (80.51 %) 0.63 (49.88 %)
LSTM 0.47 0.47 CSL-DT-LSTM 0.85 (81.04 %) 0.78 (67.47 %)
XGBoost 0.45 0.47 CSL-DT-XGBoost 0.83 (85.61 %) 0.76 (60.79 %)
Outer lane KNN 0.38 0.40 CSL-DTs-KNN 0.63 (66.24 %) 0.64 (59.53 %)
RF 0.46 0.51 CSL-DTs-RF 0.78 (70.76 %) 0.71 (39.02 %)
DT 0.44 0.48 CSL-DTs-DT 0.75 (72.40 %) 0.70 (43.69 %)
SVM 0.43 0.47 CSL-DTs-SVM 0.79 (82.80 %) 0.73 (56.19 %)
LSTM 0.46 0.51 CSL-DT-LSTM 0.82 (75.44 %) 0.72 (42.25 %)
XGBoost 0.45 0.46 CSL-DT-XGBoost 0.80 (76.47 %) 0.73 (59.33 %)
30% Inner lane KNN 0.42 0.42 CSL-DTs-KNN 0.66 (59.09%) 0.64 (50.60%)
RF 0.48 0.51 CSL-DTs-RF 0.84 (72.59%) 0.72 (41.56%)
DT 0.43 0.47 CSL-DTs-DT 0.71 (64.20%) 0.69 (45.16%)
SVM 0.46 0.48 CSL-DTs-SVM 0.76 (67.12%) 0.68 (40.25%)
LSTM 0.49 0.52 CSL-DT-LSTM 0.84 (72.23%) 0.74 (43.00%)
XGBoost 0.47 0.52 CSL-DT-XGBoost 0.82 (72.29%) 0.73 (40.12%)
Middle lane KNN 0.45 0.49 CSL-DTs-KNN 0.74 (64.65%) 0.70 (44.01%)
RF 0.47 0.51 CSL-DTs-RF 0.82 (74.86%) 0.71 (40.14%)
DT 0.45 0.49 CSL-DTs-DT 0.74 (65.62%) 0.70 (43.71%)
SVM 0.43 0.44 CSL-DTs-SVM 0.73 (68.51%) 0.64 (46.13%)
LSTM 0.48 0.49 CSL-DT-LSTM 0.84 (74.88%) 0.74 (51.65%)
XGBoost 0.47 0.48 CSL-DT-XGBoost 0.83 (77.25%) 0.76 (60.32%)
Outer lane KNN 0.43 0.43 CSL-DTs-KNN 0.69 (60.68%) 0.68 (56.30%)
RF 0.48 0.54 CSL-DTs-RF 0.83 (71.14%) 0.70 (29.70%)
DT 0.46 0.47 CSL-DTs-DT 0.81 (75.38%) 0.75 (60.57%)
SVM 0.46 0.51 CSL-DTs-SVM 0.77 (66.78%) 0.72 (41.03%)
LSTM 0.49 0.53 CSL-DT-LSTM 0.85 (73.83%) 0.76 (43.96%)
XGBoost 0.48 0.51 CSL-DT-XGBoost 0.82 (72.42%) 0.77 (50.39%)
40% Inner lane KNN 0.45 0.48 CSL-DTs-KNN 0.74 (63.26%) 0.73 (52.25%)
RF 0.49 0.52 CSL-DTs-RF 0.81 (64.76%) 0.69 (32.44%)
DT 0.46 0.47 CSL-DTs-DT 0.78 (68.87%) 0.74 (55.99%)
SVM 0.47 0.52 CSL-DTs-SVM 0.77 (62.99%) 0.72 (39.61%)
LSTM 0.50 0.51 CSL-DT-LSTM 0.85 (69.77%) 0.75 (46.32%)
XGBoost 0.48 0.52 CSL-DT-XGBoost 0.82 (68.64%) 0.76 (44.50%)
Middle lane KNN 0.46 0.47 CSL-DTs-KNN 0.72 (55.20%) 0.70 (49.90%)
RF 0.48 0.48 CSL-DTs-RF 0.76 (59.21%) 0.67 (39.48%)
DT 0.45 0.50 CSL-DTs-DT 0.75 (65.01%) 0.73 (46.20%)
SVM 0.45 0.46 CSL-DTs-SVM 0.76 (67.76%) 0.69 (48.60%)
LSTM 0.49 0.55 CSL-DT-LSTM 0.82 (66.42%) 0.76 (36.88%)
XGBoost 0.48 0.51 CSL-DT-XGBoost 0.79 (65.31%) 0.74 (46.19%)
Outer lane KNN 0.47 0.44 CSL-DTs-KNN 0.79 (67.78%) 0.71 (61.73%)
RF 0.50 0.50 CSL-DTs-RF 0.78 (56.52%) 0.70 (41.52%)
DT 0.48 0.49 CSL-DTs-DT 0.80 (65.49%) 0.75 (52.64%)
SVM 0.48 0.48 CSL-DTs-SVM 0.80 (66.61%) 0.73 (50.90%)
LSTM 0.50 0.52 CSL-DT-LSTM 0.81 (61.34%) 0.76 (45.79%)
XGBoost 0.49 0.53 CSL-DT-XGBoost 0.80 (62.76%) 0.77 (47.32%)

Note: The results shown in Table 3 are derived from the testing set; and the term "improvement rates" refers to the percentage increase in MA-AUC or MA-F1-score achieved by the proposed model compared to its corresponding baseline model. The same applies to the subsequent tables.

overestimating it. For example, the cost of predicting HR as LR (which may lead to safety hazards such as traffic accidents) should be higher than predicting LR as HR (which may reduce traffic efficiency but have a lesser impact on safety). The design of these functions can reflect domain-specific knowledge (Tang et al., 2021), emphasizing the priority of safety over efficiency.

4. Results of risk prediction

The dataset used as input for the employed prediction models was split into two subsets for training and testing, using three different ratios: 80 % for training and 20 % for testing (8:2), 70 % for training and 30 % for testing (7:3), and 60 % for training and 40 % for testing (6:4). The use of multiple ratios aims to evaluate the model's robustness. It is

important to note that although methods like k-fold cross validation can provide more comprehensive model evaluation, the benefit of incorporating k-fold cross validation is limited in this study due to the large sample size (shown in Table 2) (Kohavi, 1995). Furthermore, k-fold cross validation is considerably time-consuming (Chollet, 2021), which may not meet the computational efficiency requirements for real-time prediction. Therefore, this study only used multiple fixed ratios to assess the model's robustness.

To evaluate the impact of the proposed model on risk prediction, this study compared the performance of the proposed models and their corresponding baseline ones. The results are shown in Table 3 and Fig. 4. Specifically, Table 3 presents the MA-AUC and MA-F1-score values for both the baseline and proposed models. It is evident that the performance of the baseline models is poor, with the best-performing model

Fig. 4. Comparing the prediction results (precision) between the baseline and proposed models.

only achieving values around 0.5 for both MA-AUC and MA-F1-score, indicating that the model cannot effectively classify the data and performs nearly as randomly as guessing. This result is consistent with previous studies indicating poor performance of models in predicting multi-class variables (Dong, 2023). Moreover, regardless of the lane category or data partition ratio, the proposed model consistently outperforms its baseline model, with significant improvements in both MA-AUC and MA-F1-score. For MA-AUC, the improvement rate exceeds 55 % in all cases, with the maximum improvement reaching 84 %. However, for MA-F1-score, the average improvement is about 50 %, with the maximum improvement at 61.73 %, indicating slightly less improvement compared to MA-AUC. This suggests that while the proposed model enhances the ability to distinguish between different categories, there are still some shortcomings in category identification. Furthermore, the high improvement rates for both MA-AUC and MA-F1-score indicate that the proposed model can accurately identify potential accident hotspots, enabling targeted interventions such as dynamic speed adjustment, enhanced signage, or real-time driver alerts (Borsati et al.,

2019). Additionally, the performance of CSL-DTs-RF, CSL-DTs-LSTM, and CSL-DTs- XGBoost consistently outperforms other models (i.e., achieving the best MA-AUC or MA-F1-score values), ranking in the top three. These models are ideal for safety–critical applications, such as predicting the likelihood and severity of collisions under various traffic conditions, thus aiding in resource allocation and providing decisionmaking support for improving road safety. However, the bestperforming model for different lanes tends to vary. Therefore, while these models show great potential, their application must consider lanespecific variations and require continuous recalibration as traffic patterns evolve, which is consistent with previous research findings (Hu et al., 2022).

Fig. 4 illustrates the prediction precision for each class (i.e., NR, LR, MR, and HR) under different scenarios. Again, CSL-DTs-based models (i. e., CSL-DTs-KNN, CSL-DTs-RF, CSL-DTs-DT, CSL-DTs-SVM, CSL-DT-LSTM, and CSL-DT-XGBoost) generally outperform their corresponding baseline models. It is also evident that the precision values for CSL-DTs-based models decrease across classes in the order of NR, LR, MR,

Fig. 4. (continued).

and HR. This suggests that the model's prediction performance varies across different categories. Although the introduction of dynamic thresholds may improve this difference, it still persists. This could be attributed to factors such as model complexity, feature importance, generalization capability, the limitations of dynamic thresholds, data quality, and the applicability of the model architecture (Jiang et al., 2019; Hu et al., 2021; Patil et al., 2024). In the context of freeway traffic safety, these findings hold considerable implications for the development of more refined traffic management. The model's ability to predict NR and LR categories with higher precision can enhance proactive safety measures, such as deploying traffic monitoring resources in areas with lower risk (Macedo et al., 2021). For HR scenarios, however, where the model's performance is comparatively lower, targeted interventions such as advanced driver assistance systems (ADAS) or automated braking systems could be crucial in minimizing collision risks (Kang et al., 2022). However, it is also worth emphasizing that CSL-DTs-based models consistently outperform their corresponding baseline models in

terms of prediction precision across all classes (i.e., NR, LR, MR, and HR). Therefore, the models proposed in this study are effective in improving multi-class prediction performance.

These results clearly demonstrate that that combining cost-sensitive learning with dynamic thresholds significantly improves prediction performance when predicting multi-class traffic conditions. Additionally, based on the results in Table 3 and Fig. 4, and by comparing with previous traffic risk prediction studies, the overall prediction performance of the proposed model is evidently satisfactory (Hu et al., 2022; Yuan et al., 2022; Wu et al., 2024a,b,c,d).

To further enhance the model's interpretability analysis, we employed Permutation Importance to output feature importance. Specifically, by permuting each feature and calculating the associated performance loss, we ranked the results based on feature importance and presented them in a bar chart, as shown in Fig. 5. Notably, from the results in Table 3, it can be seen that CSL-DT-based models, such as CSL-DT-LSTM, CSL-DT-XGBoost, and CSL-DT-RF, generally perform better,

Fig. 5. Feature importance obtained from the best performing model.

showing the best MA-AUC or MA-F1-score values. However, for this part of the analysis, only one model's feature importance was selected for each scenario (specific lane type and data split ratio). The model chosen corresponds to the best average MA-AUC and MA-F1-score. The bestperforming models are as follows: (1) Testing set ratio = 20 %, inner lane: CSL-DT-XGBoost; (2) Testing set ratio = 20 %, middle lane: CSL-DT-LSTM; (3) Testing set ratio = 20 %, outer lane: CSL-DT-LSTM; (4) Testing set ratio = 30 %, inner lane: CSL-DT-LSTM; (5) Testing set ratio = 30 %, middle lane: CSL-DT-XGBoost; (6) Testing set ratio = 30 %, outer lane: CSL-DT-LSTM; (7) Testing set ratio = 40 %, inner lane: CSL-DT-LSTM; (8) Testing set ratio = 40 %, middle lane: CSL-DT-LSTM; and (9) Testing set ratio = 40 %, outer lane: CSL-DT-XGBoost.

Based on the feature importance results shown in Fig. 5, several key insights can be derived. For the inner lane, UAS (Average speed of vehicles identified upstream) and DAS (Average speed of vehicles identified downstream) are the most influential features. Since vehicles on the inner lane tend to travel at higher speeds, speed fluctuations in high-speed environments are central to the model's ability to predict potential safety risks. For the middle lane, the model emphasizes the roles of UD (Vehicle density identified upstream). The middle lane, as a "transition lane" on freeways, sees frequent car-following and lanechanging behaviors. UD directly reflects traffic density, where highdensity conditions lead to shorter distances between vehicles, and small disturbances propagate through the flow, increasing the risk of rear-end collisions. For the outer lane, DF (Number of vehicles identified downstream) and DD (Vehicle density identified downstream) are identified as crucial features. Since vehicles in the outer lane typically travel at lower speeds (e.g., trucks, cautious drivers), DF and DD directly

Table 4 Time consumption of the proposed models.

| Model | 20 % | | | 30 % | | | 40 % | | | | |-----------------|------------|-------------|------------|------------|-------------|------------|------------|-------------|------------|--| | | Inner lane | Middle lane | Outer lane | Inner lane | Middle lane | Outer lane | Inner lane | Middle lane | Outer lane | | | CSL-DTs-KNN | 2.63 | 2.80 | 2.57 | 2.49 | 2.85 | 2.36 | 2.45 | 3.00 | 2.37 | | | CSL-DTs-RF | 3.02 | 3.08 | 2.94 | 2.88 | 3.04 | 2.62 | 2.75 | 3.11 | 2.53 | | | CSL-DTs-DT | 2.88 | 2.92 | 2.86 | 2.72 | 2.90 | 2.52 | 2.70 | 3.08 | 2.48 | | | CSL-DTs-SVM | 3.14 | 3.28 | 3.03 | 3.08 | 3.18 | 2.92 | 2.88 | 3.16 | 2.74 | | | CSL-DTs-LSTM | 3.50 | 3.63 | 3.42 | 3.35 | 3.59 | 3.13 | 3.24 | 3.71 | 3.04 | | | CSL-DTs-XGBoost | 3.44 | 3.57 | 3.37 | 3.30 | 3.53 | 3.08 | 3.18 | 3.65 | 2.99 | |

Note: The time unit in the Table 4 is "×102 s".

Fig. 6. Convergence curve of the model optimization process.

reflect the passing capacity of the road ahead. If the downstream flow is dense, vehicles in the outer lane must frequently adjust their speed, which can propagate disruptions upstream, making the outer lane more susceptible to such disturbances due to its lower speed.

These findings have significant implications for traffic safety

practitioners. Identifying key features influencing model predictions can help design more effective traffic monitoring systems. For instance, since fluctuations in upstream and downstream speeds are considered primary risk factors, focusing on speed monitoring can improve safety for inner lanes. Similarly, for middle and outer lanes, systems capable of

Fig. 6. (continued).

assessing traffic density and vehicle count over time are crucial for predicting and preventing congestion-related accidents. Specifically, for the middle lane, density monitoring systems (e.g., millimeter-wave radar) should be enhanced to provide real-time warnings of traffic compression risks. For the outer lane, vehicle detectors (e.g., inductive loops) should be prioritized in downstream sections to dynamically sense congestion propagation trends.

The aforementioned results demonstrate that the proposed models significantly improve the prediction performance (i.e., MA-AUC, MA-F1 score and precision) for multi-class traffic conditions. However, the integration of cost-sensitive learning and dynamic thresholds into the prediction models inevitably leads to a higher computational cost compared to the baseline models. Given that the primary goal of this study is to enhance real-time risk prediction, therefore, the runtime of the proposed model should be further analyzed. The specific results are presented in Table 4. From these results, it can be observed that the longest runtime is 3*.71 × 102 seconds, with an average time of 3.*01 × 102 seconds. Considering the sample size mentioned in Section 3.1, the average processing time per sample is less than 0.05 s. It is important to note that these time values reflect the total time from input to output, providing a comprehensive measure of overall efficiency. However, they do not include the time spent on data preprocessing and feature extraction, which are typically performed offline in real-time prediction scenarios (Liu et al., 2020). Additionally, the relatively short processing times mentioned above ensure that the model can be quickly deployed to real-time scenarios after training. Therefore, in the

context of real-time traffic risk prediction, the computational time in the research framework — incorporating cost-sensitive learning, dynamic thresholds, and optimization algorithms — is generally acceptable (Zhang et al., 2024a,b).

It should be noted that the proposed models (i.e., CSL-DTs-KNN, CSL-DTs-RF, CSL-DTs-DT, and CSL-DTs-SVM) may not necessarily represent the best performing models in terms of prediction MA-AUC/MA-F1 score/precision. Other models, such as certain deep learning approaches, might yield better results. However, for real-time prediction, the time required for prediction is also a critical factor. In other words, models with higher MA-AUC/MA-F1-score/precision may also involve longer computation times (Loumiotis et al., 2014). Therefore, the optimal real-time risk prediction model is essentially a trade-off between prediction MA-AUC/MA-F1-score/precision and processing time. Accordingly, the models proposed in this study are considered suitable for practical application in real-time risk prediction, given their favorable performance in both prediction MA-AUC/MA-F1-score/precision and processing time.

Furthermore, in order to ensure the reliability of the optimized results (e.g., avoiding local optima), convergence curves corresponding to the optimization process were plotted, as shown in Fig. 6. It can be observed that the curve decreases rapidly in the initial phase and gradually flattens out, indicating a fast convergence rate (Patil et al., 2024). Additionally, as the process approaches convergence, the fluctuations in the fitness value are minimal, indicating high stability. This typically suggests that the convergence of the algorithm is reliable, and

Table 5 Robustness analysis of model performance under perturbations.

±2%
− 0.001
1
Cost
0.859
coefficient
− 0.12
0.001
%
±4% 0.001
0.858 − 0.23
− 0.002 %
±6%
− 0.005
0.855
− 0.58
0.002
Threshold
±2%
0.857
− 0.003
%
0.001
− 0.35
±4% %
− 0.004 − 0.47
0.856 0.002
±6% %
− 0.007 − 0.81
0.853 0.003
±2%
− 0.001
Combined
0.859
%
− 0.12
0.001
(Cost +
±4%
− 0.003
Threshold)
0.857
%
− 0.35
0.003
±6% %
0.851 0.005
− 0.009 − 1.05
±2%
− 0.001
2
Cost
0.849
%
− 0.12
0.001
coefficient %
±4% 0.001
0.848 − 0.24
− 0.002 %
±6% − 0.47
− 0.004 0.002
0.846 %
±2%
− 0.003
Threshold
0.847
− 0.35
0.001
%
±4% 0.002
0.845 − 0.59
− 0.005 %
±6% − 0.94
− 0.008 0.003
0.842 %
Combined
±2%
0.849
− 0.001
(Cost +
0.001
− 0.12
%
±4%
− 0.004
Threshold)
0.846
− 0.47
0.003
%
±6% − 1.18
− 0.010 0.006
0.840 %
±2%
− 0.001
3
Cost
0.819
coefficient
− 0.12
0.001
%
±4% − 0.24
− 0.002 0.002
0.818 %
±6% 0.003
0.816 − 0.49
− 0.004 %
±2%
− 0.002
Threshold
0.818
− 0.24
0.001
%
±4% 0.002
0.816 − 0.49
− 0.004 %
±6% − 0.85
− 0.007 0.004
0.813 %
±2%
− 0.001
Combined
0.819
(Cost +
− 0.12
0.001
%
Threshold)
±4%
0.816
− 0.004
0.003
− 0.49
%
±6% − 1.22
− 0.010 0.006
0.810 %

Note: Models 1, 2, and 3 correspond to the optimal MA-AUC values for the inner, middle, and outer lanes, respectively, when the testing set ratio is 20 %, as presented in Table 3. The MA-AUC in Table 5 represents the average values obtained from repeated trials. Δ (Absolute change): MA-AUC difference between perturbed and baseline values; SD (Standard deviation): Variation across repeated trials; %Δ (Relative change): (Δ / Baseline MA-AUC) × 100 %.

the final solution is relatively optimal (Nocedal and Wright, 2006). In addition, among all the predicted cases, the model that converges the fastest is CSL-DTs-KNN, which indicates that this model is able to quickly identify the optimal or near-optimal solution during the optimization process. This is likely because KNN is highly sensitive to local data characteristics (Cover and Hart, 1967). When combined with costsensitive learning and dynamic thresholds strategies, the model can more effectively adjust and optimize its predictions during training, thereby achieving faster convergence. Additionally, the fitness values generated by the CSL-DTs-RF, CSL-DTs-LSTM, and CSL-DTs-XGBoost

models are generally smaller, which correlates with the best prediction performance. This can be attributed to the models' ability to effectively balance the trade-off between model complexity and overfitting, ensuring that they generalize well on unseen data while maintaining high accuracy (Rigatti, 2017). Furthermore, with the assistance of cost-sensitive learning and dynamic threshold adjustments, the model can more precisely optimize its predictions for different data distributions. However, there are certain limitations to consider. The effectiveness of these models may be compromised in scenarios involving highly unpredictable or extreme events, such as sudden weather changes, or infrastructure failures. Besides, the computational demand for real-time optimization, particularly in large-scale freeway systems, might pose challenges in terms of resource allocation and system scalability (Zhao et al., 2024).

To further enhance the discussion on the sensitivity of the cost coefficients and thresholds optimized by GA, perturbations were introduced to the models corresponding to the best MA-AUC values for the inner, middle, and outer lanes in Table 3, when the testing set ratio is 20 %. Specifically, for the cost matrix Cij, the perturbed values are Cij = Cij × [(1 + U( − δ, +δ)], where δ ∈ {2%, 4%, 6%}. For the dynamic thresholds Ti, the perturbed values are Ti = Ti × [(1 + U( − φ, +φ)], where φ ∈ {2%*,4%,*6%}. Performance changes (measured by MA-AUC) were then observed under single-parameter perturbations (including cost coefficient perturbation and threshold perturbation separately) and combined perturbations, with the results presented in Table 5.

As shown in the Table 5, under single-parameter perturbations, the percentage change in MA-AUC for all models is ≤ 1 % at all levels of perturbation, with a maximum standard deviation of 0.004, indicating very low parameter sensitivity. In the case of combined perturbations, the maximum MA-AUC decrease is only 1.22 %, demonstrating the model's strong robustness to parameter interactions. Additionally, the sensitivity to threshold perturbation is slightly higher than to cost coefficient perturbation, as the changes in both Δ and %Δ for thresholds are slightly larger.

5. Conclusions

This study presents a novel approach for real-time traffic risk prediction, leveraging vehicle trajectory data from the HighD dataset to simultaneously extract traffic state and risk information. The key contribution of this research lies in the integration of cost-sensitive learning and dynamic thresholds with machine/deep learning models to enhance traffic risk prediction. Specifically, the study refines traffic risk classification into four levels (i.e., NR, LR, MR, and HR), incorporating misclassification costs through a cost-sensitive learning framework. The introduction of dynamic thresholds further addresses challenges of performance degradation commonly associated with increased risk granularity and class imbalance in multi-class prediction tasks. This novel combination alleviates the issue of poor prediction performance, which has been a longstanding challenge in previous studies (Wang et al., 2013; Sun et al., 2021). Furthermore, it provides a more accurate and practical approach for predicting traffic risks, with particular emphasis on rear-end collisions. Additionally, the optimization of both cost coefficients and thresholds using GA ensures a reliable prediction process. The impact of this research is substantial, as the proposed CSL-DTs-based models demonstrate superior performance in traffic risk prediction, particularly in terms of metrics such as MA-AUC, MA-F1-score and precision, compared to the baseline models. Furthermore, the computational demands of these models are deemed appropriate for real-time applications, making them a viable option for enhancing traffic safety prediction systems in practice. The comprehensive convergence curve analysis confirms the robustness of the GA optimization process, ensuring the reliability and effectiveness of the proposed approach. Additionally, the robustness analysis demonstrates that the prediction models remain highly stable under minor variations

in cost coefficients and thresholds, with minimal performance impact.

Despite the achievement of promising results, there are several limitations that should be noted. Firstly, this study specifically focuses on the risk of rear-end collisions, while other types of conflicts, such as side-swipe accidents, warrant investigation in future research. Additionally, the inclusion of other safety evaluation indexes would help provide a more comprehensive assessment of traffic safety. Furthermore, the HighD dataset used in this study has several limitations. It is confined to freeway traffic in Germany, which thus restricts the model's applicability to urban environments. Additionally, it lacks data on adverse weather conditions and does not account for diverse driving behaviors, such as aggressive lane-changing common in areas like Southeast Asia, potentially introducing bias in safety evaluations. Given these constraints, the optimal parameters of the proposed prediction model should be re-estimated for different research contexts and datasets. Herein, researchers shall focus on the proposed research approach and framework in the first instance. Finally, the practical application of this framework in automated traffic safety decision-making, especially in risk prediction, may raise legal and ethical concerns. However, these challenges are manageable through responsible deployment and adherence to regulatory frameworks.

CRediT authorship contribution statement

Dan Wu: Writing – review & editing, Writing – original draft,

Software, Methodology, Investigation, Funding acquisition, Formal analysis, Conceptualization. Lu Xing: Supervision, Data curation, Conceptualization. Ye Li: Supervision, Methodology, Conceptualization. Yiik Diew Wong: Writing – review & editing, Methodology, Conceptualization. Jaeyoung Jay Lee: Writing – review & editing, Conceptualization. Changyin Dong: Conceptualization.

Declaration of competing interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Acknowledgments

This research was sponsored by the National Natural Science Foundation of China (No. 52472371), the Natural Science Foundation of Hunan Province (No. 2024JJ5030), the Science and Technology Innovation Program of Hunan Province (No. 2023RC3143, 2024RC3014), the National Natural Science Foundation of China (No. 72471249), the Natural Science Foundation of Changsha (No. kq2402221), and the Postgraduate Research and Innovation Project of Central South University (No. 2023ZZTS0343). The authors would also like to express sincere gratitude to the creators of the HighD dataset for providing the valuable data.

Appendix A:. Proposed prediction model

A.1 CSL-DTs-KNN

The KNN algorithm is an instance-based learning method and a distance-based classification technique. The core idea is to predict the class of a new test sample by calculating its distance to all training samples, selecting the k nearest neighbors, and determining the most frequent class among them. The distance between a test sample and a training sample can be computed using a given formula:

$$d(x_i, xj) = \sum{m=1}^{n} (x{im} - x{jm})^2$$ (A1)

where xi and xj are two samples in the training set, and n represents the dimensionality of the samples.

Once the distances are calculated, the k nearest neighbors are selected based on their proximity. For each sample, the majority voting rule is applied to the labels of these k neighbors to determine the predicted class. In multi-class problems, a simple majority voting approach is commonly used (Hernandez-Gonzalez et al., 2018; Aeeneh et al., 2024), as shown in Eq. (A.2):

$$y_{pred} = majorityvote(y_1, y_2, \dots, y_k)$$ (A2)

where *y1, y2,* ⋯, yk are the class labels of the selected k neighbors.

Next, the concept of cost-sensitive learning is introduced. For each Class i, the weighted loss of prediction errors across all neighbors is computed. Let the neighbors' labels be *y1, y2,⋯, yk*. The total loss function can be represented as:

$$L(y{pred}) = \sum{i=1}^{k} C(yi, y{pred})$$ (A3)

where C ( yi, ypred) denotes the loss between the predicted class and the true one of Class i. The final class prediction is the one that minimizes this total loss, as shown in Eq. (A.4).

$$y_{pred} = \arg \frac{min}{yi} \sum{i=1}^{k} C(y_i, y_i)$$ (A4)

The model computes a score for each class, denoted as *S*0, *S*1, *S*2 and *S*3, with corresponding dynamic thresholds *T*0, *T*1, *T*2 and *T*3. The classification rule can then be modified to incorporate these dynamic thresholds, as follows:

$$y_{pred} = \arg \frac{max}{i} (S_i, ifS_i \ge T_i else reject the prediction)$$ (A5)

The decision rule is adjusted to account for both prediction costs and dynamic thresholds. Specifically, the prediction loss is calculated with the following equation:

$$L(y{pred}) = \sum{i=1}^{k} C(yi, y{pred}) + \partial \bullet (S{pred} < T{pred})$$ (A6)

where ( Spred &lt; Tpred) is an indicator function that penalizes the model when the predicted score is below the dynamic threshold. The final prediction is made by choosing the class with the minimum total loss:

$$y{pred} = \arg \min{j} \left( \sum_{i=1}^{k} C(y_i, y_j) + \partial \bullet (S_j < T_j) \right)$$ (A7)

A.2 CSL-DTs-RF

RF is an ensemble learning method that constructs multiple decision trees and aggregates the predictions from all trees through voting or averaging to obtain the final prediction. For a given input feature x, the traditional RF model outputs the prediction probabilities for four categories: *P*0(x)*, P*1(x)*, P*2(x)*,P*3(x). The final predicted outcome ypred is the category with the highest predicted probability:

$$y_{pred} = \operatorname{argmax}(P_0(x), P_1(x), P_2(x), P_3(x)) \tag{A8}$$

To make the RF model more focused on avoiding high-cost errors, it is necessary to consider the different costs associated with each type of prediction error during the training process. For a dataset D = (xi, yi), the objective is to minimize the following weighted loss function:

$$L = \sum{i=1}^{N} C{y_i,\hat{y}_i} \bullet \beth(y_i \neq \hat{y}_i)$$ (A9)

where yi and ̂yi represent the true and predicted classes, respectively; and ℶ yi ∕= ̂yi is an indicator function that takes the value 1 if the prediction is incorrect, and 0 otherwise.

Next, we introduce a dynamic threshold Ti to replace the traditional approach of selecting the class with the highest predicted probability. This leads to the construction of a composite loss function. Given that the model provides a set of prediction probabilities Pi(xi) for each data point xi, we can define the composite loss function as:

$$L{total} = \sum{i=1}^{N} C_{y_i \hat{y}i} \bullet \beth \left( P{\hat{y}_i}(xi) \geq T{\hat{y}_i} \right)$$ 10)

where ̂yi is the predicted class chosen based on the dynamic threshold Tˆyi . By jointly optimizing both the loss function and the dynamic thresholding process, the model can minimize high-cost errors while dynamically adjusting the threshold to improve overall prediction performance.

A.3 CSL-DTs-DT

DT is a supervised learning algorithm designed to select splitting features by minimizing the error of the decision tree. In this study, information gain is used as the splitting criterion. Given a training dataset containing N samples, where each sample consists of a feature vector Xi = (*xi1, xi2,* ⋯ , xim) and a corresponding label yi ∈ {0*,1,2,*3}, the information gain G for feature Xi is calculated as follows:

$$G(Xi) = H(D) - \sum{v \in V(X_i)} \frac{|D_v|}{|D|} H(D_v)$$

$$11)$$

where H(D) is the entropy of the dataset D, and H(Dv) is the entropy of the subset Dv corresponding to the value v of feature Xi. Next, we consider the cost of different types of prediction errors while minimizing classification errors, as expressed by the following formula:

$$L = \frac{1}{N} \sum{i=1}^{N} C{y_i \hat{y}_i} \bullet \Im(y_i \neq \hat{y}_i)$$ 12)

Let P(y = i|X) represent the predicted probability that sample X belongs to Class i. For each Class i, we define a threshold Ti. For each sample X, the predicted class is determined based on the following rule:

$$\widehat{y} = \arg \max_{i \in {0, 1, 2, 3}} [P(y = i|X) - T_i]$$ 13)

If the difference P(y = i|X)− Ti is maximal for Class i, then the predicted class is i.

A.4 CSL-DTs-SVM

SVM is a powerful classification model that can classify different classes of sample data by constructing an optimal hyperplane. For Class i ∈ {0*,1,2,* 3}, a decision function fi(x) can be constructed to distinguish class i from the other classes:

$$f_i(x) = w_i^T x + b_i \tag{14}$$

where wT i x denotes the projection of the weight vector wi on the input data x, and bi is the bias term associated with Class i. The final predicted class is determined by:

$$\widehat{y}_i = \arg \frac{max}{i} f_i(x)$$ 15)

In the standard optimization problem of an SVM, the objective is to minimize classification error. Typically, the objective function is:

$$L = \min{\mathbf{w}, b} \frac{1}{2} ||\mathbf{w}||^2 + \gamma \sum{i=1}^{N} \varepsilon_i$$ 16)

where εij are slack variables that allow some classification errors, and γ is the regularization parameter that controls the trade-off between margin size and classification error.

When considering cost-sensitive learning, the objective function is modified by adding a weight term to account for the cost of different errors:

$$L = \min{\mathbf{w}, \mathbf{b}} \frac{1}{2} ||\mathbf{w}||^2 + \gamma \sum{i=1}^{N} C{ij} \varepsilon{ij}$$ 17)

where εij is the slack variable representing the error when the i-th class is misclassified into Class j, and Cij is the cost of misclassifying Class i into j. Subsequently, by combining the advantages of cost-sensitive learning and dynamic thresholding, the objective function is further adjusted as shown in the following:

$$L = \min{\boldsymbol{w}, \, b, \, T} \frac{1}{2} ||\boldsymbol{w}||^2 + \gamma \sum{i,j=1}^{N} C{ij} \varepsilon{ij} + \beta \sum_{i=1}^{N} |T_i - \widehat{T}_i|$$ 18)

where *T*̂*i*is the optimal threshold for Class i, and β is the regularization parameter that controls the dynamic threshold adjustment. For each sample x, the decision function for all classes is first computed. Then, the final classification decision is made based on the adjusted dynamic threshold Ti:

$$\widehat{\mathbf{y}} = \arg \frac{max}{i} (f_i(\mathbf{x}) - T_i)$$ 19)

Data availability

Data will be made available on request.

References