## 5 Traffic Hazard Prediction Model  
In this chapter, we present a conceptual predictive model based on machine learning, which may be used in the future to predict road safety risks based on data from a network of speed sensors. This model has not been implemented in the current study, which relies on simulations conducted using the SUMO v. 1.23.1 for Windows software (described in Section 6). The purpose of this chapter is to identify the types of data needed to develop such a model and to outline its potential structure. Creating a predictive mathematical model that predicts traffic safety risks, specifically identifying locations where the most frequent or severe speeding violations occur, requires an approach based on machine learning. This conceptual model can be built using supervised learning techniques, such as classifiers or regressors. The goal is to predict the level of danger over time, defined as a numerical value or a class of danger for a given location. Its purpose is to outline the types of data needed and the potential structure for future development, rather than serving as an operational model in this research. The model begins by defining the output variable, y(t,s), which represents the level of risk of speeding or serious traffic danger at point s at time t. This variable is conceptualized as a categorical output with three levels, expressed as \(\mathrm{y(t,s)}=\left\{ \begin{array}{cl}0,&\mathrm{no~{}risk}\\ 1,&\mathrm{moderate~{}risk}\\ 2,&\mathrm{high~{}risk}\end{array} \right.\), providing a framework for classifying traffic hazards based on severity. This classification is crucial for informing preventive measures and is influenced by input variables such as vehicle speed and environmental conditions. A typical initial approach to modeling this risk involves probabilistic methods, such as logistic regression. The basic logistic regression model for these three risk classes is formulated as \(\mathrm{P(y=k~{}|~{}X)}=\frac{\beta^{\mathrm{B_{k}}+\Sigma_{k-1}^{+}\beta_{0}x _{1}^{\mathrm{s}}}}{\sum_{k-0}^{\mathrm{K-1}}\beta_{0}x_{1}^{\mathrm{s}}- \beta_{1}y_{1}^{\mathrm{s}}}\), where \(\mathrm{P(y=k~{}|~{}X)}\) denotes the probability of risk level k given the input features X, \(\beta_{0}\) is the intercept, and \(\beta_{i}\) are the regression coefficients associated with the input variables \(X_{i}\) for class k. This equation allows the model to weigh factors like speed and weather to estimate risk probabilities, though it remains a theoretical construct for future implementation. To handle the spatial-temporal nature of traffic data more effectively, we propose incorporating a Long Short-Term Memory (LSTM) neural network, which is well-suited for sequential data analysis. The spatial-temporal input is defined as \(\mathrm{X(t,s)}=\left\{\mathrm{v(t,s),t,w(t,s),r(s),d_{sc}(s),d_{sh}(s),h(s)}\right\}\), a vector that combines the velocity \(\mathrm{v(t,s)}\) measured at point s at time t in km/h, the measurement time t (hour of the day and day of the week), weather conditions \(\mathrm{w(t,s)}\) (e.g., temperature, precipitation, fog, and visibility), road type r(s) (e.g., highway, national road, local road, and speed limit zone), distance from the nearest school \(\mathrm{d_{sc}(s)}\), distance from the nearest store or point of interest \(\mathrm{d_{sh}(s)}\), and history of traffic incidents at a given location h(s). These variables, critical for capturing the complexity of traffic risks, are processed by the LSTM through a series of gates and states. The LSTM operates by managing information flow with specific gates. The forget gate, \(\mathrm{f_{t}}=\sigma(W_{t}\cdot\left[\mathrm{h_{t-1},X(t,s)}\right]+\mathrm{ b_{f}})\), determines which information to discard from the previous hidden state \(\mathrm{h_{t-1}}\), where \(\sigma\) is the sigmoid activation function, \(W_{t}\) is the weight matrix, and bf is the bias. This gate helps the model forget irrelevant past data, such as outdated weather conditions.