Disclosure of Invention
The embodiment of the invention provides a travel prediction method and device, and solves the problem of low precision of the existing travel prediction method.
According to a first aspect of the embodiments of the present invention, there is provided a travel prediction method, including: counting the number of trips of one or more traffic districts to obtain an original data set; determining a training set and a testing set according to the original data set; constructing a multilayer LSTM; training the multilayer LSTM through the training set and the testing set to determine model parameters of the multilayer LSTM; travel prediction is performed by the trained multi-layer LSTM.
Optionally, the counting the number of trips of one or more traffic cells to obtain an original data set includes: mapping a trip starting point and a trip end point in the traffic cell; determining time sequences of leaving the traffic cell and arriving at the traffic cell in each unit time according to a preset time unit; determining the time series as the original data set.
Optionally, the determining a training set and a test set according to the raw data set includes: and dividing the original data set into the training set and the test set according to a preset proportion, wherein the preset proportion is the proportion of the training set in the original data set.
Optionally, before the determining a training set and a test set from the raw data set, the method further comprises: converting the format of the original data set into a sample characteristic format and a sample label format according to a preset time interval; wherein the sample feature format represents input variables and the sample label format represents output variables.
Optionally, the preset ratio is 0.7 to 0.8.
Optionally, the constructing the multilayer LSTM comprises: when a traffic cell is predicted, a plurality of layers of LSTMs are constructed; when multiple traffic cells are predicted, a multi-layered encoding-decoding LSTM is constructed.
Optionally, the model parameters of the multi-layer LSTM are connection weight parameters between neurons and/or neural network layers.
Optionally, the loss function in the multi-layer LSTM training process is a mean square error function.
Optionally, the model parameter adjustment rule in the multi-layer LSTM training process is an adaptive moment estimation Adam algorithm.
According to a second aspect of the embodiments of the present invention, there is provided a travel prediction apparatus, including: the statistical module is used for counting the trip quantity of one or more traffic districts to obtain an original data set; the first determining module is used for determining a training set and a testing set according to the original data set; the building module is used for building a plurality of layers of LSTMs; the second determining module is used for training the multilayer LSTM through the training set and the testing set to determine model parameters of the multilayer LSTM; and the prediction module is used for predicting the trip through the trained multilayer LSTM.
Optionally, the statistics module includes: the mapping unit is used for mapping a trip starting point and a trip end point in the traffic cell; the first determining unit is used for determining time sequences of leaving the traffic cell and arriving at the traffic cell in each unit time according to a preset time unit; a second determining unit for determining the time series as the original data set.
Optionally, the first determining module includes: and the dividing unit is used for dividing the original data set into the training set and the test set according to a preset proportion, wherein the preset proportion is the proportion of the training set in the original data set.
Optionally, the first determining module further includes: the conversion unit is used for converting the format of the original data set into a sample characteristic format and a sample label format according to a preset time interval; wherein the sample feature format represents input variables and the sample label format represents output variables.
Optionally, the preset ratio is 0.7 to 0.8.
Optionally, the building module comprises: the first construction unit is used for constructing a plurality of layers of LSTMs when a traffic cell is predicted; and a second construction unit for constructing a multi-layer encoding-decoding LSTM when predicting a plurality of traffic cells.
Optionally, the model parameters of the multi-layer LSTM are connection weight parameters between neurons and/or neural network layers.
Optionally, the loss function in the multi-layer LSTM training process is a mean square error function.
Optionally, the model parameter adjustment rule in the multi-layer LSTM training process is Adam algorithm.
According to a third aspect of the embodiments of the present invention, there is provided a communication device, including a processor, a memory, and a program stored on the memory and executable on the processor, where the program, when executed by the processor, implements the steps of the travel prediction method according to the first aspect.
According to a fourth aspect of the embodiments of the present invention, there is provided a computer-readable storage medium, on which a computer program is stored, which when executed by a processor, implements the steps of the travel prediction method according to the first aspect.
In the embodiment of the invention, the traveling of the traffic community is counted to obtain an original data set, a multi-layer LSTM is constructed, the multi-layer LSTM is trained through the original data set, and the traveling prediction is carried out through the trained multi-layer LSTM. The neural network technology is applied to traffic trip prediction, the prediction precision is improved, and the demand of urban traffic trip prediction is met.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, an embodiment of the present invention provides a travel prediction method, including the following steps:
step 101: counting the number of trips of one or more traffic districts to obtain an original data set;
in the embodiment of the invention, a traffic cell is taken as a basic unit for predicting the travel, the number of the travel in the traffic cell is counted, and the number of the travel is determined as an original data set.
Specifically, the statistical raw data set comprises the following sub-steps:
(1) mapping a trip starting point and a trip end point in a traffic cell;
and mapping a travel starting point and a travel end point in the traffic cell, wherein the travel behavior generated at the travel starting point represents arriving at the traffic cell, and the travel behavior generated at the travel end point represents leaving from the traffic cell.
(2) Determining time sequences of leaving a traffic cell and arriving at the traffic cell in each unit time according to a preset time unit;
the preset time unit is a time unit for counting the trip amount, and the preset time unit may be one hour, or half an hour, and this is not specifically limited in the embodiment of the present invention.
And counting the number of trips leaving the traffic cell and arriving at the traffic cell in each unit time according to the determined preset time unit, and combining the number of trips and corresponding time to obtain a time sequence of the number of trips of the traffic cell.
(3) Determining the time series as an original data set;
the time series is determined as the raw data set for subsequent use.
Step 102: determining a training set and a testing set according to an original data set;
in the embodiment of the invention, the original data set is divided into the training set and the test set, wherein the training set is used for training the prediction model subsequently, and the test set is used for testing the trained prediction model so as to test the accuracy of the prediction model.
Specifically, the original data set is divided into a training set and a test set according to a preset proportion, and the preset proportion is the proportion of the training set in the original data set.
Optionally, the predetermined ratio is 0.7-0.8.
Optionally, before the training set and the test set are divided, the format of the original data set is converted into a sample feature format and a sample label format according to a preset time interval, wherein the sample feature format represents an input variable, and the sample label format represents an output variable.
The preset time interval may be selected from 1 to 10 hours, and the specific setting of the preset time interval is not limited in the embodiment of the present invention, and a person skilled in the art may select an appropriate value based on the prediction result.
Step 103: constructing a multilayer LSTM;
in the embodiment of the invention, the neural network is applied to the traffic travel prediction, and the neural network is a mathematical model simulating the structure and the function of a biological neural network and is mainly used for estimating or approximating functions. As an important branch of the neural network model, the recurrent neural network is the primary method of processing sequence data.
Compared with the common recurrent neural network neurons, the neurons of the Long-and-Short-Term Memory neural network (LSTM) comprise a forgetting gate, an input gate and an updating gate, the internal structure of the logic gate can effectively avoid the situations of gradient disappearance and gradient explosion, and the problem of Long-time interval sequence processing is solved.
Referring to FIG. 2a, there is shown the structure of an LSTM neuron, wherein XtFor input data of LSTM cells at time t, htIs the output. In the figure, tanh represents a hyperbolic tangent function, and σ represents a Sigmoid function, which may also be referred to as a logistic regression function or a Sigmoid growth curve function.
The gate function in the LSTM neuron consists of a Sigmoid function that outputs a number between 0 and 1, i.e., an output value between 0 and 1, which is used to describe how much of the throughput is per segment, with 0 representing a complete discard and 1 representing a complete pass, and a point multiplication.
The above-mentioned multilayer LSTM can be constructed by a high-level neural network library, for example: multiple layers of LSTM were constructed by Keras libraries.
Further, the output of the upper layer in the multiple layers of LSTM is the input of the next layer, and each layer of LSTM contains multiple neurons, for example, the number of neurons in each layer is 300.
Further, when prediction is made for one traffic cell, a multi-layer LSTM is constructed, for example, a three-layer LSTM is constructed. When prediction is made for multiple traffic cells, a multi-layer encoding-decoding LSTM is constructed, for example, a three-layer encoding-decoding LSTM is constructed.
It is understood that the number of layers of the multi-layer LSTM may be any number, and those skilled in the art can set the number of layers of the multi-layer LSTM according to actual needs.
Referring to fig. 2b, a schematic diagram of a multi-layer encoding-decoding LSTM structure is shown, wherein the structure of each neuron can refer to the structure of the LSTM neuron shown in fig. 2 a.
The coding refers to converting an input sequence into a vector with a fixed length; the decoding refers to converting the fixed vector generated previously into an output sequence. The codecs used in fig. 2b are all LSTM.
The above multilayer encoding-decoding LSTM has the following features:
(1) in LSTM, the hidden state of the current time is determined by the state of the last time and the current time input;
(2) and after the hidden layers of all time periods are obtained, summarizing the information of the hidden layers to generate a final intermediate vector C.
The last hidden layer is taken as the intermediate vector C in FIG. 2b, i.e.
Since LSTM takes into account the input information of each previous step, the intermediate vector C can contain information of the entire input sequence.
(3) The decoding stage can be seen as the inverse of the encoding. In the decoding process, the output sequence Y is generated according to the intermediate vector C and the previous sequence1,Y2···YT-1To predict the next output YT. In fig. 2b, the last intermediate vector C output by the encoder only acts on the first moment of the decoder;
state of last moment of encoder
I.e. a defined fixed length vector, which will be the initial state of the decoder, in the encoder, at each instantThe output will be the input for the next time instant and so on until the decoder predicts a particular symbol output at a time instant.
Step 104: training the multilayer LSTM through a training set and a testing set to determine model parameters of the multilayer LSTM;
in the embodiment of the invention, the model parameters of the multilayer LSTM are connection weight parameters among the neurons and/or the neural network layers, the multilayer LSTM is trained through multiple groups of data in a training set, the model parameters are gradually adjusted, and the final model parameters are determined when the training is finished.
Optionally, parameters such as a Batch Size (Batch Size), a training iteration number (Epoch) and the like are set in the training process, wherein the Batch Size is the number of samples selected each time, the Batch Size is a value raised to the nth power of 2, and commonly used values include: 64. 128, 256, etc., 256 may be selected when the network is small, and 64 may be selected when the network is large; the number of training iterations is the number of training for all samples, for example, the number of training iterations is 20.
It should be noted that the values of the above parameters are only examples, and those skilled in the art can determine the values of the parameters according to actual requirements.
Optionally, Mean Square Error (Mean Square Error) is chosen as a function of the loss during the multi-layer LSTM training process.
Optionally, Adaptive moment estimation (Adam) is used as a model parameter adjustment rule in the multi-layer LSTM training process.
Step 105: travel prediction is performed by the trained multi-layer LSTM.
In the embodiment of the invention, after the training of the multi-layer LSTM is finished, the trained multi-layer LSTM is used for travel prediction, so that the prediction precision is ensured.
In the embodiment of the invention, the travel quantity of a traffic cell is counted to obtain an original data set, the original data set is divided into a training set and a testing set, a plurality of layers of LSTMs are constructed and trained through the training set and the testing set, model parameters of the plurality of layers of LSTMs are determined, and the travel prediction is carried out through the trained plurality of layers of LSTMs, so that the prediction precision of travel behaviors is improved.
Referring to fig. 3, an embodiment of the present invention provides a travel prediction apparatus 300, including:
a counting module 301, configured to count the number of trips in one or more traffic cells to obtain an original data set;
a first determining module 302, configured to determine a training set and a testing set according to the original data set;
a building module 303 for building a multilayer LSTM;
a second determining module 304, configured to train the multi-layer LSTM through the training set and the test set, and determine model parameters of the multi-layer LSTM;
and a prediction module 305, configured to perform travel prediction through the trained multi-layer LSTM.
Optionally, the statistic module 301 includes:
a mapping unit 3011, configured to map a trip starting point and a trip ending point in the traffic cell;
a first determining unit 3012, configured to determine, according to a preset time unit, a time sequence of leaving the traffic cell and arriving at the traffic cell in each unit time;
a second determining unit 3013, configured to determine the time series as the original data set.
Optionally, the first determining module 302 includes:
a dividing unit 3021, configured to divide the original data set into the training set and the test set according to a preset ratio, where the preset ratio is a ratio of the training set in the original data set.
Optionally, the first determining module 302 further includes:
a conversion unit 3022, configured to convert the format of the original data set into a sample feature format and a sample label format according to a preset time interval;
wherein the sample feature format represents input variables and the sample label format represents output variables.
Optionally, the preset ratio is 0.7 to 0.8.
Optionally, the building module 303 includes:
a first constructing unit 3031, configured to construct a plurality of layers of LSTM when predicting a traffic cell;
a second constructing unit 3032, configured to construct a multi-layer encoding-decoding LSTM when predicting a plurality of traffic cells.
Optionally, the model parameters of the multi-layer LSTM are connection weight parameters between neurons and/or neural network layers.
Optionally, the loss function in the multi-layer LSTM training process is a mean square error function.
Optionally, the model parameter adjustment rule in the multi-layer LSTM training process is Adam algorithm.
In the embodiment of the invention, the travel quantity of a traffic cell is counted to obtain an original data set, the original data set is divided into a training set and a testing set, a plurality of layers of LSTMs are constructed and trained through the training set and the testing set, model parameters of the plurality of layers of LSTMs are determined, and the travel prediction is carried out through the trained plurality of layers of LSTMs, so that the prediction precision of travel behaviors is improved.
The above description is only an embodiment of the present application, but the scope of the present application is not limited thereto, and any changes or substitutions within the technical scope of the present disclosure should be covered by the scope of the present application. Therefore, the protection scope of the present application shall be subject to the protection scope of the claims.