A real-time prediction method for highway tunnel traffic incidents based on multi-model fusion

Through multi-model fusion and data preprocessing technology, a stacking model is constructed to improve the prediction accuracy and reliability of highway tunnel traffic events, solving the problems of insufficient data feature capture and insufficient model fusion in existing technologies, and realizing real-time prediction and flexible response to traffic events.

CN119580481BActive Publication Date: 2025-09-26广东交科检测有限公司 +2
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411553241.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-11-01
Publication Date
2025-09-26
Estimated Expiration
2044-11-01

AI Technical Summary

Technical Problem

Existing traffic incident prediction methods are unable to fully capture the complex traffic data characteristics in highway tunnels, resulting in insufficient prediction accuracy and reliability. They also fail to effectively integrate the strengths of various models and are unable to fully utilize the advantages of integrated models, especially in the case of data imbalance, where they are not sensitive enough to minority events.

Method used

A multi-model fusion method is adopted to build a stacked model through a stacked ensemble learning strategy. The prediction probabilities of multiple models are used as feature inputs, and logistic regression is used as the final classifier. Combined with data preprocessing and balancing techniques such as SMOTE and random downsampling, the temporal dependency of time series data is processed to improve prediction accuracy and robustness.

Benefits of technology

It improves the accuracy and reliability of real-time predictions of highway tunnel traffic events, can quickly process and analyze traffic data, provide timely warnings and response measures for tunnel management, adapt to different traffic prediction tasks, and enhance the flexibility and adaptability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119580481B_ABST
    Figure CN119580481B_ABST
Patent Text Reader

Abstract

The present invention provides a real-time prediction method for highway tunnel traffic events based on multi-model fusion, comprising: S1: collecting traffic data from multiple data sources and performing data preprocessing on the data, then dividing the processed data into a training set, a validation set, and a test set according to a specific ratio, and normalizing the training set and test set data; S2: designing and training M models using the processed data; and S3: constructing a stacked model using a stacked ensemble learning strategy for the M models obtained in S2, inputting the prediction probabilities of each model as feature inputs into the stacked model for prediction to obtain the final prediction result. This method solves the problems of the existing technology's difficulty in fully capturing the complex characteristics of traffic data, resulting in insufficient prediction accuracy and reliability, as well as the failure to effectively integrate the strengths of various models, which in turn prevents the full utilization of the advantages of the integrated model and results in uneven prediction results.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of traffic management, and more specifically, to a real-time prediction method for highway tunnel traffic events based on multi-model fusion. Background Art

[0002] In the field of traffic management, traffic incidents in highway tunnels, due to their unique, enclosed environments, often carry high safety risks. Therefore, accurately and real-timely predicting potential traffic incidents within tunnels is crucial for improving tunnel safety management. However, existing traffic incident prediction methods are mostly based on single models or simple statistical analysis, which struggle to fully capture the complex characteristics of traffic data, resulting in insufficient prediction accuracy and reliability. Traditional machine learning models, such as decision trees and support vector machines, can handle structured traffic data to a certain extent. However, due to the complexity of factors such as tunnel traffic flow, speed, and the proportion of large vehicles, these models have varying prediction performance for high-dimensional and highly variable data. Furthermore, existing methods commonly suffer from data imbalance. In traffic incident prediction, accident data is far less common than normal data, leading to a bias toward the majority class during model training, reducing sensitivity to minority class events. To address these issues, deep learning models, such as long short-term memory networks (LSTMs) and gated recurrent units (GRUs), have been introduced in recent years to address the long-term dependencies of time series data. However, single models still have limitations, such as overfitting to specific scenarios or a strong dependence on specific features, resulting in insufficient robustness and generalizability of predictions. While some research has begun exploring multi-model fusion and improving prediction accuracy through ensemble learning, these approaches often rely solely on simple model combinations, failing to effectively integrate the strengths of various models and fully exploit the advantages of ensemble models. This leaves significant room for improvement when dealing with complex traffic conditions. Therefore, existing technologies urgently need a more comprehensive and intelligent multi-model fusion approach that can effectively address data imbalance and enhance real-time prediction capabilities for highway tunnel traffic events. Summary of the Invention

[0003] The present invention aims to overcome at least one defect (shortcoming) of the above-mentioned prior art and provide a real-time prediction method for highway tunnel traffic events based on multi-model fusion, which is used to solve the problems that the prior art is unable to fully capture the complex traffic data characteristics, resulting in insufficient prediction accuracy and reliability, as well as the failure to effectively integrate the strengths of various models, unable to fully utilize the advantages of the integrated model, and uneven prediction effects.

[0004] The technical solution adopted by the present invention is a real-time prediction method for highway tunnel traffic events based on multi-model fusion, the method comprising:

[0005] S1: Collect traffic data from various data sources and perform data preprocessing. Then, divide the processed data into training, validation, and test sets according to specific ratios, and normalize the training and test data.

[0006] S2: Use the processed data to design and train M models;

[0007] S3: The M models obtained in S2 are constructed into a stacked model using a stacking ensemble learning strategy. The prediction probability of each model is used as a feature input and input into the stacked model to obtain the final prediction result.

[0008] In this application, multiple models are integrated to capture different features and patterns in traffic data, thereby improving the accuracy and reliability of predictions. A time series model is then set within the integrated multiple models to effectively process and capture the temporal dependencies in time series data, providing a more accurate prediction capability for the occurrence of traffic events. Using the prediction probabilities of multiple models as feature inputs, a stacked model is constructed for final prediction. This allows for comprehensive consideration of the outputs of different models, reducing the potential errors of a single model and improving overall robustness. Furthermore, the method can quickly process and analyze traffic data, predict potential traffic events in real time, and provide timely warnings and response measures for tunnel management. Furthermore, this method is highly flexible and can adjust and expand the model based on different data sources and requirements to accommodate different traffic prediction tasks.

[0009] Preferably, in step S3, constructing a stacking model using a stacking ensemble learning strategy includes:

[0010] S31: Use the get_probabilities function to predict each model trained in S2 to obtain the predicted probability of each category;

[0011] S32: Concatenate the predicted probabilities of all models into a new feature matrix;

[0012] S33: Use logistic regression as the final classifier of the stack to train the feature matrix to obtain a stack model, wherein the formula of the logistic regression is:

[0013]

[0014] Where P(y=k|x) represents the probability that the target variable y is equal to category k given the input feature X; X represents the input feature, that is, the row of the feature matrix; and b k Represents the weight and bias term of category k; K represents the number of categories; j represents the sample; and b jRepresents the weight and bias term of sample j.

[0015] In this application, by stacking the outputs of multiple models and using a logistic regression classifier for ensemble learning, the outputs of different models can be comprehensively considered, the errors that may be caused by a single model can be reduced, and the overall robustness can be improved.

[0016] Preferably, the step S32 specifically includes:

[0017] S321: Construct the prediction probability matrix P of model i i , in M ​​models, the prediction probability matrix P output by each model i is an N×K matrix, where N is the number of samples and K is the number of categories; the prediction probability matrix P i for:

[0018]

[0019] in, is the probability that model i gives sample j to belong to category k;

[0020] S322: For sample j, the prediction probability matrix P of each model i is i Splice by column to get the predicted probability feature vector S of sample j on all models j , the predicted probability feature vector S j for:

[0021]

[0022] S323: The predicted probability feature vector S of N samples j j The new feature matrix S is obtained by column splicing. The feature matrix S is:

[0023]

[0024] Among them, each row S j It is the predicted probability concatenation feature of sample j on all models, and each column is the set of predicted probabilities of each model for a certain category.

[0025] Preferably, in step S1, the data preprocessing includes:

[0026] S11: Extract the time feature dataset and convert the time information into features that can be used by the model;

[0027] S12: Perform data cleaning and remove invalid data;

[0028] S13: Use the merge_asof function to align different data sets by time to merge the data;

[0029] S14: Perform result matching and integrate safety information into traffic data.

[0030] Before model training, processing the collected data ensures that the model can be trained on cleaner and higher-quality data, which helps to accelerate the convergence of the model, improve the training speed, and reduce the risk of overfitting. At the same time, it also enables the model to better adapt to new data, thereby improving the performance of the model in real applications and significantly improving the performance and effectiveness of the model.

[0031] Further preferably, in S11, extracting the time feature dataset includes:

[0032] S111: Read the vehicle data file and convert the date into datetime format;

[0033] S112: Align the time to the next and previous full five minutes respectively by defining functions;

[0034] S113: Divide the data into several blocks using code to facilitate efficient data processing;

[0035] S114: Generate a time range of five-minute intervals from the start time to the end time based on the minimum and maximum time of the data, and traverse each five-minute interval to extract the data subset within the time period:

[0036] S115: For each five-minute interval data subset, the total number of vehicles, the number of large vehicles, the total traffic flow, the proportion of large vehicles, the average speed, and the traffic saturation are calculated to form a complete time feature data set.

[0037] Since traffic data such as traffic volume has a strong correlation with time, hour and minute information can be extracted from the timestamp to create time features. However, in the real world, the recording time of traffic events often lags behind the actual occurrence time. Studies have shown that this time difference is about 5 minutes. Therefore, this application uses 5-minute traffic parameters as time features, thereby forming a complete time feature data set by extracting time features, converting time information into features that can be effectively utilized by the model, thereby improving prediction accuracy.

[0038] Further preferably, step S13 includes: using results_df to merge with the vehicle speed data, the number of over-temperature vehicles data, and the number of hazardous goods vehicles data respectively, to ensure that each row of data contains all relevant information, and then merging the calculation results of all blocks.

[0039] The quality and reliability of the data were improved by merging data sets from different sources, ensuring data consistency, and selecting representative samples for analysis.

[0040] Further preferably, step S14 includes: first dividing the security levels into three categories, then creating a copy data frame and initializing a new column, iterating each traffic record, extracting time period and segment information, matching records of corresponding time ranges and segments in the security level data, and if a match is found, updating the corresponding security level to the copy data frame, and finally exporting the integrated data frame to an Excel file to ensure that each record is accompanied by accurate security level information.

[0041] By matching the results, safety information is integrated into traffic data, ensuring that each traffic record can obtain the corresponding safety level according to time and section.

[0042] Preferably, step S1 further includes data balancing processing, using the SMOTE method to generate more minority class samples and reducing the number of majority class samples by a random downsampling method, wherein the SMOTE method generates new minority class samples by connecting minority class samples and their adjacent data in the feature space, and its formula is as follows:

[0043] x i =x i +λ·(x nn -x i )

[0044] Among them, x i is a minority sample, x nm is a random sample from the adjacent data, and λ is a random number between 0 and 1.

[0045] Since there is an extremely unbalanced problem in the number of traffic event data samples, this application uses the SMOTE method to generate more minority class samples to balance the imbalance between traffic event data and normal data, and uses a random downsampling method to reduce the number of majority class samples, thereby further balancing the data set.

[0046] Preferably, the M models described in step S2 include at least five models: BP neural network, LSTM, GRU, random forest, and gradient boosted decision tree (GBDT). In this application, each model is trained using different hyperparameters. Each model is trained batch by batch using a data loader, and the performance is evaluated using a validation set to ensure that the model has high prediction accuracy.

[0047] Furthermore, each model in the present application is cross-validated using the K-fold validation method, which effectively improves the generalization ability of the model, avoids overfitting, and improves the accuracy of model prediction.

[0048] Preferably, the present application also includes deploying the model trained in step S2 and the stacked model constructed in step S3 to a production environment through a cloud service platform, and constructing a user interface to display the prediction results output by the stacked model in real time on the user interface using different colors.

[0049] Since cloud platforms usually have redundancy and fault-tolerant mechanisms, deploying the model to the cloud platform in this application ensures the high availability and stability of the model, and protects the security of data and models. In addition, a user interface is established to enable users to intuitively view the possibility of traffic incidents occurring on each segmented road, helping users to specify corresponding action plans, optimize traffic flow and improve road safety.

[0050] Compared with the prior art, the present invention has the following beneficial effects:

[0051] 1. Improve forecast accuracy

[0052] By integrating multiple models, including BP neural networks, LSTM, GRU, random forest, and GBDT, this method can capture diverse features and patterns in traffic data, improving the accuracy and reliability of predictions. Time series models such as LSTM and GRU can effectively process and capture the temporal dependencies in time series data, enabling more accurate predictions of traffic events.

[0053] 2. Enhance system robustness

[0054] By stacking the outputs of multiple models and using a logistic regression classifier for ensemble learning, the system comprehensively considers the outputs of different models, reducing the potential errors introduced by a single model and improving overall robustness. The introduction of technologies such as SMOTE and random downsampling addresses the class imbalance problem in traffic event data, preventing the model from overlooking minority events and improving predictive capabilities.

[0055] 3. Real-time and high efficiency

[0056] This method is designed as a real-time application that can quickly process and analyze traffic data, predict potential traffic incidents in real time, and provide timely warnings and response measures for tunnel management.

[0057] 4. Strong adaptability

[0058] This method is not only applicable to highway tunnel traffic incident prediction, but can also be extended to other traffic scenarios, such as urban traffic management and bridge monitoring. The system is designed to be flexible, allowing the model to be adjusted and expanded according to different data sources and requirements, adapting to different traffic prediction tasks.

[0059] 5. Innovation

[0060] This invention has significant innovations in multi-model fusion, real-time traffic event prediction and data imbalance processing, providing a new technical solution for highway tunnel traffic management. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 Schematic diagram of the process of the present invention.

[0062] Figure 2 This is a flow chart of the BP neural network model provided by the present invention.

[0063] Figure 3 Flowchart of the LSTM neural network model provided by the present invention.

[0064] Figure 4 This is a flow chart of the random forest model provided by the present invention.

[0065] Figure 5 This is a flow chart of the gradient boosting decision tree model provided by the present invention.

[0066] Figure 6 This is the model fusion flow chart provided by the present invention. DETAILED DESCRIPTION

[0067] The accompanying drawings are for illustrative purposes only and are not to be construed as limiting the present invention. To better illustrate the following embodiments, some components in the accompanying drawings may be omitted, enlarged, or reduced in size, and do not represent actual product dimensions. Those skilled in the art will appreciate that some well-known structures and their descriptions may be omitted from the accompanying drawings.

[0068] Example 1

[0069] like Figure 1 As shown, this embodiment provides a real-time prediction method for highway tunnel traffic events based on multi-model fusion, which improves the accuracy and reliability of real-time highway tunnel traffic event prediction through multi-model fusion.

[0070] Preferably, in step S1, traffic data is first collected from various data sources, including ETC, radar, high-definition cameras, thermal imaging cameras, traffic incident detection systems, and other equipment. Data includes traffic volume (x1), traffic saturation (x2), the proportion of large vehicles (x3), average speed (x4), hazardous chemical vehicles on the road (x5), the number of overheated vehicles (x6), and the number of accidents per million kilometers (x7). Furthermore, data on the maximum longitudinal slope of the tunnel (x8) and the road surface condition index (x9) are collected from tunnel design and inspection data. In addition to static data, all dynamic data includes time information.

[0071] The data is then preprocessed, including data cleaning, format conversion, and missing value filling, to ensure data quality. Based on real-time traffic data, conversion and statistics are performed on traffic volume x1, traffic saturation x2, proportion of large vehicles x3, average speed x4, hazardous chemical vehicles in transit x5, number of over-temperature vehicles x6, and number of accidents per million kilometers x7. Useful features are extracted from the processed data to generate the input feature matrix for the prediction model.

[0072] In step S11, temporal feature extraction is performed. The process includes reading data and converting the time format, defining a time alignment function, processing the data in blocks, and merging the data. In this embodiment, 5-minute traffic parameters are used as temporal features. First, the vehicle data file is read and the date column is converted to datetime format to ensure correct parsing and processing of the temporal data. Functions are then defined to align the time to the next and previous full five-minute intervals, ensuring that all timestamps fall within a uniform five-minute interval. Furthermore, to handle large data sets, the code divides the data into multiple blocks, each containing 500,000 rows of data, enabling efficient in-memory data processing. Based on the minimum and maximum time values ​​of the data, a time range of five-minute intervals is generated from the start time to the end time. Each five-minute interval is then traversed to extract a data subset within that time period. By dynamically subsetting the data for each five-minute interval, the total number of vehicles, the number of large vehicles, the total traffic volume, the proportion of large vehicles, the average speed, and traffic saturation are calculated, forming a complete temporal feature dataset. This converts temporal information into features that can be effectively utilized by the model, thereby improving prediction accuracy.

[0073] In step S12, data cleaning is performed. Since the data collected by the front-end monitoring equipment may be missing or have abnormal values ​​in some time periods, it is necessary to eliminate some invalid data, import data from the data source, and identify and process missing values, abnormal values, and duplicate values. Then, the data type is converted, the data is standardized or normalized, the format is unified and the text data is cleaned, and spell checking and feature engineering are performed, thereby effectively improving the quality of the data.

[0074] In step S13, data merging is performed, and the merge_asof function is used to align different data sets by time. This function merges the closest time records according to the chronological order. The results_df is merged with the vehicle speed data, the number of over-temperature vehicles, and the number of dangerous goods vehicles respectively to ensure that each row of data contains all relevant information. Finally, the calculation results of all blocks are merged. Since the tunnel is predicted in sections in this embodiment, the merged data of each row merged_df is used and expanded into multiple rows, so that each row contains the static data of a tunnel section. This is achieved by looping through each row of data and combining it with the static data of the tunnel. Thus, through the above operations, the data sets from different sources are merged to ensure the consistency of the data, and representative samples are selected for analysis, thereby improving the quality and reliability of the data.

[0075] In step S14, the results are matched to load the main traffic data and safety level information from the Excel file. First, the safety level is divided into three categories: 0, 1, and 2, corresponding to normal conditions, abnormal parking conditions in the tunnel, and traffic incidents in the tunnel. The safety level information records the data of abnormal parking conditions and traffic incidents. Each data includes the time of the event, the type of event, and the segment in which the event occurred. The time column is converted to the datetime type for accurate comparison. Then, a copy data frame is created and a new column is initialized. By iterating each traffic record to extract the time period and segment information, the records of the corresponding time range and segment are matched in the security level data. If a match is found, the corresponding security level is updated to the copy data frame. Finally, the integrated data frame is exported to the Excel file, which realizes the loading of the main traffic data and safety level information from the Excel file, effectively integrating the safety information into the traffic data, and ensuring that each traffic record can obtain corresponding and accurate safety level information based on the time and segment.

[0076] Since traffic event data samples are extremely unbalanced in number, this embodiment also includes balancing the data by using the SMOTE method to generate more minority class samples to balance the imbalance between traffic event data and normal data. The SMOTE method generates new minority class samples by connecting minority class samples and their adjacent data in the feature space. For the minority sample x i , randomly select a sample x from its adjacent data nm , generate new samples, the formula is as follows:

[0077] x i =x i +λ·(x nn -x i ) (1)

[0078] Among them, x i is a minority sample, x nm is a random sample from the adjacent data, and λ is a random number between 0 and 1.

[0079] Second, a random downsampling method is used to reduce the number of majority class samples to further balance the dataset.

[0080] Then, in this embodiment, the data is divided into a training set, a validation set, and a test set in a ratio of 6:2:2. The training set is used for model training, the validation set is used for parameter adjustment and evaluation of model performance, and the test set is used for evaluation and testing of the final model. The data is normalized and converted into a standard normal distribution with a mean of 0 and a variance of 1. First, it is used to fit and normalize the training set data to ensure that the training data conforms to the standard normal distribution. Then, the test set data is subjected to the same normalization process to maintain the consistency of the data distribution. Data normalization helps to improve the prediction accuracy and training efficiency of the model.

[0081] Preferably, in step S2, five models, namely, BP neural network, LSTM, GRU, random forest and gradient boosted decision tree (GBDT), are designed and trained based on the data obtained in step S1, and different hyperparameters are used to train the above models respectively. Each model is trained batch by batch through the data loader, and the performance is evaluated using the validation set.

[0082] like Figure 2 As shown, Figure 2 The BP neural network model flow chart provided for this embodiment includes three main parts: input layer, hidden layer and output layer. In this model, the input layer has 13 neurons, and each neuron corresponds to one feature. In addition to the above-mentioned traffic data and tunnel static data, the 13 neurons also have the start time and end time of every five minutes. The start time is divided into start hour and start minute, and the end time is divided into end hour and end minute. Therefore, the dimension of the input data is 13. The hidden layer is set to two layers. The first hidden layer has 64 neurons, which is responsible for extracting high-level features from the input data. The second hidden layer has 32 neurons, which are used to further abstract and combine the features extracted by the first hidden layer. The output layer contains three neurons, corresponding to the three categories in the classification task. The output of each neuron represents the predicted probability of a category. In the hidden layer, the ReLU activation function is used to alleviate the gradient vanishing problem and accelerate the training process. For negative input, ReLU outputs 0; for positive input, ReLU outputs the input value itself. In the output layer, the Softmax function is used to convert the output of the network into a probability distribution. The formula of the Softmax function is:

[0083]

[0084] Among them, z i is the output value of the i-th category, p i is the predicted probability of the category, j represents the sample, and the denominator in the formula is the exponential sum of the output values ​​of all categories.

[0085] To prevent overfitting, a Dropout layer was introduced to reduce over-reliance on training data by randomly dropping some neurons from the network. The model training used the cross-entropy loss function (Equation 3) to optimize the model's prediction accuracy.

[0086]

[0087] Among them, N is the number of samples, K is the number of categories, and y j,k is the true label (0 or 1) of sample j in category k, and p i,k is the predicted probability of class k by model i. During training, the Adam optimizer is also used, combining the momentum method with an adaptive learning rate to calculate the momentum estimate of the gradient and the weighted moving average of the squared gradient (Equations 4 and 5). These are updated using a momentum decay rate of 0.9 and a mean decay rate of 0.999, respectively. Bias correction is performed to calculate unbiased estimates. Model parameters are updated based on the learning rate (0.001) and the corrected momentum and squared gradient averages. The Adam optimizer adaptively adjusts the learning rate at each training step to ensure the stability and efficiency of parameter updates.

[0088]

[0089] Among them, m t is the first-order moment estimate at time step t (i.e., the exponentially weighted moving average of the gradient), which is used to estimate the gradient; β1 is the momentum decay rate, m t-1 is the first-order moment estimate at time step t-1; v t is the second-order moment estimate at time step t (i.e., the exponentially weighted moving average of the squared gradient), which is used to estimate the instability of the gradient (i.e., the variance of the gradient); v t-1 is the second-order moment estimate at time step t-1, β2 is the mean decay rate, is the gradient at time step t, which is the derivative of the loss function with respect to the model parameters θ.

[0090] To improve the model's generalization and avoid overfitting, a K-fold cross-validation method is used during training. In this example, the K value for cross-validation is set to 5. In each iteration, a subset is selected as the validation set, and the remaining K-1 subsets are used as the training set. This process is repeated K times, ensuring that each subset has been validated. Parameter optimization is also performed using the Adam optimizer. By continuously iterating these steps, the model gradually optimizes parameters, achieving convergence in the loss function and improving prediction accuracy.

[0091] like Figure 3 As shown, Figure 3 The flow chart of the LSTM neural network model provided for this embodiment, in which the LSTM model is used to process multidimensional sequence data containing time features, traffic data, tunnel static data and historical statistical data to predict the target variable of "safety level". Input features include time features such as "start hour", "start minute", "end hour", and "end minute", as well as indicators related to traffic conditions such as "traffic volume", "proportion of large vehicles", "traffic saturation", "average speed", "number of over-temperature vehicles", "number of hazardous chemical vehicles", "maximum longitudinal slope of the tunnel", "number of accidents per million kilometers" and "road condition index". Through these features, LSTM can capture the dynamic relationship between time series features and different variables, thereby effectively predicting road safety risks. In the LSTM model, three gate mechanisms (forget gate, input gate and output gate) are introduced to control the flow of information, so that information can be effectively retained or forgotten when processing long time series. In this model, the key parameters of the LSTM model include: input_size (the dimension of the input features, set to 13, that is, the 13 features mentioned above), hidden_size (the number of units in the LSTM hidden layer, set to 50), num_layers (the number of LSTM layers, set to 2), and output_size (the number of output categories, set to 3). In addition, to prevent overfitting, the Dropout layer is used in the LSTM model, and the dropout rate is set to 0.5. During the forward propagation of the LSTM, the forget gate (f t ) determines which parts of the historical information need to be discarded (Formula 6); then, the input gate (i t ) Combine the current input and the hidden state of the previous moment to determine what new information will be stored in the unit state (C t ) in (Formula 7); Then, through the candidate memory cells Generate new candidate information (Formula 8), and combine it with the output of the forget gate to update the current unit state (Formula 9); finally, the output gate ( t ) determines which parts of the current unit state will be passed to the hidden state at the next moment (Equations 10 and 11).

[0092] f t=σ(W f ·[h t-1 ,x t ]+b f ) (6)

[0093] i t =σ(W i ·[h t-1 ,x t ]+b i ) (7)

[0094]

[0095] o t =σ(W o ·[h t-1 ,x t ]+b o ) (10)

[0096] h t =o t *tanh(C t ) (11)

[0097] For model training, the data is first divided into training and validation sets and normalized. The data is then converted to PyTorch tensors and reshaped to fit the LSTM model. During training, a cross-entropy loss function is used to calculate the difference between predicted values ​​and actual labels, and the model parameters are updated via backpropagation. To further optimize the training process, the Adam optimizer is used with weight decay to prevent overfitting. During each training cycle (epoch), the model iterates over the training set, gradually adjusting the parameters. After each epoch, the model performance is evaluated on the validation set, and the optimal model parameters are recorded. After training, the model is loaded with the optimized parameters to ensure optimal performance on the validation set.

[0098] Secondly, in the GRU model, its flowchart is similar to that of the LSTM model, and its structure mainly includes the input layer, GRU layer, and fully connected layer. The input layer is used to receive input with a feature dimension of input_size (set to 13). The GRU layer is the main recurrent unit, and the hidden_size (set to 50) is set as the dimension of the hidden state, and num_layers (set to 2) is the number of GRU layers. The GRU layer determines the update of the hidden state by the update gate and the reset gate. The fully connected layer maps the output of the GRU layer to the dimension of the target category, that is, output_size (set to 3, corresponding to 3 categories of results). The GRU model controls the flow of information by introducing a gating mechanism, which mainly includes three parts: update gate, reset gate, and candidate activation. Update gate z tUsed to control the update degree of the current hidden state, calculated as formula 12. Reset gate r t It is used to determine how much of the previous state is forgotten, and is calculated as shown in formula 13. Current memory content Calculated by formula 14, the final hidden state h t Updated by Equation 15. The fully connected layer maps the output of the GUR model to the target category.

[0099] z t =σ(W Z ·[h t ,x t ]+b z ) (12)

[0100] r t =σ(W r ·[h t ,x t ]+b r ) (13)

[0101]

[0102] During training, the data is reshaped into the shape [batch_size, seq_len, input_size], where seq_len = 1 (since each sample has only one time step), the batch size is 64, the learning rate is 0.0001, and the weight decay is 1e-4. The loss function is cross entropy loss, and the optimizer uses Adam with a learning rate of 0.0001 and a weight decay of 1e-4. The model parameters are updated by gradient descent.

[0103] like Figure 4 As shown, Figure 4 The flowchart of the random forest model provided in this embodiment improves the accuracy of classification or regression tasks by constructing multiple decision trees. Each decision tree is generated by random sampling of the training data set with replacement, and a portion of features is randomly selected at each node to find the optimal splitting point, thereby reducing overfitting and improving the generalization ability of the model. The main parameters of the model include the number of decision trees (n_estimators = 100) and the maximum number of features for splitting (max_features = 42). The more decision trees there are, the more stable the performance of the model is. During the training process, the model selects the optimal splitting point based on the characteristics of the input data and constructs the structure of the tree. By making independent predictions on each tree, the final output is obtained by voting (classifying) the prediction results of all trees. The prediction result of the random forest is the majority vote result (classification), as shown in Formula 16. The goal of the random forest model is to improve the accuracy and robustness of the overall prediction by reducing the high variance characteristics of a single decision tree.

[0104]

[0105] in, is the predicted value of random forest, Ti(x) is the predicted category of the input sample of the i-th tree, and mode means taking the mode.

[0106] like Figure 5 As shown, Figure 5 The flow chart of the gradient boosting decision tree model provided in this embodiment, wherein the gradient boosting decision tree optimizes prediction accuracy by gradually constructing a series of decision trees. Each new tree is trained on the residuals of the previous tree to reduce the error of the overall model. The training process includes initializing the model, then iteratively calculating the prediction residuals of the current model, and fitting these residuals with a new decision tree. The prediction results of each new tree are scaled by the learning rate to adjust the contribution to the model. The main parameters include the number of trees (n_estimators = 100), the learning rate (learning_rate = 0.1), and the maximum depth of the tree (max_depth = 3). The formula for model training is:

[0107] F m =F m-1 (x)+η·T m (x) (17)

[0108] Among them F m (x) represents the predicted value of the mth iteration, F m-1 (x) represents the predicted value of the m-1th iteration, T m (x) represents the predicted value of the mth decision tree, and η is the learning rate.

[0109] In this example, each model is trained using different hyperparameters. Each model is trained batch by batch using a data loader, and its performance is evaluated using a validation set. This ensures high prediction accuracy, captures diverse features and patterns in traffic data, and improves prediction accuracy and reliability. Furthermore, time series models such as LSTM and GRU can effectively process and capture temporal dependencies in time series data, enabling more accurate predictions of traffic events.

[0110] Preferably, if Figure 6 As shown, Figure 6 The model fusion flowchart provided in this embodiment shows that in step S3, the prediction probabilities of the above five models are used as feature inputs to construct a stacking model for final prediction. After training, the prediction results of the stacking model are evaluated using evaluation indicators (accuracy, precision, recall rate and F1 score).

[0111] First, obtain the probability output of each model. In step S31, use the get_probabilities function to make predictions for each model. This function uses the eval mode of the model and forward propagates the input data to obtain the predicted probability of each category. The models include BP neural network, LSTM, GRU, random forest and gradient boosting decision tree. The prediction result generated by each model is a probability distribution. For example: in this embodiment, the predicted probability of test sample 1 is: [0.1, 0.7, 0.2], the predicted probability of test sample 2 is: [0.3, 0.4, 0.3], and the predicted probability of test sample 3 is: [0.05, 0.2, 0.75]. For each model i and sample j, the predicted probability of model i for sample j is p ij .

[0112] In step S32, the predicted probabilities of all models are concatenated into a new feature matrix. These features will serve as the input to the stacking model. The feature matrix is ​​a two-dimensional array, where each row is the feature of a sample, containing the predicted probabilities of all models.

[0113] In step S321, the prediction probability matrix P of model i is constructed i , in M ​​models, the prediction probability matrix Pi output by each model is an N×K matrix, where N is the number of samples and K is the number of categories. The prediction probability matrix P i As shown below:

[0114]

[0115] in, is the probability that model i gives sample j to belong to category k.

[0116] In step S322, for sample j, the prediction probability matrix P of each model i is i Splice by column to get the predicted probability feature vector S of sample j on all models j , if each model has K categories, then the predicted probability feature vector S j The number of columns is M×K. The predicted probability feature vector S for each sample j j for:

[0117]

[0118] Among them, S j is the predicted probability feature vector of sample j on all models.

[0119] In step S323, the predicted probability feature vector S of N samples j is j The new feature matrix S is obtained by concatenating columns.

[0120] This matrix contains the prediction information of all base models for each sample and will be used to train the stacked model.

[0121]

[0122] Each row S j It is the concatenation of the predicted probabilities of sample j across all models. Each column is the set of predicted probabilities of each model for a certain category.

[0123] Preferably, in step S33, logistic regression is used as the final classifier of the stack to train the feature matrix S. This classifier will learn how to combine the prediction results of each model to generate the final prediction, thereby obtaining a stacked model, wherein the formula of the logistic regression is:

[0124]

[0125] Where P(y=k|x) represents the probability that the target variable y is equal to category k given the input feature X; X represents the input feature, that is, the row of the feature matrix; and b k Represents the weight and bias term of category k; K represents the number of categories; j represents the sample; and b j Represents the weight and bias term of sample j.

[0126] Logistic regression learns these weights and biases by maximizing the log-likelihood function. The logistic regression model is trained using the stacked feature matrix S and the true labels. The training process uses the training data (stacked features and corresponding labels) to optimize the logistic regression model's weights W and biases b. The training process minimizes the loss function using an optimization algorithm to improve classification accuracy.

[0127] Preferably, after training is complete, the logistic regression model is evaluated using a validation or test set to determine its performance, including metrics such as accuracy, precision, recall, and F1 score, and to generate a confusion matrix. The logistic regression model will be able to make predictions on new data, obtain the stacked features of the new data, pass the new data through all the base models to obtain the predicted probabilities, and splice them into a feature matrix. The logistic regression model is applied, and these features are input into the trained logistic regression model to obtain the final prediction results.

[0128] Preferably, this embodiment also includes deploying the trained BP, LSTM, GRU, random forest, GBDT models, and integrated stacked models to a production environment via a cloud service platform, and inputting the processed data into the deployed models for real-time prediction. The stacked models will generate prediction results based on the latest traffic data, i.e., the probability of traffic events occurring.

[0129] Preferably, a user-friendly interface is constructed to display the likelihood of traffic incidents occurring in each segmented tunnel in real time, and to display the information in different colors (normal situation (0) is indicated by green, abnormal parking situation in the tunnel (1) is indicated by yellow, and traffic incident in the tunnel (2) is indicated by red). Decision suggestions are provided based on the prediction results to help users (such as traffic management personnel and drivers) formulate corresponding action plans to optimize traffic flow and improve road safety.

[0130] Example 2

[0131] This example uses a single tunnel on a highway as an example. Traffic data from the tunnel, along with tunnel design and inspection data, is collected over a year. The tunnel is equipped with a traffic event monitoring system, high-definition cameras, integrated radar and vision cameras, and infrared thermal imaging cameras. Combined with ETC checkpoint data at the tunnel entrance, various raw traffic data within the tunnel are collected. Data from multiple heterogeneous sources is collated, and data within a five-minute period is selected as a sample. Temporal feature extraction is used to combine the various data types, extracting hour and minute information from the raw data timestamps to create a temporal feature. Using five-minute traffic parameters as temporal features, the data is read, converted to datetime format, a time alignment function is defined, the data is processed in blocks, and finally merged. Each five-minute interval is traversed to extract a data subset within that time period. For each five-minute interval, the total number of vehicles, the number of large vehicles, the total traffic volume, the proportion of large vehicles, the average speed, and traffic saturation are calculated for the dynamic data subset, forming a complete temporal feature dataset. Because the data collected by the front-end monitoring equipment may contain missing time periods or outliers, it is necessary to eliminate some invalid data. Import data from the data source and identify and address missing, outlier, and duplicate values. Next, convert data types, standardize or normalize the data, unify the format, clean text data, perform spell checking, and perform feature engineering. Use the merge_asof function to align different datasets by time. Merge results_df with the speed data, the number of overheated vehicles, and the number of hazardous materials vehicles separately, ensuring that each row contains all relevant information. Finally, merge the calculation results of all blocks.

[0132] Because the tunnel is divided into five sections, each section has different accident counts per million kilometers (x7), maximum longitudinal tunnel slope (x8), and road condition index (x9). The remaining data remains the same. Therefore, one sample needs to be expanded into five samples based on the different sections, as shown in Table 1. Traffic incident statistics within the tunnel, the section where the incident occurred, and the time of the incident are exported from the traffic incident monitoring system. Safety levels are categorized into three categories: 0, 1, and 2, corresponding to normal conditions, abnormal parking conditions, and traffic incidents occurring in the tunnel. Each exported tunnel traffic event data entry includes the time of occurrence, event type, and section where the incident occurred. By iterating through each traffic record, extracting the time period and section information, the safety level data is matched against records with the corresponding time range and section. If a match is found, the corresponding safety level is updated to the duplicate data frame. Finally, the combined data frame is exported, ensuring that each record has accurate safety level information. The above process results in a dataset of 527,076 data points. The category distribution of the original dataset is: [0:527,039 1:26 2:10].

[0133]

[0134]

[0135] Table 1

[0136] Preferably, due to the extremely unbalanced number of traffic event data samples, the dataset needs to be balanced. This method uses SMOTE oversampling and downsampling to oversample and downsample traffic event data and non-traffic event data, respectively. The traffic event data and breakdown parking data are oversampled to 40,000 data items. The category distribution of the oversampled dataset is: [0:527039 1:40000 2:40000]. The remaining data is then downsampled to 40,000 data items. The category distribution of the downsampled dataset is: [0:40000 1:40000 2:40000].

[0137] Preferably, in this embodiment, each model is trained for two epochs, and the results of each training are as follows:

[0138] In the BP neural network model, its model design includes two hidden layers and one output layer. The network structure is: the input layer is connected to the first hidden layer (with 64 neurons), the first hidden layer is connected to the second hidden layer (with 32 neurons) through the ReLU activation function, and finally, the second hidden layer is connected to the output layer through the Dropout layer. The output layer is used to generate classification results. The model is trained using the Adam optimizer with a learning rate of 0.001 and a weight decay of 1e-2. During the training process, the loss is calculated by CrossEntropyLoss, and the weights are updated by backpropagation. In each epoch, the model is trained on the training data, and the performance is evaluated on the validation data to calculate the accuracy. If the accuracy on the validation set improves, the state of the current model is saved. Finally, the model is evaluated by K-fold cross validation, the accuracy of each fold is output, and the average performance index is calculated. The training results are shown in Table 2:

[0139]

[0140] Table 2

[0141] As can be seen from Table 2, the results of the BP neural network model on the training set are: average accuracy: 0.9694, average precision: 0.9711, average recall: 0.9694, and average F1 score: 0.9692.

[0142] In the LSTM model, its design includes an LSTM layer and a fully connected layer. The LSTM layer has 50 hidden units and 2 layers, processing the input data sequence to capture time series features. The input data passes through the LSTM layer, where the hidden state and cell state are initialized to zero. The output of the LSTM layer is processed by the Dropout layer to prevent overfitting, and then passed to the fully connected layer to generate the final classification result. The model uses the Adam optimizer with a learning rate of 0.0005 and a weight decay of 1e-3. During training, CrossEntropyLoss is used to calculate the loss and optimize the network parameters through backpropagation. Each epoch model is trained on the training set and the performance is evaluated on the validation set. K-fold cross validation is used for model evaluation to ensure the stability and generalization ability of the model. The LSTM model calculates the accuracy on the validation set and records the optimal model state for subsequent prediction and evaluation. The training results are shown in Table 3:

[0143]

[0144] Table 3

[0145] As can be seen from Table 3, the results of the LSTM model on the training set are: average accuracy: 0.9669, average precision: 0.9678, average recall: 0.9669, and average F1 score: 0.9668.

[0146] In the GRU model, its design includes a GRU layer and a fully connected layer. The GRU layer has 50 hidden units and 2 layers, which processes the input sequence data to capture the dynamic characteristics of the time series. The input of the model passes through the GRU layer, where the hidden state is initialized to zero. The output of the GRU layer is regularized by the Dropout layer to reduce the risk of overfitting, and then passed to the fully connected layer to generate the final classification prediction. The model uses the Adam optimizer, with a learning rate set to 0.0001 and a weight decay of 1e-4. During training, the loss is calculated using CrossEntropyLoss, and the parameters are optimized by backpropagation. The model is trained on the training set and its performance is evaluated on the validation set. The stability and generalization ability of the GRU model are evaluated by K-fold cross validation. In each fold, the accuracy of the model on the validation set is recorded, and the best model state is saved for subsequent prediction and performance evaluation. The training results are shown in Table 4:

[0147]

[0148] Table 4

[0149] As can be seen from Table 4, the results of the GRU model on the training set are: average accuracy: 0.8285, average precision: 0.8376, average recall: 0.8285, and average F1 score: 0.8248.

[0150] In a random forest model, the design involves constructing a forest of multiple decision trees. Each tree randomly selects features and samples during training to enhance the model's diversity and robustness. The model is first trained on a balanced dataset processed with SMOTE and downsampling. Classification accuracy is improved by integrating the predictions of multiple decision trees. The model is trained on the training set, using the fit method to learn patterns in the data. In this example, the random forest model achieved an accuracy of 0.9995 on the test set.

[0151] In the gradient boosting decision tree model, its design iteratively constructs a series of weak learners—decision trees—where each tree improves model performance by gradually correcting the errors of the previous tree. The training process begins with an initial model, calculates the residuals for each sample, and then trains a new decision tree on these residuals to minimize these residuals. This process is implemented using the fit method, which passes the training data to the model. In each iteration, the new tree model is weighted and added to the existing model to optimize the loss function. After training, the model is evaluated on the test set to calculate its prediction accuracy. In this embodiment, the gradient boosting decision tree model achieved an accuracy of 0.9846 on the test set. Preferably, this embodiment also includes a fusion of the above models to produce a final stacked model. The stacked model uses multiple base classifiers, including a BP neural network, an LSTM model, a GRU model, a random forest classifier, and a gradient boosting classifier. The predictions of each base model on the training and test sets are used as new features to create a new dataset. This dataset contains the predictions of all base models for each sample and is called the "first-level prediction." Using the first-layer prediction dataset as input, a new model, the "stacked model," was trained. The stacked model was then applied to the test dataset to obtain the final prediction results. In this example, the stacked model achieved the following results on the test set: accuracy: 0.9998; average precision: 0.9998; average recall: 0.9998; and average F1 score: 0.9998. The stacked model combines the advantages of multiple base models, optimizing prediction results and improving overall model performance.

[0152] In summary, as shown in Table 5, Table 5 is a comparison of the indicators of each model provided in this embodiment. From the data in the table, it can be seen that each model obtained after training has excellent performance, and the stacked model obtained by subsequently fusing each model also has high prediction accuracy and reliability for real-time prediction of highway tunnel traffic events.

[0153]

[0154] Table 5

[0155] Further preferably, this embodiment also includes real-time prediction and display. The front-end equipment collects real-time data on traffic volume x1, traffic saturation x2, proportion of large vehicles x3, average vehicle speed x4, hazardous chemical vehicles on the way x5, and number of over-temperature vehicles x6. The fused stacking model can be used to make real-time predictions on the possibility of traffic incidents in each section of the tunnel and perform visual display.

[0156] Obviously, the above embodiments of the present invention are merely examples for the purpose of clearly illustrating the technical solutions of the present invention, and are not intended to limit the specific implementation methods of the present invention. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the claims of the present invention shall be included within the scope of protection of the claims of the present invention.

Claims

1. A real-time prediction method for highway tunnel traffic incidents based on multi-model fusion, the method comprising: S1: Collect traffic data from various data sources and preprocess it. Then, divide the processed data into training, validation, and test sets according to specific ratios, and normalize the training and test set data. S2: Use the processed data to design and train M models; S3: The M models obtained in S2 are constructed into a stacked model using a stacking ensemble learning strategy. The prediction probability of each model is used as a feature input and input into the stacked model to obtain the final prediction result. It is characterized in that the stacking model constructed by adopting the stacking ensemble learning strategy in step S3 includes: S31: Use the get_probabilities function to predict each model trained in S2 to obtain the predicted probability of each category; S32: Concatenate the predicted probabilities of all models into a new feature matrix; S33: Use logistic regression as the final classifier of the stack to train the feature matrix to obtain a stack model, wherein the formula of the logistic regression is: Where P(y=k|x) represents the probability that the target variable y is equal to category k given the input feature X; X represents the input feature, that is, the row of the feature matrix; and b k Represents the weight and bias term of category k; K represents the number of categories; j represents the sample; and b j Represents the weight and bias term of sample j.

2. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 1 is characterized in that: The step S32 specifically includes: S321: Construct the prediction probability matrix P of model i i , in M ​​models, the prediction probability matrix P output by each model i is an N×K matrix, where N is the number of samples and K is the number of categories; the prediction probability matrix P i for: in, is the probability that model i gives sample j to belong to category k; S322: For sample j, the prediction probability matrix P of each model i is i Splice by column to get the predicted probability feature vector S of sample j on all models j , the predicted probability feature vector S j for: S323: The predicted probability feature vector S of N samples j j The new feature matrix S is obtained by column splicing. The feature matrix S is: Among them, each row S j It is the predicted probability concatenation feature of sample j on all models, and each column is the set of predicted probabilities of each model for a certain category.

3. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 1 is characterized in that: In step S1, the data preprocessing includes: S11: Extract the time feature dataset and convert the time information into features that can be used by the model; S12: Perform data cleaning and remove invalid data; S13: Use the merge_asof function to align different data sets by time to merge the data; S14: Perform result matching and integrate safety information into traffic data.

4. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 3 is characterized in that: In said S11, said extracting a time feature data set includes: S111: Read the vehicle data file and convert the date into datetime format; S112: Align the time to the next and previous full five minutes respectively by defining functions; S113: Divide the data into several blocks using code to facilitate efficient data processing; S114: Generate a time range of five-minute intervals from the start time to the end time based on the minimum and maximum time of the data, and traverse each five-minute interval to extract the data subset within the time period: S115: For each five-minute interval data subset, the total number of vehicles, the number of large vehicles, the total traffic flow, the proportion of large vehicles, the average speed, and the traffic saturation are calculated to form a complete time feature data set.

5. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 4 is characterized in that: Step S13 includes: using results_df to merge with the vehicle speed data, the number of over-temperature vehicles data, and the number of hazardous goods vehicles data, respectively, to ensure that each row of data contains all relevant information, and then merging the calculation results of all blocks.

6. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 5 is characterized in that: Step S14 includes: first, dividing the security levels into three categories, then creating a copy data frame and initializing a new column, iterating each traffic record, extracting time period and segment information, matching records of the corresponding time range and segment in the security level data, and if a match is found, updating the corresponding security level to the copy data frame. Finally, exporting the integrated data frame to an Excel file to ensure that each record is accompanied by accurate security level information.

7. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 1 is characterized in that: Step S1 also includes data balancing processing, using the SMOTE method to generate more minority class samples and reducing the number of majority class samples through a random downsampling method, wherein the SMOTE method generates new minority class samples by connecting minority class samples and their adjacent data in the feature space, and its formula is: x i =x i +λ·(x nn -x i ) Among them, x i is a minority sample, x nn is a random sample from the adjacent data, and λ is a random number between 0 and 1.

8. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 1 is characterized in that: The M models described in step S2 include at least five models: BP neural network, LSTM, GRU, random forest and gradient boosting decision tree.

9. The method for real-time prediction of highway tunnel traffic incidents based on multi-model fusion according to claim 8 is characterized in that: Each model was cross-validated using the K-fold validation method.

10. A real-time prediction method for highway tunnel traffic incidents based on multi-model fusion according to any one of claims 1 to 9, characterized in that: It also includes deploying the model trained in step S2 and the stacked model constructed in step S3 to a production environment through a cloud service platform, and building a user interface to display the prediction results output by the stacked model in real time on the user interface using different colors.

Citation Information

Patent Citations

  • Traffic flow prediction method based on deep learning

    CN114444813A

  • Road traffic flow prediction method based on stacked regression

    CN117116042A