Traffic flow prediction method and system based on machine learning
By constructing the adjacency matrix of traffic, meteorology and holidays in traffic flow prediction, and using graph convolutional network model based on attention mechanism and federated learning, the nonlinear feature and data security problems in traffic flow prediction are solved, and the prediction is improved Accuracy and model robustness ensure data security.
Patent Information
- Application Number
- CN202411014173.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-11-22
- Estimated Expiration
- 2044-07-26
AI Technical Summary
During the existing traffic flow prediction process, traffic flow has nonlinear characteristics and is susceptible to weather conditions and holiday conditions, resulting in the prediction accuracy needs to be improved; the actual traffic conditions are complex and changeable, with time-space dependence and nonlinear relationships, resulting in the model. Poor performance; traffic data involves a large amount of personal privacy information, and data security requirements are high.
Based on the construction of the adjacency matrix of transportation, meteorology and holidays, a graph convolutional network model based on attention mechanism is used for local model construction, and a global model update is carried out in combination with federated learning to ensure data privacy and security.
It improves the accuracy and reliability of traffic flow prediction, enhances the robustness and generalization capabilities of the model, and ensures data security.
Smart Images

Figure CN118538035B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of intelligent transportation technology, and specifically refers to a traffic flow prediction method and system based on machine learning. Background Art
[0002] Traffic flow prediction is an important part of smart city construction. It aims to use machine learning technology to analyze historical traffic data and other related information to predict traffic flow in specific areas in the future time period, help traffic management departments identify potential traffic congestion in advance, improve traffic mobility, and improve urban operation efficiency and quality of life of residents. However, in the existing traffic flow prediction process, there are technical problems that traffic flow has nonlinear characteristics and is easily affected by weather conditions and holidays, resulting in the need to improve the accuracy of prediction; there are technical problems that the actual traffic conditions are complex and changeable, with spatiotemporal dependence and nonlinear relationships, resulting in poor model performance; there are technical problems that traffic data involves a large amount of personal privacy information and requires high data security. Summary of the invention
[0003] In view of the above situation, in order to overcome the defects of the prior art, the present invention provides a traffic flow prediction method and system based on machine learning. In view of the technical problem that in the existing traffic flow prediction process, traffic flow has nonlinear characteristics and is easily affected by weather conditions and holiday conditions, resulting in the need to improve the prediction accuracy, this solution further constructs a local model on the basis of constructing a traffic adjacency matrix, a meteorological adjacency matrix and a holiday adjacency matrix, effectively integrating traffic characteristics, meteorological characteristics and holiday characteristics, which helps to improve the prediction accuracy and reliability; in view of the fact that in the existing traffic flow prediction process, the actual traffic conditions are complex and changeable, with spatiotemporal dependence and nonlinear relationships, resulting in the model performance being poor. In order to solve the technical problem of poor performance, this solution creatively adopts a graph convolutional network model based on the attention mechanism to build a local model, which can better capture the dynamic changes in traffic data, comprehensively consider the influence of various features, and improve the model robustness and prediction performance. In view of the technical problem that traffic data involves a large amount of personal privacy information and has high requirements for data security in the existing traffic flow prediction process, this solution creatively adopts federated learning to update the global model, effectively ensuring data privacy and security. Different clients belong to different regions and have diverse data, which can more effectively capture the spatiotemporal dependence of traffic data, improve the generalization ability and accuracy of the model, and enhance data security.
[0004] The technical solution adopted by the present invention is as follows: The traffic flow prediction method based on machine learning provided by the present invention comprises the following steps:
[0005] Step S1: data preparation;
[0006] Step S2: adjacency matrix construction;
[0007] Step S3: local model construction;
[0008] Step S4: global model update;
[0009] Step S5: Generate a forecast report.
[0010] Furthermore, in step S1, data preparation is used for the client to collect local data and perform preprocessing, specifically, traffic data, weather data and holiday data are collected through the client, and preprocessed through data cleaning, time alignment and normalization to obtain local optimized data, and the local optimized data includes traffic optimized data, weather optimized data and holiday optimized data.
[0011] Furthermore, in step S2, the adjacency matrix is constructed, specifically, based on the local optimization data, a traffic flow map, a weather map and a holiday map are constructed respectively, and a traffic adjacency matrix, a weather adjacency matrix and a holiday adjacency matrix are further constructed, including the following steps:
[0012] Step S21: constructing a graph structure, specifically, constructing a traffic flow graph, a weather graph, and a holiday graph respectively based on the local optimization data;
[0013] Each node of the traffic flow graph represents a traffic node, and the node attribute is the traffic condition, specifically including traffic flow, traffic density, average speed and congestion status;
[0014] Each node of the weather map represents an area, and the node attributes are weather conditions, including temperature, rainfall and wind speed;
[0015] Each node of the holiday graph represents a time period, and the node attribute is the holiday status, which specifically includes the holiday type, holiday length, and holiday identifier, and the holiday identifier is used to indicate whether the time period is a holiday;
[0016] Step S22: constructing a traffic adjacency matrix, specifically, establishing the connection relationship between each node in the traffic flow graph according to the spatial relationship in the traffic optimization data. If there is a road connection between two nodes, the corresponding adjacency matrix element is 1, otherwise it is 0, and the traffic adjacency matrix is obtained;
[0017] Step S23: constructing a meteorological adjacency matrix, specifically, establishing a connection relationship between each node in the meteorological map according to the position relationship in the meteorological optimization data. If the distance between two nodes is within a preset range, the corresponding adjacency matrix element is 1, otherwise it is 0, and the meteorological adjacency matrix is obtained;
[0018] Step S24: constructing a holiday adjacency matrix, specifically, establishing the connection relationship between each node in the holiday graph according to the holiday optimization data. If the holiday types of two nodes are the same, the corresponding adjacency matrix element is 1, otherwise it is 0, and the holiday adjacency matrix is obtained.
[0019] Further, in step S3, the local model construction is used to construct a local model of the client and deploy it, specifically, designing a graph convolutional network model based on an attention mechanism, constructing a local model, and completing local model deployment;
[0020] The graph convolutional network model based on the attention mechanism specifically includes a change feature extraction layer, a self-attention feature fusion layer, a parallel spatiotemporal graph convolution layer and a dense prediction layer;
[0021] The change feature extraction layer is used to capture dynamic change features in traffic data;
[0022] The self-attention feature fusion layer is used to fuse the change feature and the traffic flow feature;
[0023] The parallel spatiotemporal graph convolution layer is used to aggregate adjacency matrix node information;
[0024] The dense prediction layer is used to fuse multiple features to make predictions and generate prediction results;
[0025] The local model construction includes the following steps:
[0026] Step S31: constructing the basic architecture of the graph convolutional network model;
[0027] Step S32: Optimize the graph convolution network model and design a graph convolution network model based on the attention mechanism. Specifically, on the basis of the graph convolution network model, an improved self-attention mechanism is added, and a change feature extraction layer, a self-attention feature fusion layer and a parallel spatiotemporal graph convolution layer are designed to obtain a graph convolution network model based on the attention mechanism, including the following steps:
[0028] Step S321: Design a change feature extraction layer, specifically, set a differential operation, a dense layer, a long short-term memory layer and a maximum attention block in the change feature extraction layer, extract the change features of the traffic optimization data through the change feature extraction layer, and generate the final hidden state, including the following steps:
[0029] Step S3211: performing a differential operation on the traffic optimization data to obtain a change feature sequence;
[0030] Step S3212: Map the change feature sequence to a high-dimensional space through a dense layer to obtain a high-dimensional dynamic feature. The calculation formula is:
[0031] ;
[0032] Where, d hint is a high-dimensional dynamic feature, W hint is the mapping weight, d is the change feature sequence, b hint is the mapping bias term;
[0033] Step S3213: extracting time series information from high-dimensional dynamic features through the long short-term memory layer to obtain long-term and short-term hidden states;
[0034] Step S3214: constructing a maximum attention block, specifically by performing a global maximum pooling operation on the long-term and short-term hidden states, and concatenating the global maximum pooling result with the long-term and short-term hidden states to obtain pooling change features, calculating the attention weight through the attention mechanism, and calculating the final hidden state based on the attention weight;
[0035] The attention weight is calculated by the attention mechanism, and the calculation formula for calculating the final hidden state based on the attention weight is:
[0036] ;
[0037] In the formula, is the attention weight, softmax(·) is the softmax function, A1 is the first attention weight matrix, T is the transpose operation, tanh(·) is the hyperbolic tangent function, A2 is the second attention weight matrix, pf is the pooling change feature, is the final hidden state at the tth time step, t is the time step index, used to represent the current moment, is the attention weight at the first time step, h1 is the long and short hidden state at the first time step, is the attention weight at the t-1th time step, h t-1 is the long and short hidden state at the t-1th time step;
[0038] Step S322: designing a self-attention feature fusion layer, specifically setting a dense layer, a self-attention block and a convolutional attention block in the self-attention feature fusion layer, and calculating the self-attention fusion feature through the self-attention feature fusion layer, including the following steps:
[0039] Step S3221: Map the traffic optimization data to the same dimension as the final hidden state through a dense layer, and concatenate the mapping result with the final hidden state to obtain a traffic concatenation vector;
[0040] Step S3222: construct a self-attention block for calculating self-attention, specifically using three independent dense layers to map the traffic splicing vectors respectively, generate a query matrix, a key matrix and a value matrix, and apply the self-attention mechanism for calculation;
[0041] Step S3223: construct a convolutional attention block for feature extraction and enhancement. Specifically, in the convolutional attention block, the traffic optimization data is calculated in sequence through the convolution layer, the batch normalization layer, the Gaussian error linear unit and the channel attention sub-block;
[0042] Step S3224: performing a residual connection between the output of the self-attention block and the output of the convolutional attention block to obtain a self-attention fusion feature, wherein the self-attention fusion feature specifically refers to the output result of the self-attention feature fusion layer;
[0043] Step S323: Design a parallel spatiotemporal graph convolution layer to generate aggregate features of traffic, weather, and holidays. The aggregate features are calculated through the parallel spatiotemporal graph convolution layer, including the following steps:
[0044] Step S3231: setting three parallel spatiotemporal graph convolutional layers and one feature aggregation block in the parallel spatiotemporal graph convolutional layer;
[0045] Step S3232: constructing a spatiotemporal graph convolution layer, specifically constructing a spatiotemporal convolution layer and a graph convolution layer in each spatiotemporal graph convolution layer;
[0046] Step S3233: extracting features from the traffic adjacency matrix, the weather adjacency matrix, and the holiday adjacency matrix respectively through three parallel spatiotemporal graph convolutional layers to generate traffic, weather, and holiday features;
[0047] Step S3234: constructing a feature aggregation block, specifically aggregating traffic, weather and holiday features through the feature aggregation block to obtain aggregated features;
[0048] Step S324: designing a dense prediction layer, setting a first dense layer, a GLU activation operation, a transformer encoder, and a second dense layer in the dense prediction layer, calculating the self-attention fusion feature and the aggregation feature through the dense prediction layer, and outputting the prediction result;
[0049] The calculation formula of the GLU activation operation is:
[0050] ;
[0051] Where GLU(·) is the GLU activation operation, X is the input parameter of the GLU activation operation, is the element-by-element multiplication symbol, W1 is the first weight of the GLU activation operation, b1 is the first bias term of the GLU activation operation, Sig(·) is the S-type activation function, W2 is the second weight of the GLU activation operation, and b2 is the second bias term of the GLU activation operation;
[0052] Step S33: Local model deployment, specifically deploying the graph convolutional network model based on the attention mechanism to each client to obtain a client local model.
[0053] Further, in step S4, the global model update is used to update the global model of the server, specifically using federated learning to update the global model, including the following steps:
[0054] Step S41: local model training, specifically using each client's local optimization data to train the client's local model, and uploading the model parameters of each client to the central server;
[0055] Step S42: Model aggregation and updating, specifically, aggregating the model parameters of each client on the central server through a joint proximal method, updating the global model parameters, and sending the updated global model parameters back to each client;
[0056] Step S43: global model training, specifically, performing iterative training by repeating the steps described in step S41 and step S42 to obtain the optimal global prediction model.
[0057] Furthermore, in step S5, the forecast report is generated to predict traffic flow and generate a report, specifically, traffic flow forecasting is performed through the optimal global forecasting model, and a traffic flow forecast report is generated to provide traffic flow peak reminders. The traffic flow forecast report includes a time range, road section and traffic flow trend.
[0058] The traffic flow prediction system based on machine learning provided by the present invention comprises: a data preparation module, an adjacency matrix construction module, a local model construction module, a global model update module and a prediction report generation module;
[0059] The data preparation module is used for data preparation, obtains local optimization data through data preparation, and sends the local optimization data to the adjacency matrix construction module, the local model construction module and the global model update module;
[0060] The adjacency matrix construction module is used for adjacency matrix construction, and obtains a traffic adjacency matrix, a meteorological adjacency matrix and a holiday adjacency matrix through adjacency matrix construction, and sends the traffic adjacency matrix, the meteorological adjacency matrix and the holiday adjacency matrix to the local model construction module;
[0061] The local model building module is used for local model building, obtains the client local model through local model building, and sends the client local model to the global model updating module;
[0062] The global model updating module is used for global model updating, obtains the optimal global prediction model through global model updating, and sends the optimal global prediction model to the prediction report generating module;
[0063] The forecast report generation module is used for forecast report generation, through which a traffic flow forecast report is obtained and a traffic flow peak reminder is issued.
[0064] The beneficial effects achieved by the present invention using the above scheme are as follows:
[0065] (1) In view of the technical problem that the current traffic flow prediction process has nonlinear characteristics and is easily affected by weather conditions and holiday conditions, resulting in the need to improve the prediction accuracy, this solution further constructs a local model based on the construction of the traffic adjacency matrix, meteorological adjacency matrix and holiday adjacency matrix, effectively integrating traffic characteristics, meteorological characteristics and holiday characteristics, which helps to improve the prediction accuracy and reliability;
[0066] (2) In view of the technical problem that the actual traffic conditions are complex and changeable, with spatiotemporal dependencies and nonlinear relationships, which leads to poor model performance in the existing traffic flow prediction process, this solution creatively adopts a graph convolutional network model based on the attention mechanism to build a local model, better capture the dynamic change characteristics of traffic data, comprehensively consider the influence of multiple aspects of characteristics, and improve the model robustness and prediction performance;
[0067] (3) In view of the technical problem that traffic data in the existing traffic flow prediction process involves a large amount of personal privacy information and has high requirements for data security, this solution creatively uses federated learning to update the global model, effectively ensuring data privacy and security. In addition, different clients belong to different regions and have diverse data, which can more effectively capture the spatiotemporal dependence of traffic data, improve the generalization ability and accuracy of the model, and enhance data security. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] Figure 1 A flow chart of a traffic flow prediction method based on machine learning provided by the present invention;
[0069] Figure 2 A schematic diagram of a traffic flow prediction system based on machine learning provided by the present invention;
[0070] Figure 3 is a schematic flow chart of step S2;
[0071] Figure 4 is a schematic flow chart of step S3;
[0072] Figure 5 It is a flowchart diagram of step S32.
[0073] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention. DETAILED DESCRIPTION
[0074] The technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments; based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0075] In the description of the present invention, it should be understood that terms such as “upper”, “lower”, “front”, “back”, “left”, “right”, “top”, “bottom”, “inside” and “outside” indicating directions or positional relationships are based on the directions or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific direction, be constructed and operated in a specific direction, and therefore should not be understood as limiting the present invention.
[0076] Example 1, see Figure 1 The present invention provides a method for predicting traffic flow based on machine learning, which comprises the following steps:
[0077] Step S1: data preparation;
[0078] Step S2: adjacency matrix construction;
[0079] Step S3: local model construction;
[0080] Step S4: global model update;
[0081] Step S5: Generate a forecast report.
[0082] Example 2, see Figure 1 This embodiment is based on the above embodiment. In step S1, data preparation is used for the client to collect local data and perform preprocessing. Specifically, traffic data, weather data and holiday data are collected through the client, and preprocessed through data cleaning, time alignment and normalization to obtain local optimized data. The local optimized data includes traffic optimized data, weather optimized data and holiday optimized data.
[0083] Example 3, see Figure 1 and Figure 3This embodiment is based on the above embodiment. In step S2, the adjacency matrix is constructed, specifically, based on the local optimization data, a traffic flow map, a weather map and a holiday map are constructed respectively, and a traffic adjacency matrix, a weather adjacency matrix and a holiday adjacency matrix are further constructed, including the following steps:
[0084] Step S21: constructing a graph structure, specifically, constructing a traffic flow graph, a weather graph, and a holiday graph respectively based on the local optimization data;
[0085] Each node of the traffic flow graph represents a traffic node, and the node attribute is the traffic condition, specifically including traffic flow, traffic density, average speed and congestion status;
[0086] Each node of the weather map represents an area, and the node attributes are weather conditions, including temperature, rainfall and wind speed;
[0087] Each node of the holiday graph represents a time period, and the node attribute is the holiday status, which specifically includes the holiday type, holiday length, and holiday identifier, and the holiday identifier is used to indicate whether the time period is a holiday;
[0088] Step S22: constructing a traffic adjacency matrix, specifically, establishing the connection relationship between each node in the traffic flow graph according to the spatial relationship in the traffic optimization data. If there is a road connection between two nodes, the corresponding adjacency matrix element is 1, otherwise it is 0, and the traffic adjacency matrix is obtained;
[0089] Step S23: constructing a meteorological adjacency matrix, specifically, establishing a connection relationship between each node in the meteorological map according to the position relationship in the meteorological optimization data. If the distance between two nodes is within a preset range, the corresponding adjacency matrix element is 1, otherwise it is 0, and the meteorological adjacency matrix is obtained;
[0090] Step S24: constructing a holiday adjacency matrix, specifically, establishing the connection relationship between each node in the holiday graph according to the holiday optimization data. If the holiday types of two nodes are the same, the corresponding adjacency matrix element is 1, otherwise it is 0, and the holiday adjacency matrix is obtained;
[0091] By performing the above operations, in order to address the technical problem that in the existing traffic flow prediction process, traffic flow has nonlinear characteristics and is easily affected by weather conditions and holiday conditions, resulting in the need to improve the prediction accuracy, this solution further constructs a local model based on the construction of traffic adjacency matrix, meteorological adjacency matrix and holiday adjacency matrix, effectively integrating traffic characteristics, meteorological characteristics and holiday characteristics, which helps to improve the prediction accuracy and reliability.
[0092] Example 4, see Figure 1 , Figure 4 and Figure 5, this embodiment is based on the above embodiment. In step S3, the local model is constructed to construct a local model of the client and deploy it, specifically, a graph convolutional network model based on an attention mechanism is designed, a local model is constructed, and local model deployment is completed;
[0093] The graph convolutional network model based on the attention mechanism specifically includes a change feature extraction layer, a self-attention feature fusion layer, a parallel spatiotemporal graph convolution layer and a dense prediction layer;
[0094] The change feature extraction layer is used to capture dynamic change features in traffic data;
[0095] The self-attention feature fusion layer is used to fuse the change feature and the traffic flow feature;
[0096] The parallel spatiotemporal graph convolution layer is used to aggregate adjacency matrix node information;
[0097] The dense prediction layer is used to fuse multiple features to make predictions and generate prediction results;
[0098] The local model construction includes the following steps:
[0099] Step S31: constructing the basic architecture of the graph convolutional network model;
[0100] Step S32: Optimize the graph convolution network model and design a graph convolution network model based on the attention mechanism. Specifically, on the basis of the graph convolution network model, an improved self-attention mechanism is added, and a change feature extraction layer, a self-attention feature fusion layer and a parallel spatiotemporal graph convolution layer are designed to obtain a graph convolution network model based on the attention mechanism, including the following steps:
[0101] Step S321: Design a change feature extraction layer, specifically, set a differential operation, a dense layer, a long short-term memory layer and a maximum attention block in the change feature extraction layer, extract the change features in the traffic optimization data through the change feature extraction layer, and generate the final hidden state, including the following steps:
[0102] Step S3211: performing a differential operation on the traffic optimization data to obtain a change feature sequence;
[0103] Step S3212: Map the change feature sequence to a high-dimensional space through a dense layer to obtain a high-dimensional dynamic feature. The calculation formula is:
[0104] ;
[0105] Where, d hint is a high-dimensional dynamic feature, W hint is the mapping weight, d is the change feature sequence, b hint is the mapping bias term;
[0106] Step S3213: extracting time series information from high-dimensional dynamic features through the long short-term memory layer to obtain long-term and short-term hidden states;
[0107] Step S3214: constructing a maximum attention block, specifically by performing a global maximum pooling operation on the long-term and short-term hidden states, and concatenating the global maximum pooling result with the long-term and short-term hidden states to obtain pooling change features, calculating the attention weight through the attention mechanism, and calculating the final hidden state based on the attention weight;
[0108] The attention weight is calculated by the attention mechanism, and the calculation formula for calculating the final hidden state based on the attention weight is:
[0109] ;
[0110] In the formula, is the attention weight, softmax(·) is the softmax function, A1 is the first attention weight matrix, T is the transpose operation, tanh(·) is the hyperbolic tangent function, A2 is the second attention weight matrix, pf is the pooling change feature, is the final hidden state at the tth time step, t is the time step index, used to represent the current moment, is the attention weight at the first time step, h1 is the long and short hidden state at the first time step, is the attention weight at the t-1th time step, h t-1 is the long and short hidden state at the t-1th time step;
[0111] Step S322: designing a self-attention feature fusion layer, specifically setting a dense layer, a self-attention block and a convolutional attention block in the self-attention feature fusion layer, and calculating the self-attention fusion feature through the self-attention feature fusion layer, including the following steps:
[0112] Step S3221: Map the traffic optimization data to the same dimension as the final hidden state through a dense layer, and concatenate the mapping result with the final hidden state to obtain a traffic concatenation vector;
[0113] Step S3222: construct a self-attention block for calculating self-attention. Specifically, three independent dense layers are used to map the traffic splicing vectors respectively, generate query matrix, key matrix and value matrix, and apply the self-attention mechanism for calculation. The calculation formula is:
[0114] ;
[0115] In the formula, is the self-attention output sequence, specifically the output of the self-attention block, specifically the output of the self-attention mechanism, Q is the query matrix, K is the key matrix, V is the value matrix, and d is the hidden dimension of the self-attention mechanism;
[0116] Step S3223: construct a convolutional attention block for feature extraction and enhancement. Specifically, in the convolutional attention block, the traffic optimization data is calculated in sequence through the convolution layer, the batch normalization layer, the Gaussian error linear unit and the channel attention sub-block;
[0117] Step S3224: performing a residual connection between the output of the self-attention block and the output of the convolutional attention block to obtain a self-attention fusion feature, wherein the self-attention fusion feature specifically refers to the output result of the self-attention feature fusion layer;
[0118] Step S323: Design a parallel spatiotemporal graph convolution layer to generate aggregate features of traffic, weather, and holidays. The aggregate features are calculated through the parallel spatiotemporal graph convolution layer, including the following steps:
[0119] Step S3231: setting three parallel spatiotemporal graph convolutional layers and one feature aggregation block in the parallel spatiotemporal graph convolutional layer;
[0120] Step S3232: constructing a spatiotemporal graph convolution layer, specifically constructing a spatiotemporal convolution layer and a graph convolution layer in each spatiotemporal graph convolution layer;
[0121] Step S3233: extracting features from the traffic adjacency matrix, the weather adjacency matrix, and the holiday adjacency matrix respectively through three parallel spatiotemporal graph convolutional layers to generate traffic, weather, and holiday features;
[0122] Step S3234: constructing a feature aggregation block, specifically aggregating traffic, weather and holiday features through the feature aggregation block to obtain aggregated features;
[0123] Step S324: designing a dense prediction layer, setting a first dense layer, a GLU activation operation, a transformer encoder, and a second dense layer in the dense prediction layer, calculating the self-attention fusion feature and the aggregation feature through the dense prediction layer, and outputting the prediction result;
[0124] The calculation formula of the GLU activation operation is:
[0125] ;
[0126] Where GLU(·) is the GLU activation operation, X is the input parameter of the GLU activation operation, is the element-by-element multiplication symbol, W1 is the first weight of the GLU activation operation, b1 is the first bias term of the GLU activation operation, Sig(·) is the S-type activation function, W2 is the second weight of the GLU activation operation, and b2 is the second bias term of the GLU activation operation;
[0127] Step S33: local model deployment, specifically deploying the graph convolutional network model based on the attention mechanism to each client to obtain a client local model;
[0128] By performing the above operations, in order to solve the technical problem that the actual traffic conditions in the existing traffic flow prediction process are complex and changeable, with spatiotemporal dependencies and nonlinear relationships, resulting in poor model performance, this solution creatively adopts a graph convolutional network model based on the attention mechanism to build a local model, better capture the dynamic changes in traffic data, comprehensively consider the influence of multiple features, and improve the model robustness and prediction performance.
[0129] Example 5, see Figure 1 This embodiment is based on the above embodiment. In step S4, the global model update is used to update the global model on the server side. Specifically, the global model update is performed using federated learning, and includes the following steps:
[0130] Step S41: local model training, specifically using each client's local optimization data to train the client's local model, and uploading the model parameters of each client to the central server;
[0131] Step S42: Model aggregation and updating, specifically, aggregating the model parameters of each client on the central server through a joint proximal method, updating the global model parameters, and sending the updated global model parameters back to each client;
[0132] Step S43: global model training, specifically, performing iterative training by repeating the steps described in step S41 and step S42 to obtain an optimal global prediction model;
[0133] By performing the above operations, in order to address the technical problem that in the existing traffic flow prediction process, traffic data involves a large amount of personal privacy information and has high requirements for data security, this solution creatively uses federated learning to update the global model, effectively ensuring data privacy and security. In addition, different clients belong to different regions and have diverse data, which can more effectively capture the spatiotemporal dependency of traffic data, improve the generalization ability and accuracy of the model, and enhance data security.
[0134] Example 6, see Figure 1This embodiment is based on the above embodiment. In step S5, the prediction report is generated to predict traffic flow and generate a report. Specifically, traffic flow prediction is performed through the optimal global prediction model, and a traffic flow prediction report is generated to provide traffic flow peak reminders. The traffic flow prediction report includes a time range, road section, and traffic flow trend.
[0135] Embodiment 7, see Figure 2 ,This embodiment is based on the above embodiment. The machine learning-based traffic flow prediction system provided by the present invention includes: a data preparation module, an adjacency matrix construction module, a local model construction module, a global model update module and a prediction report generation module;
[0136] The data preparation module is used for data preparation, obtains local optimization data through data preparation, and sends the local optimization data to the adjacency matrix construction module, the local model construction module and the global model update module;
[0137] The adjacency matrix construction module is used for adjacency matrix construction, and obtains a traffic adjacency matrix, a meteorological adjacency matrix and a holiday adjacency matrix through adjacency matrix construction, and sends the traffic adjacency matrix, the meteorological adjacency matrix and the holiday adjacency matrix to the local model construction module;
[0138] The local model building module is used for local model building, obtains the client local model through local model building, and sends the client local model to the global model updating module;
[0139] The global model updating module is used for global model updating, obtains the optimal global prediction model through global model updating, and sends the optimal global prediction model to the prediction report generating module;
[0140] The forecast report generation module is used for forecast report generation, through which a traffic flow forecast report is obtained and a traffic flow peak reminder is issued.
[0141] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device.
[0142] While the embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that many changes, modifications, substitutions and variations can be made to the embodiments without departing from the principles and spirit of the invention.
[0143] The present invention and its embodiments are described above, and such description is not restrictive. The drawings show only one embodiment of the present invention, and the actual structure is not limited thereto. In short, if ordinary technicians in the field are inspired by it, without departing from the purpose of the invention, they can design a structure and embodiment similar to the technical solution without creativity, which should belong to the protection scope of the present invention.
Claims
1. A traffic flow prediction method based on machine learning, characterized by: The method comprises the following steps: Step S1: Data preparation, which is used for the client to collect local data and perform preprocessing, specifically, collecting traffic data, weather data and holiday data through the client, and preprocessing through data cleaning, time alignment and normalization to obtain local optimized data, wherein the local optimized data includes traffic optimized data, weather optimized data and holiday optimized data; Step S2: Adjacency matrix construction, specifically, constructing a traffic flow map, a weather map, and a holiday map respectively based on the local optimization data, and further constructing a traffic adjacency matrix, a weather adjacency matrix, and a holiday adjacency matrix; Step S3: Local model construction, which is used to build the client's local model and deploy it. Specifically, a graph convolutional network model based on the attention mechanism is designed, local model construction is performed, and local model deployment is completed. The graph convolutional network model based on the attention mechanism specifically includes a change feature extraction layer, a self-attention feature fusion layer, a parallel spatiotemporal graph convolution layer and a dense prediction layer; The change feature extraction layer is used to capture dynamic change features in traffic data; The self-attention feature fusion layer is used to fuse the change feature and the traffic flow feature; The parallel spatiotemporal graph convolution layer is used to aggregate adjacency matrix node information; The dense prediction layer is used to fuse multiple features to make predictions and generate prediction results; The local model construction includes the following steps: Step S31: constructing the basic architecture of the graph convolutional network model; Step S32: Optimize the graph convolution network model and design a graph convolution network model based on the attention mechanism. Specifically, on the basis of the graph convolution network model, an improved self-attention mechanism is added, and a change feature extraction layer, a self-attention feature fusion layer and a parallel spatiotemporal graph convolution layer are designed to obtain a graph convolution network model based on the attention mechanism, including the following steps: Step S321: Design a change feature extraction layer, specifically, set a differential operation, a dense layer, a long short-term memory layer and a maximum attention block in the change feature extraction layer, extract the change features in the traffic optimization data through the change feature extraction layer, and generate the final hidden state, including the following steps: Step S3211: performing a differential operation on the traffic optimization data to obtain a change feature sequence; Step S3212: Map the change feature sequence to a high-dimensional space through a dense layer to obtain a high-dimensional dynamic feature. The calculation formula is: ; Where, d hint is a high-dimensional dynamic feature, W hint is the mapping weight, d is the change feature sequence, b hint is the mapping bias term; Step S3213: extracting time series information from high-dimensional dynamic features through the long short-term memory layer to obtain long-term and short-term hidden states; Step S3214: constructing a maximum attention block, specifically by performing a global maximum pooling operation on the long-term and short-term hidden states, and concatenating the global maximum pooling result with the long-term and short-term hidden states to obtain pooling change features, calculating the attention weight through the attention mechanism, and calculating the final hidden state based on the attention weight; The attention weight is calculated by the attention mechanism, and the calculation formula for calculating the final hidden state based on the attention weight is: ; In the formula, is the attention weight, softmax(·) is the softmax function, A1 is the first attention weight matrix, T is the transpose operation, tanh(·) is the hyperbolic tangent function, A2 is the second attention weight matrix, pf is the pooling change feature, is the final hidden state at the tth time step, t is the time step index, used to represent the current moment, is the attention weight at the first time step, h1 is the long and short hidden state at the first time step, is the attention weight at the t-1th time step, h t-1 is the long and short hidden state at the t-1th time step; Step S322: designing a self-attention feature fusion layer, specifically setting a dense layer, a self-attention block and a convolutional attention block in the self-attention feature fusion layer, and calculating the self-attention fusion feature through the self-attention feature fusion layer, including the following steps: Step S3221: Map the traffic optimization data to the same dimension as the final hidden state through a dense layer, and concatenate the mapping result with the final hidden state to obtain a traffic concatenation vector; Step S3222: construct a self-attention block for calculating self-attention, specifically using three independent dense layers to map the traffic splicing vectors respectively, generate a query matrix, a key matrix and a value matrix, and apply the self-attention mechanism for calculation; Step S3223: construct a convolutional attention block for feature extraction and enhancement. Specifically, in the convolutional attention block, the traffic optimization data is calculated in sequence through the convolution layer, the batch normalization layer, the Gaussian error linear unit and the channel attention sub-block; Step S3224: performing a residual connection between the output of the self-attention block and the output of the convolutional attention block to obtain a self-attention fusion feature, wherein the self-attention fusion feature specifically refers to the output result of the self-attention feature fusion layer; Step S323: Design a parallel spatiotemporal graph convolution layer to generate aggregate features of traffic, weather, and holidays. The aggregate features are calculated through the parallel spatiotemporal graph convolution layer, including the following steps: Step S3231: setting three parallel spatiotemporal graph convolutional layers and one feature aggregation block in the parallel spatiotemporal graph convolutional layer; Step S3232: constructing a spatiotemporal graph convolution layer, specifically constructing a spatiotemporal convolution layer and a graph convolution layer in each spatiotemporal graph convolution layer; Step S3233: extracting features from the traffic adjacency matrix, the weather adjacency matrix, and the holiday adjacency matrix respectively through three parallel spatiotemporal graph convolutional layers to generate traffic, weather, and holiday features; Step S3234: constructing a feature aggregation block, specifically aggregating traffic, weather and holiday features through the feature aggregation block to obtain aggregated features; Step S324: designing a dense prediction layer, setting a first dense layer, a GLU activation operation, a transformer encoder, and a second dense layer in the dense prediction layer, calculating the self-attention fusion feature and the aggregation feature through the dense prediction layer, and outputting the prediction result; The calculation formula of the GLU activation operation is: ; Where GLU(·) is the GLU activation operation, X is the input parameter of the GLU activation operation, is the element-by-element multiplication symbol, W1 is the first weight of the GLU activation operation, b1 is the first bias term of the GLU activation operation, Sig(·) is the S-type activation function, W2 is the second weight of the GLU activation operation, and b2 is the second bias term of the GLU activation operation; Step S33: local model deployment, specifically deploying the graph convolutional network model based on the attention mechanism to each client to obtain a client local model; Step S4: global model update, used to update the global model on the server side, specifically using federated learning to update the global model, including the following steps: Step S41: local model training, specifically using each client's local optimization data to train the client's local model, and uploading the model parameters of each client to the central server; Step S42: Model aggregation and updating, specifically, aggregating the model parameters of each client on the central server through a joint proximal method, updating the global model parameters, and sending the updated global model parameters back to each client; Step S43: global model training, specifically, performing iterative training by repeating the steps described in step S41 and step S42 to obtain an optimal global prediction model; Step S5: Forecast report generation, used to predict traffic flow and generate a report, specifically, to predict traffic flow through the optimal global prediction model, and generate a traffic flow forecast report, and issue a traffic flow peak reminder. The traffic flow forecast report includes a time range, road section and traffic flow trend.
2. The method for predicting traffic flow based on machine learning according to claim 1, characterized in that: In step S2, the adjacency matrix is constructed, including the following steps: Step S21: constructing a graph structure, specifically, constructing a traffic flow graph, a weather graph, and a holiday graph respectively based on the local optimization data; Each node of the traffic flow graph represents a traffic node, and the node attribute is the traffic condition, specifically including traffic flow, traffic density, average speed and congestion status; Each node of the weather map represents an area, and the node attributes are weather conditions, including temperature, rainfall and wind speed; Each node of the holiday graph represents a time period, and the node attribute is the holiday status, which specifically includes the holiday type, holiday length, and holiday identifier, and the holiday identifier is used to indicate whether the time period is a holiday; Step S22: constructing a traffic adjacency matrix, specifically, establishing the connection relationship between each node in the traffic flow graph according to the spatial relationship in the traffic optimization data. If there is a road connection between two nodes, the corresponding adjacency matrix element is 1, otherwise it is 0, and the traffic adjacency matrix is obtained; Step S23: constructing a meteorological adjacency matrix, specifically, establishing a connection relationship between each node in the meteorological map according to the position relationship in the meteorological optimization data. If the distance between two nodes is within a preset range, the corresponding adjacency matrix element is 1, otherwise it is 0, and the meteorological adjacency matrix is obtained; Step S24: constructing a holiday adjacency matrix, specifically, establishing the connection relationship between each node in the holiday graph according to the holiday optimization data. If the holiday types of two nodes are the same, the corresponding adjacency matrix element is 1, otherwise it is 0, and the holiday adjacency matrix is obtained.
3. A machine learning-based traffic flow prediction system, used to implement the machine learning-based traffic flow prediction method as described in any one of claims 1-2, characterized in that: It includes data preparation module, adjacency matrix construction module, local model construction module, global model update module and prediction report generation module.
4. The machine learning-based traffic flow prediction system according to claim 3, characterized in that: The data preparation module is used for data preparation, obtains local optimization data through data preparation, and sends the local optimization data to the adjacency matrix construction module, the local model construction module and the global model update module; The adjacency matrix construction module is used for adjacency matrix construction, and obtains a traffic adjacency matrix, a meteorological adjacency matrix and a holiday adjacency matrix through adjacency matrix construction, and sends the traffic adjacency matrix, the meteorological adjacency matrix and the holiday adjacency matrix to the local model construction module; The local model building module is used for local model building, obtains the client local model through local model building, and sends the client local model to the global model updating module; The global model updating module is used for global model updating, obtains the optimal global prediction model through global model updating, and sends the optimal global prediction model to the prediction report generating module; The forecast report generation module is used for forecast report generation. Through the forecast report generation, a traffic flow forecast report is obtained and a traffic flow peak reminder is issued.
