APP下载

Traffic flow prediction of urban road network based on LSTM-RF model

2020-04-28ZHAOShuxuZHANGBaohua

ZHAO Shu-xu, ZHANG Bao-hua

(School of Electronic and Information Engineering, Lanzhou Jiaotong University, Lanzhou 730070, China)

Abstract: Traffic flow prediction, as the basis of signal coordination and travel time prediction, has become a research point in the field of transportation. For traffic flow prediction, researchers have proposed a variety of methods, but most of these methods only use the time domain information of traffic flow data to predict the traffic flow, ignoring the impact of spatial correlation on the prediction of target road segment flow, which leads to poor prediction accuracy. In this paper, a traffic flow prediction model called as long short time memory and random forest (LSTM-RF) was proposed based on the combination model. In the process of traffic flow prediction, the long short time memory (LSTM) model was used to extract the time sequence features of the predicted target road segment. Then, the predicted value of LSTM and the collected information of adjacent upstream and downstream sections were simultaneously used as the input features of the random forest model to analyze the spatial-temporal correlation of traffic flow, so as to obtain the final prediction results. The traffic flow data of 132 urban road sections collected by the license plate recognition system in Guiyang City were tested and verified. The results show that the method is better than the single model in prediction accuracy, and the prediction error is obviously reduced compared with the single model.

Key words: traffic flow prediction; long short time memory and random forest (LSTM-RF) model; random forest; combination model; spatial-temporal correlation

0 Introduction

Transportation is the foundation of urban development. Real-time accurate prediction of traffic flow can effectively alleviate the pressure brought by the increase of motor vehicle ownership on urban traffic in recent years. For traffic flow prediction problem, scholars in various fields have proposed hundreds of prediction methods. These methods can be summarized into two categories: the traffic prediction method based on time domain information, and the traffic prediction method based on spatial information. Typical time-based traffic prediction methods include the historical average forecast[1], time series prediction[2]and Kalman filtering model prediction[3], etc. The essence of this kind of prediction method is to infer the future traffic flow of the target road section through historical data. The second kind of prediction method mainly uses spatial correlation analysis method, and its representative methods include nonparametric regression[4], state space reconstruction[5]and artificial neural network[6], etc. The essence of this method is to predict the traffic condition of the target road section through acquired experience and knowledge. This kind of method has certain adaptability, but the insufficient thinking on the characteristics of traffic flow data leads to low prediction accuracy.

In order to solve the problem that a single model can not accurately reflect the complex features of traffic flow and may ignore the spatial relationship, this paper proposes a traffic flow prediction combination model called as long short time memory and random forest (LSTM-RF), which considers the time-varying, nonlinear, periodic and spatial cross-correlated features of traffic flow. From the point of time domain and space domain, traffic flow data is decomposed into two parts: time autocorrelation and space cross-correlation. And the experiment was carried out by taking the data of 132 urban road sections in Guiyang City.

1 Basic theory

1.1 Temporal characteristics of urban road traffic flow

According to the data analysis, traffic flow data of a specific location or region has some regularity in a certain period of time. For example, the traffic flow data of the same workday, the same rest day or specific periods of the same day in different weeks are similar[7-8]. In addition, unexpected traffic accidents, weather, road conditions and other external factors will also lead to random fluctuations in traffic flow data. These complex characteristics make traffic flow prediction a serious challenge. Ref.[9] shows that the extraction of the hidden periodic change rules in traffic flow data can help people better understand the traffic system and thus obtain more accurate prediction results.

1.2 Spatial characteristics of urban road traffic flow

Urban road network is a closely connected complex network, in which each section is interconnected to the other[10], so each section of traffic flow is not independent. Traffic flow is bound to be constrained by both temporal and spatial information. Therefore, when predicting the traffic flow, we should fully consider the time domain information of the historical data of the traffic flow on the target road section and the spatial information of the upstream and downstream sections of the target road section.

1.3 Correlation analysis

Urban road traffic flow has obvious temporal and spatial characteristics[11]. So when judging the correlation between sections in variable flow state, we should consider not only the temporal correlation, but also the spatial correlation between different sections. In this paper, Pearson correlation coefficient is used to analyze the spatial correlation of urban traffic flow. Assuming that linksAandBhave relationship with upstream and downstream, the correlation degree between them can be calculated by

(1)

wherexAtandxBtare the traffic flow parameters of the two road sections in the period oft, respectively;xAandxBare the average of the two timing data on sectionAandB, respectively;ρis the correlation degree between two time series.

2 Prediction model

2.1 Long short time memory

As an improved model of recurrent neural network (RNN), long short time memory (LSTM) was first proposed by Hochreiter and Schmidhuber in 1997[12]. Its essence is to add the control device to the common RNN, so that the common RNN can effectively process historical information. The key to the LSTM is the “cell state”, which is like a conveyor belt that runs through the chain. All it takes is a little bit of linear manipulation to keep the information flowing through the chain. The “gate” structure enables the LSTM to add or delete information to the “cell state”. Fig.1 shows the “cell state” structure of LSTM.

Fig.1 LSTM “cell state” structure diagram

In Fig.1,stis the input threshold layer used to control the input of information;ftis the forgetting threshold layer for controlling the retention degree of historical information;otis the output threshold layer to control the output of information;σis the sigmoid activation function acting between the three gates; andσhis the tanh activation function.

The essence of LSTM is to control the input and output of information through the cooperation of three gate structures. First, the forgetting gate is used to determine which information needs to be deleted, then the input gate is used to determine how much new information needs to be put into the “cell state”, and finally the information filtered by the “cell state” is output through the output gate. The main working principle of LSTM is expressed as

ft=σ(Wf[ht-1,xt]+bf),

(2)

st=σ(Ws[ht-1,xt]+bs),

(3)

(4)

ot=σ(Wo[ht-1,xt]+bo),

(5)

whereht-1is the output of the previous loop;xtis the input of the current loop;σis sigmoid activation function;σhis tanh activation function;Wf,WsandWcare the weight matrices;bf,bs,bcandboare four biased vectors.

It can be known from the above results that the output of output layer and hidden layer can be calculated by

(6)

ht=ot×σh(Ct).

(7)

The final output of the LSTM layer can be represented by

YT=[hT-n,…,hT-1].

(8)

2.2 Random forest algorithm

Random forest (RF) was proposed by the founder of decision tree in 2001. It uses bootstrap resampling method to sample multiple sub-samples from the original data, establish a decision tree model for each sub-sample, and then combine the prediction results of multiple decision trees to obtain the final prediction results through voting[13-14].

RF is an extended version of Bagging. Bagging is still its main idea, but it has made some unique improvements based on Bagging. First, the basic classifier of RF is CART decision tree and RF adds random attribute selection to the training of decision tree, further increasing the generalization ability of the model. The schematic diagram is shown in Fig.2.

Fig.2 RF schematic diagram

2.3 LSTM-RF

Traditional traffic flow prediction methods usually use historical traffic flow data of target road section to construct the corresponding functions under the assumption that the variance of traffic flow remains unchanged[15], or use the decomposition principle to decompose the collected traffic flow data into intrinsic part and fluctuating part[16]. This decomposition method not only accurately grasps the periodic changes of traffic flow, but also takes into account the traffic fluctuations caused by weather, road emergencies and traffic accidents[17]. This method can clearly get the characteristics of traffic flow and greatly improve the prediction accuracy. However, only considering the temporal correlation of traffic flow data and neglecting its spatial correlation characteristics limit the prediction accuracy of these methods. Urban road network is interconnected, and any point in the network has high spatial accessibility. So the traffic flow between different sections of the urban road network does not exist independently, which is restricted by upstream and downstream. Therefore, this paper proposes LSTM-RF model based on combination model and ensemble learning idea, which takes into account the characteristics of traffic flow data in both time and space domains to improve the prediction accuracy of traffic flow. Fig.3 shows the schematic diagram of the model structure.

Fig.3 Structure diagram of composite model

3 Experiments

In order to verify the advantages of the model proposed in this paper, two single prediction models were selected as comparative experiments. Based on the actual urban road traffic flow data, the experimental verification was carried out. Meanwhile, Explain_variance_score, mean absolute percent error, mean squared error, root mean squared error andR2are used to validate the model.

3.1 Dataset

The dataset used in this experiment was from Guiyang City, Guizhou Province. The dataset was captured by a license plate recognition camera installed on various urban roads of Guiyang City, and collected and stored by the traffic management system. The experiment selected 132 roads in the urban area as the original dataset, from May 1, 2017 to August 1, 2017, with a time interval of 5 min. For the convenience of research, this paper only analyzes the traffic data from Monday to Friday. By analyzing the traffic flow data collected by the license plate recognition system, eleven model features are selected as follows: the current time ofWeekdayindicates the workday;Ft,Ft1andFt2respectively represent flow data of predicted target road section in current time and the first two periods;Fu_t,Fu_t1andFu_t2respectively represent the traffic flow information of upstream target road section at different time periods;Fd_t,Fd_t1andFd_t2respectively represent the traffic flow information of downstream target road section at different time periods; andYrepresents the predicted value of the LSTM model.

3.2 Data analysis

3.2.1 Temporal correlation

The traffic flow is a dynamic process that changes with time[18]. Observing the flow change of the target road segment in different periods can help the researchers to better discover and determine the change rule, and improve the prediction accuracy of the model. In this paper, temporal correlation analysis of urban road traffic flow data collected from different dates in the same week and specific dates in different weeks are carried out.

1) Time series analysis of traffic data for different workdays in a specific week

According to the analysis, the urban road traffic flow has obvious periodicity on workdays. Fig.4 shows the traffic flow raw data of the 5th working day of the 2nd week of May 2017 in a road section of Guiyang City. As seen from Fig.4, the traffic flow of a particular road segment changes periodically within 5 working days in the same week.

Fig.4 Traffic flow on weekdays

In order to better analyze the temporal correlation of traffic flow data, this paper uses the correlation coefficient matrix to analyze the correlation among traffic variables. The elements of columns and rows of correlation coefficient matrix are calculated by

(9)

where cov(xi,yj)=E(xi-E(xi))(yj-E(yj)), and the correlation coefficient matrix is

(10)

As seen from Eq.(10), the coefficient correlation matrix is a symmetric matrix with a diagonal element of 1. Assuming the traffic data matrix is a whole, the equation for calculating the overall correlation coefficient is

(11)

The correlation analysis of traffic flow of 5 working days in the same week is shown in Table 1.

Table 1 Correlation analysis of traffic flow in different working days of the same week

WeekdayMonTueWedThuFriMon1.00.854 70.923 40.912 50.840 5Tue0.854 71.00.847 50.832 70.864 7Wed0.923 40.847 51.00.879 40.941 3Thu0.912 50.832 70.879 41.00.957 2Fri0.840 50.864 70.941 30.957 21.0

As seen from Table 1, the traffic flows among different working days in the same week are highly similar. According to Eq.(11), the overall correlation coefficient of the traffic flow on different days of the same week is 0.885 39, which shows high correlation.

2) Time series analysis of traffic data for a specific day in different week

A section of the traffic flow in Guiyang City was taken as the research object. The traffic flow data for the four consecutive weeks in May 2017 were selected for analysis. Fig.5 represents the traffic flow changes of every Monday in May.

Fig.5 Flow comparison on the same day indifferent weeks

As seen from Fig.5, the traffic flow trend of a particular road section has a strong similarity on the same day in different weeks. The flow similarity of the road section on the same day can be calculated by Eq.(9). The final similarity matrix is shown in Table 2.

Table 2 Correlation analysis of traffic flow on the same working day in different weeks

Week1stMonday2ndMonday3rdMonday4thMonday1st Monday1.00.909 40.953 20.918 52nd Monday0.909 41.00.932 10.905 73rd Monday0.953 20.932 11.00.929 94th Monday0.918 50.905 70.929 91.0

It can be seen from Table 2 that the flow similarity of the road section on the same day is as high as 90%. The overall correlation coefficient is 0.924 8, which shows high correlation.

3.2.2 Spatial correlation

Most of the existing prediction models use timing-related information and have less consideration for spatial correlation. However, Ref.[19] shows that the traffic conditions in the upstream and downstream sections are critical to predict the flow of target section. Predicting the traffic state of the adjacent upstream and downstream of the target road section can indirectly reflect the evolution trend of the future traffic state of the road section. In this paper, the data from the experimental road in 05.08-05.12 was used to analyze the correlation coefficient between the target road section and the adjacent sections. The correlation coefficients obtained through the experiment are shown in Table 3.

Table 3 Correlation analysis of traffic flow between target road section and adjacent road sections

DateFu_t1Fu_t2Fd_t1Fd_t208/050.4520.4280.2320.29309/050.4390.3990.0700.07110/050.5490.4930.1350.14211/050.5390.4910.0800.08312/050.5130.4760.0650.087

It can be seen from Table 4 that the current flowFtof the target section is highly correlated with the upstream section flow of the first two time windowsFu_t1,Fu_t2, and the correlation coefficient reaches 40% or even 50% in most days. While its correlation with the downstream sections is lower.

3.3 Experimental results and evaluation metrics

The training set selected in the experiment is the traffic flow data of a certain road section from May 1, 2017 to July 18, 2017. The test set is the flow data from July 19, 2017 to August 1, 2017. The flow data of a road section of Guiyang City all day (24 h) is predicted, and the sampling interval is 5 min.

To verify the reliability of the model, two single models were used as comparative experiments. The predicted results of the three models are compared with the actual collected data, as shown in Figs.6-8. In order to visually reflect the effects of this model, the loss rates are plotted in Fig.9, and the accuracies of the test data and the train data are present in Fig.10. The analysis shows that the prediction results of the LSTM-RF model are closer to the actual data and can reflect the trend of traffic flow.

Fig.6 Prediction result diagram of LSTM model

Fig.7 Prediction result diagram of RF model

Fig.8 Prediction result diagram of LSTM-RF model

Fig.9 Loss rate comparison of three different models

Fig.10 Prediction accuracy of LSTM-RF model

To test the prediction performance of the LSTM-RF model, LSTM and RF are compared in this experiment. Meanwhile, the following five metrics are used to evaluate the difference between the real traffic data and the prediction,

explained variance score

(12)

mean absolute percent error (MAPE)

(13)

mean squared error (MSE)

(14)

root mean squared error (RMSE)

(15)

coefficient of determination

(16)

Finally, the above five evaluation indicators are compared among the LSTM, RF and LSTM-RF in traffic flow prediction. The results are shown in Table 4. The comparison of the three models shows that the model in this paper is more reliable and stable.

Experiments were carried out on computers with the same configuration (CPU Intel i5-6200, RAM 8 GB), and the comparison of running time is shown in Fig.11. It can be seen from the Fig.11 that under the same conditions, the running time of the LSTM model is the smallest, but its prediction accuracy is also low. The LSTM-RF model proposed in this paper has high prediction accuracy and moderate running time.

Table 4 Flow prediction performance of different models

Fig.11 Running time of LSTM, RF and LSTM-RF

4 Conclusion

In this paper, we took the traffic flow data collected by Guiyang license plate recognition system as the research object, and constructed the LSTM-RF traffic flow prediction model. It is found that the model considering the temporal and spatial correlation of traffic flow is superior to the single prediction model only considering time domain information, and the MAPE value is also significantly reduced. However, the flow data for a specific phase (peak period) has not been discussed in depth. Therefore, the next step will focus on the following two aspects: (1) Improving the model by considering the influence of external factors such as weather, road conditions and traffic restrictions; (2) Analyzing the predictive effect of the model at a specific stage and improving the universality of the model.