Highway tunnel traffic incident real-time prediction method based on multi-model fusion
Through the multi-model fusion method, the stacked models are constructed using the predicted probability of multiple models, which solves the problems of insufficient traffic data feature capture and incomplete model fusion in the prior art, and realizes real-time prediction of high accuracy and reliability of highway tunnel traffic events.
Patent Information
- Application Number
- CN202411553241.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-01
- Publication Date
- 2025-03-07
- Estimated Expiration
- 2044-11-01
AI Technical Summary
The existing technology is difficult to fully capture complex traffic data characteristics, resulting in insufficient real-time prediction accuracy and reliability of road tunnel traffic events, and failure to effectively integrate the strengths of multiple models, resulting in uneven prediction effects.
Using a multi-model fusion method, multiple models (such as BP neural network, LSTM, GRU, random forest and GBDT) are designed and trained by collecting traffic data from multiple data sources and preprocessing them, and then using stacking ensemble learning strategies to build stacking models, using the prediction probability of each model as feature input, and the final prediction results are generated.
It improves the accuracy and reliability of real-time prediction of road tunnel traffic events, enhances the robustness of the system, realizes rapid processing and analysis of traffic data, predicts potential traffic events in real time, and provides timely early warnings and response measures for tunnel management.
Smart Images

Figure CN119580481A_ABST
Abstract
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 are often accompanied by high safety risks due to their special closed environment. Therefore, real-time and accurate prediction of possible traffic incidents in tunnels has become the key to improving the level of tunnel safety management. However, most of the existing traffic incident prediction methods are based on a single model or simple statistical analysis, which makes it difficult to fully capture the complex characteristics of traffic data, resulting in insufficient prediction accuracy and reliability. Although traditional machine learning models such as decision trees and support vector machines can process structured traffic data to a certain extent, due to the complexity of factors such as traffic flow, vehicle speed, and the proportion of large vehicles in tunnels, these models have uneven prediction effects on high-dimensional and variable feature data. In addition, existing methods generally have data imbalance problems, especially in traffic incident prediction, where the data of accidents is far less than normal data, which makes the model easily biased towards the majority class during training, thereby reducing the sensitivity to minority class events. In order to solve these problems, deep learning models such as long short-term memory networks (LSTM) and gated recurrent units (GRU) have been introduced in recent years to deal with the long-term dependence of time series data. However, single models still have limitations, such as overfitting to specific scenarios or strong dependence on specific features, which makes the predictions lack of robustness and universality. Although some studies have begun to try multi-model fusion and improve prediction accuracy through integrated learning, these methods often only stay at simple model combinations and fail to effectively integrate the strengths of various models and give full play to the advantages of integrated models, resulting in a large room for improvement when dealing with complex traffic conditions. Therefore, the existing technology urgently needs a more comprehensive and intelligent multi-model fusion method that can effectively solve the problem of data imbalance and improve the real-time prediction capability of 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 difficult to fully capture the complex traffic data characteristics, resulting in insufficient prediction accuracy and reliability, and fails to effectively integrate the strengths of various models, cannot give full play to the advantages of the integrated model, and has 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 preprocess them. Then divide the processed data into training set, validation set and test set according to a specific ratio, and normalize the training set and test set 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 stacked ensemble learning strategy, and the prediction probability of each model is used as a feature input, which is input into the stacked model for prediction to obtain the final prediction result;
[0008] In this application, multiple models are integrated to capture different features and patterns in traffic data, improve the accuracy and reliability of prediction, and set a time series model in the integrated multiple models to effectively process and capture the time series dependencies in time series data, so as to have more accurate prediction capabilities for the occurrence of traffic events. Using the prediction probabilities of multiple models as feature inputs, a stacking model is constructed for final prediction, which can comprehensively consider the outputs of different models, reduce the errors that may be caused by a single model, improve overall robustness, and can also quickly process and analyze traffic data, predict potential traffic events in real time, and provide timely warnings and response measures for tunnel management. In addition, this method is highly flexible and can adjust and expand the model according to different data sources and needs to adapt to different traffic prediction tasks.
[0009] Preferably, in step S3, constructing a stacked model using a stacked ensemble learning strategy includes:
[0010] S31: Use the get_probabilities function to make predictions for 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 stacked 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 , among the 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 sample j belongs to category k for model i;
[0020] S322: For sample j, the prediction probability matrix P of each model i is i Concatenate 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 concatenation. 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 collection 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 speed up the convergence of the model, improve the training speed, and reduce the risk of overfitting. 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 said S11, said extracting a time feature data set comprises:
[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 the code to facilitate efficient data processing;
[0035] S114: Generate a time range of five-minute intervals from the start time to the end time according to the minimum and maximum time of the data, and traverse each five-minute interval to extract a 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 volume, the proportion of large vehicles, the average vehicle speed and the traffic saturation are calculated, thereby forming a complete time characteristic 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. 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 minutes of 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 used 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 dangerous 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, the step S14 includes: firstly dividing the security levels into three categories, then creating a copy data frame and initializing a new column, iterating each traffic record, extracting the time period and section information, matching the records of the corresponding time range and section 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 the traffic data, ensuring that each traffic record can obtain the corresponding safety level according to time and section.
[0042] Preferably, 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 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 the 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 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, in this application, the SMOTE method is used to generate more minority class samples to balance the imbalance between traffic event data and normal data, and a random downsampling method is used 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 through a data loader, and the performance is evaluated using a validation set to ensure that the model has a high prediction accuracy.
[0047] Further preferably, in the present application, each model adopts the K-fold validation method for cross-validation, 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 can also protect the security of data and models. In addition, a user interface is established to enable users to intuitively view the possibility of traffic incidents 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 such as BP neural network, LSTM, GRU, random forest, GBDT, etc., this method can capture different features and patterns in traffic data and improve the accuracy and reliability of prediction. Time series models such as LSTM and GRU can effectively process and capture the temporal dependencies in time series data and have more accurate prediction capabilities for the occurrence of traffic events.
[0053] 2. Enhance system robustness
[0054] By stacking the outputs of multiple models and using logistic regression classifiers for ensemble learning, the system can comprehensively consider the outputs of different models, reduce the errors that may be caused by a single model, and improve overall robustness. The introduction of technologies such as SMOTE and random downsampling solves the problem of class imbalance in traffic event data, prevents the model from ignoring minority events, and improves prediction capabilities.
[0055] 3. Real-time and high efficiency
[0056] The 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 event prediction, but can also be extended to other traffic scenarios, such as urban traffic management, bridge monitoring, etc. The system is designed to be flexible and can adjust and expand the model according to different data sources and requirements to adapt 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, and provides a new technical solution for highway tunnel traffic management. BRIEF DESCRIPTION OF THE DRAWINGS
[0061] Figure 1 The figure is a schematic diagram of the process of the method 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 a flow chart of the model fusion provided by the present invention. DETAILED DESCRIPTION
[0067] The drawings of the present invention are only for illustrative purposes and should not be construed as limiting the present invention. In order to better illustrate the following embodiments, some parts of the drawings may be omitted, enlarged or reduced, and do not represent the size of the actual product; it is understandable to those skilled in the art that some well-known structures and their descriptions in the drawings may be omitted.
[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 a variety of data sources, including data from ETC, radar, high-definition camera, thermal imaging camera, traffic incident detection system and other equipment, including traffic volume x1, traffic saturation x2, large vehicle ratio x3, average vehicle speed x4, hazardous chemical vehicles on the way x5, number of overheated vehicles x6, number of accidents per million kilometers x7, and data on tunnel longitudinal maximum slope x8 and road condition index x9 are collected from tunnel design data and regular inspection data. In addition to static data, all dynamic data have time information.
[0071] Then the data is preprocessed, including data cleaning, format conversion, missing value filling, etc., to ensure data quality. According to real-time traffic data, traffic volume x1, traffic saturation x2, large vehicle ratio x3, average vehicle speed x4, hazardous chemical vehicles on the way x5, number of over-temperature vehicles x6, number of accidents per million kilometers x7 and other real-time traffic data are converted and counted, and useful features are extracted from the processed data to generate an input feature matrix for use in the prediction model.
[0072] In step S11, time feature extraction is performed, and the process includes reading data and converting the time format, defining a time alignment function, processing data in blocks, processing data in blocks, and merging data. In this embodiment, a 5-minute traffic parameter is used as the time feature. First, the vehicle data file is read and the date column is converted to the datetime format to ensure the correct parsing and processing of the time data. Then, the time is aligned to the next and previous full five minutes respectively by defining a function to ensure that all timestamps fall within a unified five-minute interval. In addition, in order to process large data sets, the code also divides the data into multiple blocks, each containing 500,000 rows of data, so that data can be processed efficiently in memory. And according to the minimum and maximum time of the data, a time range of five-minute intervals from the start time to the end time is generated, and each five-minute interval is traversed to extract the data subset within the time period. By calculating the total number of vehicles, the number of large vehicles, the total traffic volume, the proportion of large vehicles, the average speed and the traffic saturation for each five-minute interval of the dynamic data subset, a complete time feature data set is formed, and the time information is converted into a feature that can be effectively used by the model, thereby improving the prediction accuracy.
[0073] In step S12, data cleaning is performed. Since the data collected by the front-end monitoring equipment is missing or has 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 in time. This function merges the closest time records according to the time sequence. The results_df is merged with the vehicle speed data, the number of over-temperature vehicles data, and the number of dangerous goods vehicles data respectively to ensure that each row of data contains all relevant information, and finally the calculation results of all blocks are merged. Since the tunnel is predicted in sections in this embodiment, each row of merged data merged_df is used and expanded into multiple rows, so that each row contains the static data of a tunnel section, which is achieved by looping through each row of data and combining it with the static data of the tunnel. Thus, through the above operations, data sets from different sources are merged to ensure data consistency, 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 realize loading the main traffic data and security level information from the Excel file. First, the security 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 security 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 where 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. The time period and segment information are extracted by iterating each traffic record, and 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, and the main traffic data and security level information are loaded from the Excel file, which effectively integrates the security information into the traffic data, ensuring that each traffic record can obtain corresponding and accurate security level information according to the time and segment.
[0076] Since the number of traffic event data samples is extremely unbalanced, this embodiment also includes balancing the data and 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. 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 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] Next, 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 to adjust parameters and evaluate model performance, and the test set is used to evaluate and test the final model. The data is normalized and converted to 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 the above models are trained using different hyperparameters respectively, and 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 a feature. In addition to the above-mentioned traffic data and tunnel static data, the 13 neurons also have the start time and end time every five minutes. The start time is divided into start hours and start minutes, and the end time is divided into end hours and end minutes. 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] In order to prevent overfitting, the Dropout layer is introduced to reduce excessive dependence on training data by randomly discarding a part of neurons in the network. The model training uses the cross entropy loss function (Formula 3) to optimize the prediction accuracy of the model.
[0086]
[0087] Where 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 model i for category k. The Adam optimizer is also used in the training process, combining the momentum method and adaptive learning rate to calculate the momentum estimate of the gradient and the weighted moving average of the squared gradient (Equation 4 and Equation 5), which are updated by the momentum decay rate (0.9) and the mean decay rate (0.999), respectively. Bias correction is performed to calculate unbiased estimates. The model parameters are updated according to the learning rate (0.001) and the corrected momentum and squared gradient average. The Adam optimizer ensures the stability and efficiency of parameter updates by adaptively adjusting the learning rate in each training step.
[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] In order to improve the generalization ability of the model and avoid overfitting, the K-fold cross-validation method is used in the training process. In this embodiment, the K value of 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 training sets. Repeat K times so that each subset is verified. At the same time, the Adam optimizer is combined for parameter optimization. By continuously iterating the above steps, the model gradually optimizes the parameters, so that the loss function converges and the prediction accuracy is improved.
[0091] like Figure 3 As shown, Figure 3 The LSTM neural network model flow chart provided for the present embodiment, in which the LSTM model is used to process multidimensional sequence data including time features, traffic data, tunnel static data and historical statistical data to predict the target variable of "safety level". The input features include time features such as "start hour", "start minute", "end hour", "end minute", and indicators related to traffic conditions such as "traffic volume", "large vehicle proportion", "traffic saturation", "average speed", "number of overheated vehicles", "number of hazardous chemicals vehicles", "maximum longitudinal slope of 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, so as to effectively predict 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 feature, 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, in order to prevent overfitting, the Dropout layer is used in the LSTM model, and the dropout rate is set to 0.5. In the forward propagation process of 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 which 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 standardized. Then, the data is converted to PyTorch tensors and reshaped to fit the LSTM model. During training, the cross entropy loss function is used to calculate the difference between the predicted value and the actual label, and the model parameters are updated through the back-propagation algorithm. To further optimize the training process, the Adam optimizer is used in combination with weight decay to prevent overfitting. In each training cycle (epoch), the model traverses the training set, gradually adjusts the parameters, and uses the validation set to evaluate the model performance after each round, recording the best model parameters. After training, the model is loaded with the optimal parameters to ensure that it achieves the best 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 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 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 tIt is used to control the update degree of the current hidden state, and the calculation is as shown in Equation 12. Reset gate r t It is used to determine how much of the previous state is forgotten, and is calculated as 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 resized to 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, and 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 with replacement of the training data set, and a portion of features are randomly selected at each node to find the optimal split 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), where the more decision trees there are, the more stable the performance of the model is usually. During the training process, the model selects the optimal split point according to 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 the random forest, Ti(x) is the predicted category of the i-th tree for the input sample, and mode means taking the majority.
[0106] like Figure 5 As shown, Figure 5 The gradient boosting decision tree model flow chart provided for this embodiment 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] where 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 embodiment, each model is trained using different hyperparameters, each model is trained batch by batch through the data loader, and the performance is evaluated using the validation set, ensuring that the model has high prediction accuracy, can capture different features and patterns in traffic data, and improve the accuracy and reliability of prediction. In addition, time series models such as LSTM and GRU can effectively process and capture the time series dependencies in time series data, and have more accurate prediction capabilities for the occurrence of traffic events.
[0110] Preferably, if Figure 6 As shown, Figure 6 The model fusion flow chart provided for this embodiment, in step S3, the prediction probabilities of the above five models are used as feature inputs, and a stacking model is constructed for final prediction. After the training is completed, the prediction results of the stacking model are evaluated by 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: [0.1, 0.7, 0.2], the predicted probability of test sample 2: [0.3, 0.4, 0.3], and the predicted probability of test sample 3: [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 be used as input to the stacking model. The feature matrix is a two-dimensional array, in which each row is a 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 sample j belongs to category k for model i.
[0116] In step S322, for sample j, the prediction probability matrix P of each model i is i Concatenate 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 is 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 predicted probability concatenation feature of sample j on 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 the 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 bias terms 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 weights W and bias b of the logistic regression model. The training process minimizes the loss function through an optimization algorithm to improve classification accuracy.
[0127] Preferably, after training is completed, the logistic regression model is evaluated using a validation set or a test set to determine its performance, including indicators 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 basic models to obtain the predicted probability, and splice it into a feature matrix, apply the logistic regression model, and input these features into the trained logistic regression model to obtain the final prediction results.
[0128] Preferably, in this embodiment, the trained BP, LSTM, GRU, random forest, GBDT models and integrated stacking models are deployed to the production environment through the cloud service platform, and the processed data is input into the deployed model for real-time prediction. The stacking model will generate a prediction result based on the latest traffic data, that is, the possibility of a traffic incident.
[0129] Preferably, a user-friendly interface is constructed to display the possibility of traffic incidents in each segmented tunnel in real time, and to display them in different colors (normal situation (0) is indicated by green, abnormal parking situation in the tunnel (1) is indicated by yellow, and traffic incidents 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 embodiment takes a single tunnel of a highway as an example, collects the traffic data of the tunnel within one year, the tunnel design data and the regular inspection data, and the tunnel is equipped with a traffic event monitoring system, a high-definition camera, a radar vision integrated machine, and an infrared thermal imaging camera. Combined with the ETC card port data in front of the tunnel entrance, various types of traffic raw data in the tunnel are obtained. From the multi-source heterogeneous data, the data within five minutes are sorted and selected as a sample. The various types of data are combined by time feature extraction, and the hour and minute information is extracted from the timestamp of the original data to create a time feature. The 5-minute traffic parameters are used as the time feature, and the data is read, the time format is converted to the datetime format, the time alignment function is defined, the data is processed in blocks, the data is processed in blocks, and the data is merged. Traverse each five-minute interval and extract the data subset within the time period. For each dynamic data subset of the five-minute interval, 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. Since the data collected by the front-end monitoring equipment is missing or outliers in some time periods, it is necessary to eliminate some invalid data. Import data from the data source and identify and handle missing values, outliers, and duplicate values. Then, convert data types, standardize or normalize data, unify formats, clean text data, perform spelling checks, and perform feature engineering. Use the merge_asof function to align different data sets by time. Merge results_df with speed data, overheated vehicle number data, and hazardous goods vehicle number data to ensure that each row of data contains all relevant information. Finally, merge the calculation results of all blocks.
[0132] Since the tunnel is divided into five sections, the number of accidents per million kilometers x7, the maximum longitudinal slope of the tunnel x8, and the road condition index x9 of each section are different. The rest of the data are the same. Therefore, one sample needs to be expanded into five samples according to the different sections, as shown in Table 1. The traffic events, event sections, and event time statistics in the tunnel are exported from the traffic event monitoring system. The safety level is divided into three categories: 0, 1, and 2, corresponding to normal conditions, abnormal parking conditions, and traffic events in the tunnel. Each piece of data of the exported tunnel traffic event includes the time of occurrence, event type, and event section. By iterating each traffic record, extracting the time period and section information, and matching the records of the corresponding time range and section in the safety level data. If a match is found, the corresponding safety level is updated to the copy data frame. Finally, the integrated data frame is exported to ensure that each record is accompanied by accurate safety level information. Through the above process, a data set with a data quantity of 527076 is obtained. The category distribution of the original data set: [0: 527039 1: 26 2: 10].
[0133]
[0134]
[0135] Table 1
[0136] Preferably, since the number of traffic event data samples is extremely unbalanced, it is also necessary to comb the data set for sample balance. This method uses the SMOTE oversampling and downsampling method to oversample and downsample the traffic event data and non-traffic event data respectively. The traffic event data and the breakdown parking data are oversampled to 40,000 data, and the category distribution of the oversampled data set is: [0: 527039 1: 40000 2: 40000]. The remaining data is then downsampled to 40,000, and the category distribution of the downsampled data set 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 back propagation. 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 one LSTM layer and one fully connected layer. The LSTM layer has 50 hidden units and 2 layers, processing the input data sequence to capture the time series characteristics. 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 the training process, CrossEntropyLoss is used to calculate the loss and optimize the network parameters through back propagation. 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 evaluation of 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 the learning rate set to 0.0001 and the weight decay to 1e-4. During the training process, the loss is calculated using CrossEntropyLoss, and the parameters are optimized by back propagation. The model is trained on the training set and the 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 predictions 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 the random forest model, the design includes building a forest of multiple decision trees, each of which randomly selects features and samples during training to enhance the diversity and robustness of the model. The model is first trained on a balanced data set that has been processed with SMOTE and downsampling, and the classification accuracy is improved by integrating the prediction results of multiple decision trees. The model is trained on the training set and the fit method is used to learn the patterns in the data. In this embodiment, the accuracy of the random forest model on the test set is 0.9995.
[0151] In the gradient boosting decision tree model, its design is to iteratively construct a series of weak learners - decision trees, and each tree improves the model performance by gradually correcting the error of the previous tree. The training process starts with the initial model, calculates the residuals of each sample, and then trains a new decision tree on the residuals to minimize these residuals. This process is implemented by the ˋfitˋ method, passing 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 the training is completed, the model is evaluated on the test set to calculate its prediction accuracy. In this embodiment, the accuracy of the gradient boosting decision tree model on the test set is 0.9846. Preferably, in this embodiment, the fusion of the above models is also included to obtain the final stacking model. The stacking model uses a variety of basic classifiers, including BP neural network, LSTM model, GRU model, random forest classifier and gradient boosting classifier. The prediction results of each basic model on the training set and test set are used as new features to create a new data set. This data set contains the predicted values of all basic models for each sample, which is called "first layer prediction". Use the first layer predicted data set as input to train a new model, namely the "stacked model". Apply the stacked model to the test data set to obtain the final prediction results. In this embodiment, the results of the stacked model on the test set are: accuracy: 0.9998; average precision: 0.9998; average recall: 0.9998; average F1 score: 0.9998. The stacked model combines the advantages of multiple basic models, optimizes the prediction effect, and improves the overall performance of the model.
[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 the subsequent fusion of each model also has high prediction accuracy and reliability for the real-time prediction of highway tunnel traffic events.
[0153]
[0154] Table 5
[0155] Further preferably, real-time prediction and display are also included in this embodiment. The front-end equipment collects real-time data of traffic volume x1, traffic saturation x2, proportion of large vehicles x3, average vehicle speed x4, hazardous chemicals 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 displays.
[0156] Obviously, the above embodiments of the present invention are merely examples for clearly illustrating the technical solution 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 in the protection scope 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 them. Then divide the processed data into training set, validation set and test set according to a specific ratio, and normalize the training set 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 stacked ensemble learning strategy, and the prediction probability of each model is used as a feature input, which is input into the stacked model for prediction 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 make predictions for 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 stacked 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 , among the 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 sample j belongs to category k for model i; S322: For sample j, the prediction probability matrix P of each model i is i Concatenate 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 concatenation. 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 collection 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 the 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 the S11, the extracting of the 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 the code to facilitate efficient data processing; S114: Generate a time range of five-minute intervals from the start time to the end time according to the minimum and maximum time of the data, and traverse each five-minute interval to extract a 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 volume, the proportion of large vehicles, the average vehicle speed and the traffic saturation are calculated, thereby forming a complete time characteristic 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 dangerous 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: The step S14 includes: firstly, dividing the security level into three categories, then creating a copy data frame and initializing a new column, iterating each traffic record, extracting the time period and section information, matching the records of the corresponding time range and section 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.
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: The 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 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 the formula is: x i =x i +λ·(x nn -x i ) Among them, x i is a minority sample, x nm is a random sample from 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 method for real-time prediction of 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
Real-Time Predictive Maintenance of Hardware Components Using a Stacked Deep Learning Architecture on Time-Variant Parameters Combined with a Dense Neural Network Supplied with Exogeneous Static Outputs
US20200380336A1
Cited By
Vehicle speed prediction method and device, computer equipment, storage medium and program product
CN117272105A
Vehicle speed prediction methods, devices, computer equipment, storage media and software products
CN117272105B
A method to improve event detection accuracy based on multi-model fusion
CN119785162A
Storage node load balancing method and device, equipment and storage medium
CN120390014A
Monitoring management method and system for smart tunnel based on Internet of Things
CN120499209A