Prediction method and system for road traffic flow
By adopting a prediction method with a hierarchical GRU structure, integrating multi-source data and providing a two-stage training strategy, the shortcomings of existing traffic flow prediction methods in complex traffic environments are solved, and efficient and accurate traffic flow prediction and intelligent regulation suggestions are achieved.
Patent Information
- Application Number
- CN202411473918.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-22
- Publication Date
- 2025-03-04
AI Technical Summary
The existing traffic flow prediction methods have problems such as insufficient data diversity, limited model complexity and lack of intelligent suggestions when dealing with complex and dynamic traffic environments.
The prediction method of hierarchical GRU structure is adopted, and the model is trained through two-stage training strategies, integrating real-time traffic flow, geological information and meteorological data, and providing intelligent flow regulation suggestions.
It improves the timeliness and accuracy of traffic flow prediction, improves the prediction performance of the model in different traffic situations, and provides real-time traffic regulation suggestions to reduce congestion risk.
Smart Images

Figure CN119559781A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of intelligent transportation technology, and in particular to a method and system for predicting highway traffic flow. Background Art
[0002] In modern traffic management, accurate prediction of highway traffic flow plays an important role in improving traffic efficiency, optimizing road planning, and reducing accident risks. Traditional traffic flow prediction methods mainly rely on historical data and statistical models, such as linear regression and time series analysis. However, these methods have significant shortcomings when dealing with complex and dynamic traffic environments:
[0003] Insufficient data diversity: Traditional models mostly rely only on historical traffic flow data and fail to fully integrate real-time geological, meteorological and other multi-source data. This results in the model being unable to reflect the dynamic changes in traffic conditions in a timely manner, limiting the accuracy of predictions.
[0004] Limited model complexity: Existing methods mostly use simple linear models, which are difficult to effectively capture the nonlinear characteristics and long-term dependencies of traffic flow. Therefore, when faced with traffic surges or emergencies during peak hours, the model's predictive ability is significantly reduced.
[0005] Lack of intelligent suggestions: Traditional systems find it difficult to provide intelligent traffic control suggestions based on predictions, resulting in delayed decision-making and high adjustment costs for traffic management departments when faced with emergencies.
[0006] The information disclosed in this background technology section is only intended to deepen the understanding of the overall background technology of the present invention, and should not be regarded as acknowledging or suggesting in any form that the information constitutes the prior art already known to those skilled in the art. Summary of the invention
[0007] The purpose of the present invention is to provide a highway traffic flow prediction method and system thereof to solve the technical problems existing in the prior art.
[0008] In order to achieve the above object, the present invention adopts the following technical solutions:
[0009] In a first aspect, the present invention provides a method for predicting highway traffic flow, comprising:
[0010] Data collection: Collect public traffic flow data sets, national highway traffic flow data sets, and geological and meteorological information data sets;
[0011] Data preprocessing: preprocess the collected data;
[0012] Model training: A hierarchical GRU structure is adopted, and the model structure includes detailed configurations of the input layer, encoding layer, attention mechanism, and output layer. The model adopts a two-stage training strategy, and the model training is divided into a pre-training stage and a scene-specific training stage. The pre-training stage uses a large-scale public traffic flow data set for pre-training, so that the model can learn the basic traffic flow change pattern; the scene-specific training stage uses the scene data to fine-tune the model and adjust the model parameters.
[0013] Model evaluation: A variety of evaluation criteria are used to measure the performance of the model in the traffic flow prediction task. Specific evaluation indicators and standards include: mean absolute error, mean square error, mean square logarithmic error, and determination coefficient.
[0014] Preferably, in the step of data collection, the traffic flow data set includes: hourly flow data, recording timestamp, vehicle type, vehicle speed and flow; the geological information includes: geological type of the road section, soil moisture and geological disaster risk assessment; the meteorological information: recording temperature, precipitation, wind speed meteorological parameters.
[0015] Preferably, in the step of data preprocessing, the steps of data preprocessing include: missing value filling, outlier processing and data standardization processing.
[0016] Preferably, in the step model training, a hierarchical GRU structure is used to solve the complex time series data processing problem in highway traffic flow prediction, wherein the input layer uses a convolutional layer for preliminary feature extraction, the encoding layer uses a hierarchical GRU for time series feature modeling, the attention mechanism increases the focus on important features, and the output layer performs traffic prediction.
[0017] Preferably, in the step model training, the training steps include:
[0018] Data preparation: Divide the dataset into training set, validation set, and test set, and design specific ratios;
[0019] If pre-training is performed, a large-scale public traffic flow dataset is used for initialization so that the model can learn the basic traffic flow change pattern. The optimization process uses MSLE as the loss function and the Adam optimization algorithm. The training iteration is performed for multiple rounds until the validation set loss no longer decreases significantly.
[0020] If scenario-specific training is performed, the data in the scenario is used for retraining to further adjust the model parameters. The optimization process uses MSLE as the loss function and the Adam optimization algorithm. The training iteration is performed for multiple rounds until the validation set loss no longer decreases significantly.
[0021] Training evaluation: Evaluate model performance through cross-validation, use early stopping strategy, save the model parameters with the best performance indicators as the final model, and the training ends.
[0022] In a second aspect, the present invention provides a highway traffic flow prediction module, which adopts the highway traffic flow prediction method, including: a data collection module, a data preprocessing module, a model training module, and a model evaluation module; the data collection module is used to collect public traffic flow data sets, national highway traffic flow data sets, and geological information and meteorological information data sets; the data preprocessing module is used to preprocess the collected data; the model training module adopts a hierarchical GRU structure and a two-stage training strategy, and the model training is divided into a pre-training stage and a scenario-specific training stage; the model evaluation module adopts multiple evaluation criteria to measure the performance of the model in the traffic flow prediction task.
[0023] By adopting the above technical solution, the present invention has the following beneficial effects:
[0024] (1) Multi-source data integration and analysis: The present invention integrates real-time traffic flow, geological information and meteorological data to achieve comprehensive analysis of multi-source data, thereby improving the timeliness and accuracy of traffic forecasting.
[0025] (2) Application of hierarchical GRU model: By introducing the hierarchical GRU model, the present invention can effectively capture the temporal characteristics and complex nonlinear relationships of traffic flow data, and improve the prediction performance of the model in different traffic scenarios.
[0026] (3) Intelligent traffic control suggestions: Based on the predicted traffic flow, the present invention can provide real-time traffic control suggestions to help traffic management departments respond quickly and optimize resource allocation, thereby reducing congestion risks.
[0027] (4) Efficient real-time prediction capability: With the help of the powerful computing power of the deep learning model, the present invention supports real-time traffic flow prediction and dynamic adjustment, significantly improving the flexibility and response speed of the traffic management system. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0029] Figure 1 The overall architecture diagram of the highway traffic flow prediction method provided by the embodiment of the present invention;
[0030] Figure 2 A structural diagram of a hierarchical GRU model provided by an embodiment of the present invention;
[0031] Figure 3 A flow chart of model training provided in an embodiment of the present invention. DETAILED DESCRIPTION
[0032] The technical solution of the present invention will be described clearly and completely below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0033] The specific implementation of the present invention is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described here is only used to illustrate and explain the present invention, and is not used to limit the present invention.
[0034] Embodiment 1
[0035] Combination Figures 1 to 3 As shown, this embodiment 1 provides a method for predicting highway traffic flow, which includes:
[0036] Data collection: Collect public traffic flow data sets, national highway traffic flow data sets, and geological and meteorological information data sets;
[0037] Data preprocessing: preprocess the collected data;
[0038] Model training: A hierarchical GRU structure is adopted, and the model structure includes detailed configurations of the input layer, encoding layer, attention mechanism, and output layer. The model adopts a two-stage training strategy, and the model training is divided into a pre-training stage and a scene-specific training stage. The pre-training stage uses a large-scale public traffic flow data set for pre-training, so that the model can learn the basic traffic flow change pattern; the scene-specific training stage uses the scene data to fine-tune the model and adjust the model parameters.
[0039] Model evaluation: A variety of evaluation criteria are used to measure the performance of the model in the traffic flow prediction task. Specific evaluation indicators and standards include: mean absolute error, mean square error, mean square logarithmic error, and determination coefficient.
[0040] In this embodiment, preferably, the data collection uses a public traffic flow data set, a national highway traffic flow data set, and a geological and meteorological information data set. The specific data includes:
[0041] Among them, traffic flow data: contains hourly traffic data, recording timestamps, vehicle types, speeds and flow rates.
[0042] Among them, geological information includes: geological type of the road section, soil moisture and geological disaster risk assessment.
[0043] Among them, meteorological information: records meteorological parameters such as temperature, precipitation, and wind speed.
[0044] The data is stored in CSV format, and the data sample is as follows:
[0045]
[0046] In this embodiment, preferably, data preprocessing is a key link to ensure the quality of model input data. It can ensure the integrity and consistency of the data, so that the model can learn the inherent laws of the data under consistent input conditions, thereby making full use of data features and improving the generalization ability and prediction performance of the model. The steps of data preprocessing are as follows:
[0047] 1. Missing value filling: Use the missing value filling method based on the K-Nearest Neighbors (KNN) algorithm. This method finds the K nearest data points and uses their average value to fill the missing values. The algorithm steps are as follows:
[0048] Compute the Euclidean distance between each data point and every other point in the dataset.
[0049] Select the K nearest neighbor data points.
[0050] Calculate the average of these neighboring data points as the filling value for the missing values.
[0051] The formula is:
[0052]
[0053] in, is the value after filling, is the value of the neighbor data point, is the number of neighbor data points
[0054] 2. Outlier processing: Use the interquartile range (IQR) method to detect and remove outliers. First, calculate the first quartile of the data ( ) and the third quartile ( ), outliers are defined as values below ( - 1.5 ) or higher than ( +1.5 ) value, the formula is as follows:
[0055]
[0056] - 1.5
[0057] + 1.5
[0058] 3. Data standardization: Standardize the data to a range with a mean of 0 and a variance of 1. The formula is as follows:
[0059]
[0060] in, is the standardized data, is the mean, This step can eliminate the impact of dimension and improve the training efficiency of the model.
[0061] In this embodiment, preferably, a hierarchical GRU structure is used to solve the problem of complex time series data processing in highway traffic flow prediction. This structure introduces multi-level GRU units to more effectively capture and model the spatiotemporal characteristics of traffic flow data, thereby providing more accurate results for traffic flow prediction. The model includes the following modules:
[0062] 1. Input layer: The main function of the input layer is to perform preliminary feature extraction and dimensionality reduction processing on traffic flow data. The present invention uses a one-dimensional convolutional layer (1D Convolutional Layer) in the input layer to extract local features of sequence data and improve the model's ability to understand input data. The convolutional layer can capture dependencies in time series, laying the foundation for subsequent GRU unit understanding and modeling of temporal relationships. These functions together improve the model's ability to predict changes in traffic flow. The following is a detailed introduction to the convolutional layer parameters, including the meaning and selection criteria of each parameter:
[0063] Kernel Size:
[0064] The kernel size determines the length of the sliding window, which is the number of time steps observed each time a convolution operation is performed on the input data. Smaller kernels can capture fine local features, while larger kernels help extract patterns over longer time spans. For traffic flow data, a kernel of 3 time steps can effectively capture changes and trends between adjacent moments.
[0065] Number of convolution kernels (Number of Filters):
[0066] The number of convolution kernels determines the number of output channels of the convolution layer. Each convolution kernel can extract different types of features. Increasing the number of convolution kernels helps to enhance the ability to express features. This model selects 64 convolution kernels, which can capture rich features without causing excessive computation and affecting model efficiency.
[0067] Activation Function:
[0068] Activation functions are used to introduce nonlinear characteristics, enabling the model to learn complex patterns. ReLU (Rectified Linear Unit) is a commonly used activation function in convolutional layers. It can effectively accelerate training convergence, solve the gradient vanishing problem, and is computationally simple.
[0069] Stride:
[0070] The stride determines the step size of the convolution kernel sliding on the input data. The larger the stride, the smaller the size of the output feature map. The stride is set to 1 to ensure that the convolution operation is calculated for every time step of the input data, without missing important features.
[0071] Convolution calculation: Convolution calculation is an important part of the traffic flow prediction model. It can effectively capture local patterns and features in traffic flow data, such as the trend and periodicity of traffic flow changes, by using a sliding window to perform local perception and feature extraction on the input data. It not only helps to extract key information from the data, but also reduces data redundancy and computational complexity through dimensionality reduction, thereby improving the training speed and efficiency of the model. The convolution calculation formula is as follows:
[0072]
[0073] in, is the convolution output, is the convolution kernel parameter, is the input sequence, is the bias term.
[0074] 2. Encoding layer: In the Hierarchical GRU model, the encoding layer is mainly responsible for processing the features extracted by the convolutional layer to capture the temporal characteristics and hierarchical structure of traffic flow data. The encoding layer consists of multiple layers of GRU units, and its structure and formula are as follows:
[0075] In GRU (Gated Recurrent Unit), reset gate, update gate, candidate hidden state and hidden state update are key components that work together to manage and optimize the flow of information in a sequence. GRU units use update gates and reset gates to control the flow of information and avoid the gradient vanishing problem. The core formula of GRU is as follows:
[0076] Update Gate:
[0077] The update gate is responsible for deciding how to update the hidden state during the current time step. This includes determining how much new information should be introduced and how much old information should be retained.
[0078] The update gate is the most important gating mechanism in GRU because it plays a crucial role in ensuring the memory of long-term dependencies. By balancing the fusion of new and old information, the update gate helps the network respond to new data while remembering the past, thereby improving the accuracy and stability of predictions.
[0079]
[0080] : Update gate vector, used to decide how much information in the current state comes from the past state.
[0081] : sigmoid activation function, compressing the input to between 0 and 1.
[0082] , : Update the gate weight matrix.
[0083] : Current input vector.
[0084] : The hidden state at the previous moment.
[0085] : Update gate bias vector.
[0086] Reset Gate:
[0087] The reset gate controls the influence of the previous time step hidden state on the candidate hidden state of the current time step. Specifically, it determines how much historical information needs to be forgotten.
[0088] By adjusting the degree of information forgetting, the reset gate allows the network to ignore irrelevant historical information, which is especially useful when dealing with long-term dependencies. For example, when processing text data, some contextual information may become irrelevant after a long distance, and the reset gate can selectively reset this influence.
[0089]
[0090] : Reset gate vector, used to decide how much information from the previous state to ignore.
[0091] , : Reset the gate weight matrix.
[0092] : Reset the bias vector of the gate.
[0093] Candidate Activation State:
[0094] A candidate hidden state is a temporary state after processing the current input and information from the previous time step. It is prepared as a possible next hidden state before applying the update gate.
[0095] The candidate hidden state is a potential response to the current input, which plays an intermediary role in integrating the current input and historical information. By introducing nonlinear activation at this layer, GRU can effectively capture complex temporal patterns.
[0096]
[0097] : Candidate activation state, indicating the candidate value of the hidden state at the current moment.
[0098] : Hyperbolic tangent activation function.
[0099] , : Weight matrix for candidate activations.
[0100] : Bias vector for candidate activations.
[0101] : Element-wise product.
[0102] Hidden State Update:
[0103] The hidden state update is the result of the computation of the final hidden state, which combines the output of the update gate and the candidate hidden state.
[0104] This process is the core step of GRU, which provides a balance mechanism that flexibly adapts to changes in new inputs while maintaining important historical information. By applying the update gate to the candidate hidden state and the previous hidden state, GRU can remember long-term information while maintaining sensitivity to new patterns.
[0105]
[0106] : The hidden state at the current moment.
[0107] This formula means that the current hidden state is a weighted sum of the past hidden states and the candidate activation states.
[0108] The coding layer parameters and selection criteria are as follows:
[0109] Number of Layers:
[0110] This model uses a 3-layer GRU unit. The multi-layer structure can better capture the temporal features of different levels and improve the expressiveness of the model.
[0111] Number of Hidden Units:
[0112] Each layer of GRU contains 128 hidden units. When processing complex traffic flow data, 128 hidden units can provide sufficient model capacity to capture the nonlinear characteristics in the data while maintaining the training efficiency of the model.
[0113] Activation function:
[0114] GRU uses sigmoid and tanh functions internally. Sigmoid is used for gating operations to compress the input between 0 and 1 to control the flow of information; tanh is used for state updates to ensure that the hidden state value is between -1 and 1, which helps stabilize the training process.
[0115] Learning Rate:
[0116] The learning rate is set to 0.001. A learning rate of 0.001 can provide a balanced update step size during training and prevent the model parameters from converging too fast or too slow.
[0117] Batch Size:
[0118] The batch size is set to 32. A batch size of 32 can provide good memory usage efficiency and stability of parameter updates during training.
[0119] 3. Attention Mechanism:
[0120] The model introduces an attention mechanism at the encoding layer, which enhances the model's predictive ability by selectively focusing on key information in the input sequence.
[0121] The core idea of the attention mechanism is to determine the importance of each element in the input sequence by calculating the similarity between the query vector and the key vector. Then, these importances are used as weights and applied to the value vector to generate the final output.
[0122] Query vector: A vector input to the model for selecting information from the input sequence and used to calculate attention.
[0123] Key vector: represents the features of each element in the input sequence, which is used to calculate the similarity with the query vector to determine the attention weight.
[0124] Value vector: represents the information contained in each element in the input sequence. The input information corresponding to the key vector is weighted and summed to generate the output.
[0125] Similarity calculation
[0126] Similarity calculation usually uses dot product or other functions to measure the similarity between the query vector and the key vector. The formula is as follows:
[0127]
[0128] : query vector
[0129] : key vector
[0130] : Indicates the similarity between the query and the key
[0131] Normalization
[0132] The similarity scores are normalized, usually using a softmax function, to ensure that the sum of all scores is 1. This can be converted into weights as follows:
[0133]
[0134] : The attention weight of the iiith element in the input sequence
[0135] : The length of the input sequence
[0136] Weighted Sum
[0137] The value vector is weighted summed using the attention weight to generate the context vector c, as follows:
[0138]
[0139] : context vector
[0140] : The value vector of the i-th element in the input sequence
[0141] 4. Output layer:
[0142] The main function of the output layer is to convert the feature vector processed by the encoder and the attention mechanism into the final result of traffic flow prediction. The output layer consists of a fully connected layer and an activation function, which converts the hidden state of the model into a specific prediction output.
[0143] 1). Fully connected layer
[0144] The fully connected layer is a linear transformation layer that maps the input feature vector to the output space. It consists of a weight matrix and a bias vector, which is used to linearly combine the input features. The formula is as follows;
[0145]
[0146] : Output vector, which is the output of the fully connected layer and the final prediction value of the model, indicating the traffic flow prediction result.
[0147] : Weight matrix, where noutn_{\text{out}}nout is the number of units in the output layer, and nhiddenn_{\text{hidden}}nhidden is the length of the hidden state vector. Each element wijw_{ij}wij is a learning parameter, indicating the degree of influence of the jjjth dimension of the hidden state on the output iiith unit.
[0148] : The hidden state vector, which comes from the features processed by the encoding layer and the attention mechanism. It contains the high-level features extracted by the model from the input to generate the final output.
[0149] : Bias vector, used to adjust the activation threshold of each output unit. The bias vector enables the model to produce reasonable output when there is no input and helps the model adapt to more diverse input patterns.
[0150] 2). Activation function
[0151] In the output layer, a linear activation function is selected for traffic flow prediction. The linear activation function is suitable for regression tasks such as traffic flow prediction because it allows the output prediction results to expand in an infinite range without being restricted to a fixed range. This is very important for capturing the fluctuations and changes in actual traffic flow.
[0152]
[0153] In the formula, the output (i.e., the predicted value) is directly the linear combination of the weights and the input vector, without any nonlinear transformation. This direct linear relationship enables the model to effectively reflect the proportional relationship between the input features and the output in numerical predictions (such as continuous changes in traffic flow). By selecting a linear activation function, the output layer can accurately predict continuous traffic flow values, adapt to changes under different traffic conditions, and provide a reliable basis for traffic management decisions.
[0154] In this embodiment, preferably, the model training adopts a two-stage training strategy, and the model training is divided into two stages: pre-training and training, each with different functions and goals to improve the performance and prediction ability of the model.
[0155] 1. Pre-training:
[0156] The main purpose of the pre-training phase is to provide a good initialization starting point for the model. By training on a large-scale public traffic flow dataset, the model can learn common traffic patterns and characteristics, thereby enhancing its ability to adapt to new data. Pre-training helps capture common features in different traffic scenarios, improve the generalization ability of the model in different scenarios, and reduce the convergence time when training in specific scenarios. This stage of training makes the model more robust and can run effectively on a wider data distribution, avoiding overfitting.
[0157] The training phase focuses on fine-tuning the parameters of the pre-trained model to achieve optimal performance in a specific application scenario. In this phase, the model is retrained using data from specific cases to further adjust and optimize the model parameters to adapt to specific traffic conditions and changes. The goal of the training phase is to improve the accuracy and stability of the model in specific traffic flow prediction tasks, so that it can more accurately reflect local traffic conditions and provide reliable support for traffic management and decision-making. By combining these two phases, the model can achieve higher prediction accuracy and robustness.
[0158] 2. Loss function selection
[0159] Select Mean Squared Logarithmic Error (MSLE):
[0160] The mean square logarithmic error (MSLE) is suitable for data in traffic flow prediction because it is more sensitive to proportional errors and can effectively handle nonlinear relationships in traffic changes. The formula is as follows:
[0161]
[0162] in:
[0163] : Sample size.
[0164] : Actual value.
[0165] : predicted value.
[0166] : Perform a smooth logarithmic transformation on the actual and predicted values to avoid excessive errors.
[0167] MSLE can suppress the impact of outliers in the prediction, making the model more sensitive to prediction errors in a small range and suitable for capturing subtle changes in traffic flow.
[0168] 3. Training steps
[0169] (1) Data preparation: The dataset is divided into training set, validation set, and test set in a ratio of 7:2:1. In the pre-training phase, public datasets are used for feature learning.
[0170] (2) Pre-training stage:
[0171] Initialization: Use a large-scale public traffic flow dataset for pre-training to enable the model to learn the basic traffic flow change pattern.
[0172] Optimization process: MSLE is used as the loss function, the Adam optimization algorithm is adopted, and the learning rate is set to 0.001.
[0173] Training iterations: Perform multiple rounds of iterations until the validation set loss no longer decreases significantly to prevent overfitting.
[0174] (3) Scenario-specific training phase:
[0175] Fine-tune the model: Retrain the model in a specific case scenario using the data within the scenario to further adjust the model parameters to suit specific traffic conditions.
[0176] Adjustment steps:
[0177] The same loss function (MSLE) and optimization algorithm (Adam) are used to ensure consistency in training.
[0178] The training process is optimized by adjusting the learning rate and batch size (e.g. 64).
[0179] (4) Training evaluation:
[0180] Cross Validation:
[0181] During the training process, the model performance is evaluated through cross-validation technology. Cross-validation is a technology for evaluating model performance, which is mainly used to prevent the model from overfitting on a specific training set, thereby improving the model's generalization ability on unseen data.
[0182] Cross validation steps:
[0183] Data partitioning: Divide the dataset into K subsets (folds) of equal size, and select K=5 in the model.
[0184] Training and validation:
[0185] In each iteration, one of the subsets is used as the validation set and the remaining K-1 subsets are used as the training set.
[0186] Repeat K times so that each subset serves as a validation set.
[0187] Performance evaluation:
[0188] At each iteration, the performance metric (such as loss or accuracy) of the model on the validation set is calculated.
[0189] Record the performance metrics of each iteration and calculate the average of all K times.
[0190] Result analysis:
[0191] By analyzing the average performance indicators of K validations, the generalization ability and stability of the model can be judged.
[0192] The results of cross-validation provide an assessment of the consistency and robustness of the model on different data distributions.
[0193] Early stopping strategy:
[0194] Early stopping is a regularization technique used to prevent overfitting during model training. By monitoring the performance of the model on the validation set, training is stopped when the validation set loss no longer decreases significantly to avoid overfitting.
[0195] Early stopping strategy steps:
[0196] Monitoring Metrics: Select validation set loss to monitor model performance.
[0197] To set tolerance:
[0198] A tolerance step (patience) is defined, that is, the number of consecutive iterations at which the performance index does not improve significantly. In the present invention, 5 epochs are selected.
[0199] Training process:
[0200] After each epoch, the performance indicators of the model on the validation set are evaluated.
[0201] If the performance indicator does not improve within the set tolerance step size, stop training.
[0202] Model saving:
[0203] The model parameters with the best performance index are saved as the final model.
[0204] In this embodiment, preferably, in order to ensure the prediction performance and reliability of the model, the system adopts a series of evaluation criteria to measure the performance of the model in the traffic flow prediction task. The specific evaluation indicators and criteria are as follows:
[0205] Evaluation Metrics
[0206] Mean Absolute Error (MAE)
[0207]
[0208] in:
[0209] : Sample size.
[0210] : Actual value.
[0211] : predicted value.
[0212] MAE is used to measure the average absolute error between the predicted value and the actual value, reflecting the average prediction deviation of the model. A smaller MAE indicates that the model has higher prediction accuracy.
[0213] Mean Squared Error (MSE)
[0214]
[0215] MSE is used to measure the average squared difference between the predicted value and the actual value. A smaller MSE indicates a smaller difference between the predicted value and the actual value. MSE is more sensitive to outliers.
[0216] Mean Squared Logarithmic Error (MSLE)
[0217]
[0218] MSLE is used to measure the proportional difference between the predicted value and the actual value, and is particularly suitable for traffic flow data with significant magnitude changes. It is more sensitive to smaller errors.
[0219] Coefficient of Determination (\(R^2\))
[0220]
[0221] in:
[0222] : The mean of the actual values.
[0223] It measures how well the model fits the data. The value range is from 0 to 1. The closer the value is to 1, the stronger the explanatory power of the model.
[0224] In summary, this embodiment has the following innovative features:
[0225] Multi-source data integration and deep fusion: In traffic flow prediction, the present invention achieves deep fusion of multi-source data by integrating traffic flow, geological information and meteorological data. By adopting a hierarchical GRU model, important features can be extracted from multidimensional data to improve the adaptability and accuracy of the prediction model. Compared with traditional prediction methods that only rely on historical traffic data, the present invention can more comprehensively capture the dynamic changes in traffic conditions.
[0226] Improved hierarchical GRU model: In existing traffic prediction methods, simple linear models or traditional machine learning methods are difficult to handle the complex time series characteristics of traffic flow. This paper introduces a hierarchical GRU model, which can effectively capture the nonlinear characteristics and long-term dependencies in traffic flow with its powerful time series data modeling capabilities. This structure significantly improves the model's prediction performance for complex traffic environments.
[0227] Efficient data preprocessing method: This paper adopts K-nearest neighbor algorithm to fill missing values and uses interquartile range method to remove outliers, which improves the accuracy and efficiency of data cleaning compared with traditional data preprocessing methods. This efficient data preprocessing process provides more reliable input data for model training, ensuring the accuracy and stability of prediction results.
[0228] Application of attention mechanism: The introduction of attention mechanism in the model structure further improves the ability to focus on key information. The attention mechanism can dynamically adjust the weight of each input feature, so that the model can more accurately focus on factors that have an important impact on the prediction, thereby improving the accuracy and robustness of the prediction.
[0229] Embodiment 2
[0230] This embodiment 2 provides a highway traffic flow prediction module based on the embodiment 1. This embodiment 2 includes the technical contents disclosed in the embodiment 1, and the technical contents of this embodiment 2 that are the same as those of the embodiment 1 are not repeated here. The differences between this embodiment 2 and the embodiment 1 are described below.
[0231] The present embodiment provides a highway traffic flow prediction module, which adopts the highway traffic flow prediction method, including: a data collection module, a data preprocessing module, a model training module, and a model evaluation module; the data collection module is used to collect public traffic flow data sets, national highway traffic flow data sets, and geological information and meteorological information data sets; the data preprocessing module is used to preprocess the collected data; the model training module adopts a hierarchical GRU structure and a two-stage training strategy, and the model training is divided into a pre-training stage and a scenario-specific training stage; the model evaluation module adopts multiple evaluation criteria to measure the performance of the model in the traffic flow prediction task.
[0232] Embodiment 3
[0233] The third embodiment is further refined and applied on the basis of the first embodiment. The third embodiment includes the technical contents disclosed in the first embodiment. The same technical contents as those in the first embodiment are not repeated here. The differences between the third embodiment and the first embodiment are described below.
[0234] For example, in order to verify the actual application effect of the highway traffic flow prediction method and system of the present invention, a busy ordinary highway is selected as the research object, and a prediction experiment of real traffic flow data is carried out. The experiment is intended to simulate the data processing and model application process in a real working environment and evaluate the prediction performance of the present invention in actual situations.
[0235] 1. Data Collection
[0236] In this example, the following data sources are used for model training and validation:
[0237] Traffic flow data: Obtain traffic flow data of the target highway from the national transportation department. The data set covers daily traffic information within one year. Specific data includes the number of vehicles passing per hour, vehicle speed (km / h), vehicle type, etc.
[0238] Geological information: Obtain geological data along the highway from the geological survey department, including soil moisture, geological type and potential geological disaster risks.
[0239] Meteorological information: Obtain relevant meteorological data from the meteorological department, including temperature (℃), precipitation (mm), wind speed (m / s) and other parameters.
[0240] The data is stored in CSV file format. The sample data is as follows:
[0241]
[0242] 2. Data Preprocessing
[0243] Data preprocessing is performed to improve the quality of model input data. The specific steps are as follows:
[0244] 2.1 Missing Value Filling
[0245] The K-nearest neighbor (KNN) algorithm is used to fill in the missing data:
[0246] Compute the Euclidean distance between each data point and every other point.
[0247] Select the K nearest adjacent data (K=5 in this embodiment).
[0248] The mean of these adjacent data is used to fill in the missing values.
[0249] The formula is:
[0250]
[0251] in, is the value after filling, is the value of the neighbor data point, is the number of neighbor data points
[0252] 2.2 Outlier Processing
[0253] Use the interquartile range (IQR) method to remove outliers:
[0254] Calculate the first quartile of the data ( ) and the third quartile ( ).
[0255] Outliers are defined as values less than - 1.5 or greater than + 1.5 The value of .
[0256] 2.3 Data Standardization
[0257] Standardize the data to make its mean 0 and variance 1 to improve the training efficiency of the model. The formula is:
[0258]
[0259] in, is the standardized data, is the mean, This step can eliminate the impact of dimension and improve the training efficiency of the model.
[0260] 3. Model Structure
[0261] 3.1 Input Layer
[0262] The input layer extracts local features of traffic flow data through a 1D convolutional layer.
[0263] Convolution kernel size: Select 3 time steps to capture changes in adjacent moments.
[0264] Number of convolution kernels: 64 convolution kernels to enhance feature expression capabilities.
[0265] Activation function: ReLU, providing non-linear characteristics.
[0266] 3.2 Coding Layer
[0267] A hierarchical GRU model is used to process the features extracted by the convolutional layer to capture the temporal characteristics of traffic flow data.
[0268] Update gate and reset gate control the flow of information and prevent gradient disappearance.
[0269] Candidate activation and hidden state updates combine historical information and new input.
[0270] Parameter selection:
[0271] Number of GRU layers: 3.
[0272] Number of hidden units: 128.
[0273] Learning rate: 0.001.
[0274] Batch size: 32.
[0275] 3.3 Attention Mechanism
[0276] The attention mechanism is introduced to selectively focus on the key information in the input sequence and enhance the predictive ability of the model.
[0277] Similarity Calculation: The similarity between the query vector and the key vector is evaluated using the dot product method.
[0278] Normalization: Use softmax to convert similarity scores into weights.
[0279] Weighted summation: The context vector is generated by weighted summation of the value vector according to the weights.
[0280] 3.4 Output Layer
[0281] The output layer converts the feature vector into traffic flow prediction results through a fully connected layer and a linear activation function.
[0282] Fully connected layer: linearly combines feature vectors.
[0283] Activation function: Linear activation function, suitable for regression tasks.
[0284] 4. Model Training
[0285] 4.1 Pre-training
[0286] Use large public traffic flow datasets for pre-training to enable the model to learn common traffic flow features and improve its generalization ability on new data.
[0287] 4.2 Scenario-Specific Training
[0288] In an embodiment, the model is retrained using actual data from a target highway to fine-tune the model to adapt to the specific traffic conditions in the case.
[0289] Training steps:
[0290] The dataset is divided into training set, validation set and test set with a ratio of 7:2:1.
[0291] The optimization algorithm used was Adam, and the learning rate was set to 0.001.
[0292] The loss function uses the mean squared logarithmic error (MSLE), which is suitable for capturing subtle changes in traffic flow.
[0293] The model performance was evaluated through 5-fold cross validation.
[0294] Early stopping strategy: monitor the validation set loss to avoid overfitting.
[0295] 5. Results Analysis
[0296] The evaluation results on the test set show that the model performs well in traffic flow prediction. The results of each evaluation indicator are as follows:
[0297] Mean Absolute Error (MAE):
[0298]
[0299] Reflects the mean absolute error between the model's predictions and the actual values. A MAE of 35.7 vehicles / hour indicates that the model has a high prediction accuracy. This value means that the difference between the model's predictions and the actual values in the hourly traffic forecast is an average of 35.7 vehicles. If the actual traffic flow on a particular highway segment is between 400 and 500 vehicles per hour, then = 35.7 vehicles / hour is relatively small, indicating that the model has good prediction performance and can provide relatively accurate traffic flow prediction. This level of accuracy can provide a reliable basis for traffic management departments to make traffic control and planning decisions.
[0300] Mean Squared Error (MSE):
[0301]
[0302] Measures the average squared difference between the predicted value and the actual value, which reflects the variance of the prediction error, represents the squared value of the error, and emphasizes large error terms. = 1950 vehicles² / hour² indicates that the average square error between the predicted value and the actual traffic value is 1950. This means that the model is more sensitive to extreme deviations, and larger errors will have a more significant impact on MSE.
[0303] Mean Squared Logarithmic Error (MSLE):
[0304]
[0305] MSLE measures the average of the squares of the logarithmic differences between the actual and predicted values, and is primarily used to examine the proportional error between the predicted and actual values. MSLE = 0.029 indicates that the difference between the predicted and actual values in logarithmic space is small. It is particularly sensitive to proportional changes in traffic flow prediction, which allows the model to maintain stability and accuracy when dealing with traffic of different magnitudes.
[0306] Coefficient of Determination (R2R^2R2):
[0307]
[0308] It is an indicator of the goodness of fit of the model, indicating the proportion of the dependent variable variation that the independent variable can explain. Its value is between 0 and 1, and the closer it is to 1, the better the model. =0.86 means that the model can explain 86% of the traffic flow variation. This means that most of the traffic flow variation is captured by the model, and only 14% of the variation is due to noise caused by other unconsidered factors. High The value indicates that the model has a strong explanatory power in capturing traffic flow patterns, which provides a reliable basis for traffic flow management and optimization and ensures that the model can provide accurate predictions in most cases.
[0309] Multiple performance evaluation index data verify the excellent performance of the hierarchical GRU model in the present invention in highway traffic flow prediction, and can provide accurate and reliable support for traffic management. The present invention improves the prediction accuracy and enhances the intelligent level of traffic management by combining multi-source data and deep learning models.
[0310] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for predicting highway traffic flow, characterized in that: include: Data collection: Collect public traffic flow data sets, national highway traffic flow data sets, and geological and meteorological information data sets; Data preprocessing: preprocess the collected data; Model training: A hierarchical GRU structure is used. The model structure includes detailed configuration of the input layer, encoding layer, attention mechanism, and output layer. The model adopts a two-stage training strategy. Model training is divided into a pre-training stage and a scenario-specific training stage. The pre-training stage uses a large-scale public traffic flow data set for pre-training, so that the model can learn the basic traffic flow change pattern; the scenario-specific training stage uses the scene data to fine-tune the model and adjust the model parameters. Model evaluation: Multiple evaluation criteria are used to measure the performance of the model in the traffic flow prediction task, including mean absolute error, mean square error, mean square logarithmic error, and determination coefficient.
2. The method for predicting highway traffic flow according to claim 1, characterized in that: In the step data collection, the traffic flow data set includes: hourly flow data, recording timestamp, vehicle type, vehicle speed and flow; the geological information includes: geological type of the road section, soil moisture and geological disaster risk assessment; the meteorological information: recording temperature, precipitation, wind speed meteorological parameters.
3. The method for predicting highway traffic flow according to claim 1, characterized in that: In the step of data preprocessing, the steps of data preprocessing include: missing value filling, outlier processing and data standardization processing.
4. The method for predicting highway traffic flow according to claim 1, characterized in that: In the step model training, the hierarchical GRU structure is used to solve the complex time series data processing problem in highway traffic flow prediction, wherein the input layer uses a convolutional layer for preliminary feature extraction, the encoding layer uses a hierarchical GRU for time series feature modeling, the attention mechanism increases the focus on important features, and the output layer performs traffic prediction.
5. The method for predicting highway traffic flow according to claim 1, characterized in that: In step model training, the training steps include: Data preparation: Divide the dataset into training set, validation set, and test set, and design specific ratios; If pre-training is performed, a large-scale public traffic flow dataset is used for initialization so that the model can learn the basic traffic flow change pattern. The optimization process uses MSLE as the loss function and the Adam optimization algorithm. The training iteration is performed for multiple rounds until the validation set loss no longer decreases significantly. If scenario-specific training is performed, the data in the scenario is used for retraining to further adjust the model parameters. The optimization process uses MSLE as the loss function and the Adam optimization algorithm. The training iteration is performed for multiple rounds until the validation set loss no longer decreases significantly. Training evaluation: Evaluate model performance through cross-validation, use early stopping strategy, save the model parameters with the best performance indicators as the final model, and the training ends.
6. A highway traffic flow prediction module, characterized in that: A method for predicting highway traffic flow as described in any one of claims 1 to 5, comprising: a data collection module, a data preprocessing module, a model training module, and a model evaluation module; the data collection module is used to collect public traffic flow data sets, national highway traffic flow data sets, and geological information and meteorological information data sets; the data preprocessing module is used to preprocess the collected data; the model training module adopts a hierarchical GRU structure and a two-stage training strategy, and the model training is divided into a pre-training stage and a scenario-specific training stage; the model evaluation module adopts multiple evaluation criteria to measure the performance of the model in the traffic flow prediction task.