Short-term traffic flow prediction based on weather factors analysis and neural network

With the progress of urban transportation infrastructure and the construction of intelligent transportation system, sufficiently accurate traffic flow prediction is of increasing importance for urban planning and management. This paper based on traffic flow data in a section of highway in Los Angeles, USA, we combine external qualitative data such as weather and work calendars, analyze and process the factors significantly influencing traffic flow first, then train and test the traffic flow data by building machine learning Support Vector Regression (SVR) model and the Back Propagation neural network (BP neural network). The test results show that the BP neural network traffic flow prediction model incorporating the external environment is more accurate, and that the external environment has a significant impact on the traffic flow prediction problem. If more significantly influencing factors can be taken into account, or if the current algorithm can be optimized, the prediction accuracy will have further improved, thus effectively enhancing the efficiency and safety of traffic systems.


Introduction
As a result of urbanization and economic growth, the proliferation of privately-owned automobiles within urban areas has exhibited a year-on-year increase, which makes the traffic congestion problem gradually prominent, especially in the morning and evening rush hours.Unreasonable traffic flow distribution often leads to some traffic congestion on important roads, which in turn not only affects commuting efficiency, but also has a negative impact on the economy and road environment, becoming a significant problem for the development of smart cities.
When solving the traffic problems, how to use the obtained multidimensional complex data and select the appropriate model is crucial.So far, there exists a considerable body of previous research on studies on traffic flow prediction.From the early methods of linear prediction [1] to methods based on the clustering [2], and then to Association Rule Mining (ARM) prediction [3], the results gradually tend to be stable.Although these methods are simplistic and efficient, the accuracy of prediction is considered to be weak [4].In fact, short-term prediction is far more valuable than long-term prediction for traffic flow forecasting, which is also more challenging for its uncertainty and susceptibility [5].And with the development of artificial intelligence, machine learning and neural networks, algorithms, the utilization of artificial intelligence techniques for enhanced problem-solving is progressively on the rise within the field and they have also shown greater performance and application prospects than traditional statistical models.
In the same short-term flow prediction problem, an integrated neural network traffic flow prediction method based on BP neural network compensates for the poor generalization performance of neural networks to new sample sets by using Adaboost algorithm to integrate many networks [6].The anomalous traffic flow data screening method based on the random forest missing value filling and isolated forest algorithms improves the problem of repairing anomalous traffic flow data [7].For realtime problem analysis, examples of classification algorithms include K-Nearest Neighbors (KNN) and Support Vector Machine (SVM).It has also been used to crawl spatial image information to obtain results on traffic congestion images [8].The support vector machine regression (SVR) algorithm has predicted aerospace equipment failures and its swarm algorithm has used to predict landslides caused by rainfall, both of which have been shown with excellent accuracy [9,10].More and more machine learning methods are being successfully used to solve flow control problems with increasingly accurate results [11].
Despite the substantial progress made in prior studies, the accuracy of traffic flow prediction tasks has been greatly enhanced, it cannot meet the practical application requirements, which is mainly reflected in the failure to fully consider the impact of weather factors on the traffic flow prediction task.In fact, the change of traffic flow is greatly affected by the weather.For example, good weather will encourage people to travel, while unnecessary outings in extreme weather will be canceled.How to optimize the traffic flow prediction model with weather data is still an outstanding problem.
To mitigate the aforementioned issues, this paper aims to delve deeper into the characteristics that influence traffic flow by building upon existing research.Specifically, we learn characteristic weather features and use them as key information to build traffic prediction models.SVR algorithm in machine learning will be used to implement short-term traffic flow prediction.The study outcome will optimize an algorithm for short-term traffic prediction, whose results can be used to optimize the Intelligent Transport System (ITS) to provide more efficient and accurate information, such as the best route recommendations, thus reducing urban traffic congestion and improving urban transport efficiency and safety.

Primary data acquisition
In this paper, traffic flow data is selected and combined with local meteorological data to establish the forecast model.A1, the time interval used in this article is one hour.The data set was derived from the detector located in Hollywood, Los Angeles County, California, USA.For single-detector short-term traffic flow prediction, detector LDS 714926 was used.The time span is 31 days from January 1, 2023 to January 31, 2023, with 24 time points per day.Four dimensions of vehicle flow, vehicle speed, vehicle occupancy and vehicle driving hours were used.The traffic flow changes over time as shown in Figure 1.

Significant feature selection
Traffic flow is a continuous process, which is cyclical, random, reticulated and spatially and temporally dependent.For short period traffic flows, the data are not only influenced by the values and trends of the previous period, but also traffic flow can be influenced by external factors, such as weather conditions and significant events.The features of traffic flows are divided into two types in this essay.

Extracted features from the flow data.
As shown in Figure 2, the presence of morning and evening peaks on weekdays and other relatively regular and stable traffic trends: traffic flows show a stable timebased cyclical variation under certain conditions, and the training of a large amount of data allows the prediction to automatically meet the conditions of this cyclical variation if the conditions and period are met.

Figure 2.
Daily traffic flow trends during a week.Minor traffic accidents and other unexpected events with a high probability of occurring daily: Although minor traffic accidents such as minor tailgating and cutting are random and unexpected, the sudden fluctuation in traffic flow caused by such events is an obvious feature that can be corrected in time for short-term traffic prediction.In addition, for datasets containing large amounts of traffic data, such incidents are a probability distribution problem that is relatively concentrated at a certain time and spatial scale, and sufficient training allows the prediction results to include consideration of such incidents.

External environment factors.
Weather: Inclement weather such as heavy rain, fog and snow storms can cause problems such as reduced visibility and slippery roads, resulting in a reduction in the overall traffic capacity of the area, which in turn has an impact on traffic flow [12].
Surface obstacles such as accumulated snow: for northern cities, snow days can affect the road conditions for the following several days, which is often a more critical feature than the weather [13], and as the snow melts away a little, the road traffic capacity gradually increases.
Weekday/rest days: Data features that are cyclical in nature may only apply to weekdays or rest days (e.g., morning and evening peaks).In addition, the impact of external factors, such as weather, on traffic flow may differ between weekdays and non-work days.

Relevance analysis.
Spearman correlation analysis is a nonparametric statistical method used to assess the correlation between two variables.Spearman correlation analysis is suitable for situations where the distribution of data is non-normal or uncertain, there are abnormal values or outliers in the data, and the data does not satisfy the linear relationship.This paper studies the impact of short-term traffic flow, weather factors and traffic itself, such as vehicle speed, visibility, lanes, temperature, humidity, precipitation, wind speed and other factors.This data is selected from a section of highway in Los Angeles, USA, and its data meet the requirements of Spearman.This paper conducts a correlation analysis on it, so as to obtain the factors that have a greater impact on traffic flow, so as to select appropriate factors to establish a prediction model.
Initially, the existence of a statistically significant relationship between XY is tested to ascertain whether the p-value indicates significance (p<0.05).If significant, there is a correlation between the two variables, otherwise, there is no correlation between the two variables.Subsequently, the final outcomes involve analyzing the direction (positive or negative) and strength (degree) of the correlation coefficient.The results are presented below in Table 2.

Data pre-processing
In the process of data collection, due to the failure of detection equipment, external environment and other uncertain factors, the data will be abnormal.It is necessary to pre-process the data before using it to ensure the reliability and accuracy of the traffic flow prediction results.3sigma outlier recognition is used in this essay to replace misidentified data with the averages, thus reducing the detrimental effect on the whole model.Since there are significant differences in the volume and dimensionality of the traffic and meteorological data collected at different time periods, normalization is employed to enhance the precision of the prediction model and to facilitate simulation.The partial data after pre-processing is shown in Table 3. (2) where  is the spacing, which means samples in the region between () −  and () +  are considered without loss.
Considering the relaxations  and  ̂, then the SVR problem can be expressed as:  After solving, the expression for the support vector machine regression equation for this problem, (), is derived as: 2.4.2.Back propagation neural network.This essay further utilizes the Back Propagation (BP) neural network, which is a prevalent type of artificial neural network, to re-establish the traffic flow prediction model.The BP neural network relies on the error back-propagation algorithm to train the network, thereby resolving the intricate non-linear problem of traffic flow prediction in this paper.The BP neural network comprises an input layer, a hidden layer, and an output layer, with the possibility of multiple hidden layers.Each layer is composed of numerous neurons, which communicate with each other through connections.In this study, the first hidden layer is comprised of 100 neurons.Each neuron has an activation function, which is used to weight and process the input signal and output it.() is chosen as the Sigmoid function.
Initially, the forward propagation process is executed, allowing the information to enter the network through the input layer and subsequently traversing each layer to obtain the final output layer.This process commences from the input layer and progresses through the hidden layers. ℎ represents the input of the outgoing neuron.
ℎ = ∑  =1  ℎ   +  ℎ , (16) and rom hidden layer to output layer.  represents the input from the hidden layer of neurons.
Finally output the result to the output layer.During training, the error of the network is minimized by adjusting the weights and thresholds between neurons.The calculation error formula () is as follows.
This is accomplished through the utilization of the backpropagation algorithm, which adjusts the connection weight and threshold between each neuron based on the error between the output and actual results, so that the error is continuously reduced, and finally converges to a stable state.In this paper, the gradient descent method is used to perform weight reverse update.
= ()  , (19)   =   +   . (20) Among them,   is for weight. is called the learning rate, which can adjust the update pace, and selecting an appropriate learning rate is essential to ensure that the objective function converges to a local minimum within a reasonable time.BP neural network has strong nonlinear fitting ability and adaptability, and can be used in various fields such as classification, prediction, and identification.The present study employs a maximum of 1000 iterations, and a regularization term of 1 is employed to minimize over-fitting.

Testing results after models training
The data are trained using the SVR and BP neural network methods described above, and the data from the test set are used to predict the flows.Figures 3 and 4

Evaluation indicator analysis
Evaluation index is a method commonly used to evaluate the results of traffic flow prediction model.Commonly used evaluation indexes include mean square error, root mean square error, mean absolute error, mean absolute percentage error and R². = where   means the true value,   ̂ means the predicted value,  ̅  means the average, n means the total number of samples.
Using these evaluation indicators to evaluate the short-term traffic prediction models of SVR and BP neural network algorithms respectively, and the results are shown in Figure 5 and 6.It can be observed that, the SVR can obtain a MAPE of 19.19 and R 2 on the train test, while is similar to results on the test set.This first verifies the generalization ability of model training, that is, the model can quickly and accurately migrate to similar application scenarios.In addition, we also obtain a MSE of 0.004, RMSE of 0.06 and MAE of 0.052 on the train test.All the results demonstrate the effectiveness of our proposed model.The SVR model and BP neural network model trained in this paper are more accurate in predicting traffic flow.In comparison, the BP neural network model is better, which can achieve a performance gain of all five metrics.Taking the MAPE as an example, the MAPE of BP neural network is 7.219, which is about 12 lower than the SVR.This paper explores the reasons for this, which may have the following points: The data characteristics do not conform to the assumption of SVR: SVR assumes that the distribution of data is linear.If the nonlinearity of the data characteristics is high, the performance of SVR may be limited.BP neural network can deal with nonlinear problems.BP neural network has a strong ability to fit data and can handle more complex data characteristics.
Insufficient data volume: This article only uses traffic flow data with a length of one month.SVR needs sufficient data volume to train the model.If the data volume is insufficient, the performance of SVR may decline.The BP neural network has a strong generalization ability and can perform well on small-scale data sets.
Data noise can negatively impact the performance of SVR.To mitigate the effects of noise on the model, the BP neural network can increase the number of layers and nodes of the network.This enables the network to better handle the noise in the data.

Experimental analysis
This model is a traffic flow data prediction model that integrates weather factors.The main characteristic factors include traffic flow itself and local weather factors.On the basis of the previous spearman correlation analysis, this paper conducts experiments to verify which type of data, or which data has a huge impact on the prediction accuracy of the model.
There are three indicators of traffic flow factors, which are vehicle speed, lane occupancy rate and VHT.Among them, VHT refers to vehicle hours (Vehicle Hours Traveled), which is a commonly used indicator in the field of transportation.It is used to indicate the total number of hours of driving of all vehicles in a certain area, road section or transportation network within a specific temporal interval.
This paper takes the SVR model to explore the impact of different feature selections on the prediction model.First of all, this paper ignores the traffic flow factors (vehicle speed, lane occupancy rate and VHT), and explores whether only relying on the influence of weather characteristics can have a good prediction result on traffic flow.As shown in Table 4, this paper found that in the SVR model with only weather features, the prediction result is poor, and the  2 is only about 0.3.When only the traffic flow features exist, the prediction effect is better, and the  2 is about 0.9.When this paper integrates weather features and traffic flow features for model training,  2 can reach about 0.971, and the effect is relatively good.This paper also conducts tests, when more and more traffic flow factors are included, the prediction accuracy gradually increases.In this paper, the spearman correlation analysis carried out above is used to remove features with small correlation coefficients, such as precipitation and sea level air pressure, and further improve the prediction model  2 to about 0.98.Through this experiment, it can be verified that the traffic flow factor is the key factor, and the prediction accuracy can be significantly improved after incorporating the weather factor.

Discussion
This paper is different from the traditional traffic flow forecasting model.This paper innovatively integrates weather features and traffic features to build a model, and fully explains the weather features through feature selection to further improve the prediction accuracy of the model.The data in this paper selects the road and weather conditions of Los Angeles within a month, and processes the data noise through smoothing and outlier detection.In addition to adding more features and then performing feature selection, this paper also optimizes the SVR model by continuously adjusting the kernel function and penalty parameters, and optimizes the BP neural network model by adjusting factors such as the number of neurons, the number of layers, and connection weights.Forecast accuracy continues to improve.During the research process, this paper found that when the BP neural network is processing long sequence data, there is a probability of gradient disappearance and gradient explosion, which leads to a decline in model performance.Therefore, this paper explores and finds that LSTM (long short-term memory network) may be more suitable for the research of this problem.LSTM can process long sequence data and avoid the gradient disappearance problem of BP neural network when processing long sequences.This approach utilizes memory units and gating mechanisms to capture the long-term dependencies present in the sequence, thus making it highly effective in predicting time series data.
In the future, for the research on this issue, on the basis of applying weather factors, LSTM and BP neural network can be integrated to boost the prediction ability of the model.LSTM can be used as a pre-processor to convert time series data into feature vector sequences, and then input them into BP neural network for further processing and prediction.By combining the ability of LSTM to handle sequence data within a specific temporal window and the powerful nonlinear fitting capability of BP neural network, the proposed approach can leverage the strengths of both models to enhance prediction accuracy and stability.

Conclusion
Accurate prediction of traffic flow is crucial for the advancement of intelligent transportation systems and smart cities, with external factors such as weather conditions also impacting traffic flow.To enhance the precision of traffic flow prediction, this study proposes utilizing weather factors as reference indicators for traffic flow prediction, while considering the characteristics of traffic flow and external weather factors, by introducing a traffic flow prediction method based on deep learning SVR and BP neural network.The results of analysis and validation suggest that the BP neural network prediction model combined with weather factors is more effective in predicting traffic flow.
This study is an essential foundation for future research on intelligent transportation systems and smart cities.The combination of weather factors and traffic flow prediction can further enhance the accuracy and comprehensiveness of traffic flow prediction, providing traffic managers with valuable reference and data support for traffic scheduling and planning.In the future, more advanced prediction models can be developed to achieve more efficient and accurate results.

Appendix
Table A1

2. 1 . 1 .
Traffic flow data.Performance Measurement System (PeMS) datasets, developed by the California Department of Transportation, represent the most widely utilized data sources in traffic research due to their intelligent traffic monitoring capabilities.As shown in Table

Figure 1 .
Figure 1.Traffic flow data as at 1 January 2023.

Figure 3 .
Figure 3. Differences between the predicted values by SVR and the true values.

Figure 4 .
Figure 4. Differences between the predicted values by BP neural network and the true values.

Figure 6 .
Figure 6.Evaluation indicator values for BP neural network.The SVR model and BP neural network model trained in this paper are more accurate in predicting traffic flow.In comparison, the BP neural network model is better, which can achieve a performance gain of all five metrics.Taking the MAPE as an example, the MAPE of BP neural network is 7.219, which is about 12 lower than the SVR.This paper explores the reasons for this, which may have the following points:The data characteristics do not conform to the assumption of SVR: SVR assumes that the distribution of data is linear.If the nonlinearity of the data characteristics is high, the performance of SVR may be limited.BP neural network can deal with nonlinear problems.BP neural network has a strong ability to fit data and can handle more complex data characteristics.Insufficient data volume: This article only uses traffic flow data with a length of one month.SVR needs sufficient data volume to train the model.If the data volume is insufficient, the performance of SVR may decline.The BP neural network has a strong generalization ability and can perform well on small-scale data sets.Data noise can negatively impact the performance of SVR.To mitigate the effects of noise on the model, the BP neural network can increase the number of layers and nodes of the network.This enables the network to better handle the noise in the data.

Table 1 .
2.1.2.Weather data.The weather data comes from the National Oceanic and Atmospheric Administration.The data set was derived from the Los Angeles International Airport site in California, USA.As shown in Table1, the time span is 31 days from January 1, 2023 to January 31, 2023.The dry bulb temperature, wet bulb temperature, wind speed, visibility, precipitation and other dimensions were used.Raw partial weather data.

Table 3 .
The partial data after pre-processing.Subsequently, the pre-processed dataset is trained using the Support Vector Regression (SVR) method, and the prediction performance is tested for shortterm traffic flow forecasting.Let the regression equation be () =  + , where  and  are two unknown parameters, then for a training set  = {( 1 ,  1 ), ( 1 ,  1 ), … … , (  ,   )},   ∈ , the value of () should be made as close as possible to the value of  .Considering the loss function, the SVR problem can be expressed as:

Table 4 .
Feature selection results.
. Raw partial traffic flow data.