# Passenger Flow Prediction Using Smart Card Data from Connected Bus System Based on Interpretable XGBoost

Authors: Liang Zou; Sisi Shu; Xiang Lin; Kaisheng Lin; Jiasong Zhu; Linchao Li
Journal: Wireless Communications and Mobile Computing
 (2022)

---

## Abstract

Bus passenger flow prediction is a critical component of advanced transportation information system for public traffic management, control, and dispatch. With the development of artificial intelligence, many previous studies attempted to apply machine learning models to extract comprehensive correlations from transit networks to improve passenger flow prediction accuracy, given that the variety and volume of traffic data have been easily obtained. The passenger flow on a station is highly affected by various factors such as the previous time step, peak hours or nonpeak hours, and extracting the key features from the data is essential for a passenger flow prediction model. Although the neural networks,k-nearest neighbor, and some deep learning models have been adopted to mine the temporal correlations of the passenger flow data, the lack of interpretability of the influenced variables is still a big problem. Classical tree-based models can mine the correlations between variables and rank the importance of each variable. In this study, we presented a method to extract passenger flow of different routes on the station and implemented a XGBoost model to find the contributions of variables to the prediction of passenger flow. Comparing to benchmark models, the proposed model can reach state-of-the-art prediction accuracy and computational efficiency on the real-world dataset. Moreover, the XGBoost model can interpret the predicted results. It can be seen that period is the most important variable for the passenger flow prediction, and so the management of buses during peak hours should be improved.


---

## Body

## 1. Introduction

Passenger flow prediction is important for advanced transportation information system (ATIS) and the planning for multimodal traffic management. A comprehensive classification of historical changing patterns of passenger flow for public bus stations is not only capable of finding the hot spots of public transportation of multimodal traffic network but also able to improve the accuracy of future passenger flow prediction. As a component of ATIS, accurate passenger flow prediction is the prerequisite for dynamic vehicle scheduling and public transport planning. The increasing need for short-term passenger flow prediction embedded in ATIS has led to a large amount of research on passenger flow prediction in the past ten decades. Before the breakthrough of artificial intelligence, passenger flow prediction models have been gradually changing from traditional statistical models to machine learning models. With the exponential growing of computational capability and the volume of traffic data, a large number of deep learning models, such as conventional neural network, recurrent neural network, and their extensions, have been adopted for short-term passenger flow prediction during recent years.However, there are still some challenges in the prediction model. The first question is how to extract accurate passenger flow from the massive bus card data and vehicle operation data. The accurate data is the basic of the prediction model. Moreover, how much each variable contributes to prediction is also a question. There might be several routes at one station, and the buses of the same route could arrive many times during one predicted interval. The competition and complementation are critical factors contributing to the number of passenger flow. Considering the above two variables into current prediction models is necessary.To address the above issues, we propose a new model for bus passenger flow prediction and to rank the influence factors. In this paper, we firstly presented the method to extract the passenger flow from the bus card data and the vehicle operation data. Then, XGBoost can be implemented to mine the temporal correlations in the time series data and find contributions of each variable. In order to learn the correlations between different routes of the same stations and fulfill passenger flow prediction, we take the number of buses arriving on the same routes and different routes into consideration in the prediction model. As tested on a real-world dataset collected from Guangzhou, the introduced preprocess method is effective and XGBoost achieves better predicted accuracy with strong interpretability comparing to existing benchmark models. The contributions of this paper are summarized as follows:(1)
An integral process to extract passenger flow from the raw data is presented. Moreover, a real-world dataset is used to test the proposed model(2)
The interaction between different routes could affect the passenger flow at a specific station. In this study, we consider the number of buses coming during the prediction interval to improve predicted accuracy and measure the influence(3)
Besides improving the accuracy, this study mines the factors from massive bus card data and vehicle operation data affecting passenger flow. The results can contribute to bus station and route planningThe rest of this paper is organized as follows. Section2 discusses the existing literature. Section 3 defines XGBoost-related concepts and describes the methodology in detail. The data preprocessing procedures and evaluation criteria are presented in Section 4. The experimental results are shown in Section 5. Finally, we conclude the paper in Section 6.


## 2. Literature Review

During recent years, a large number of passenger flow prediction models for public transportation have been built. Generally, the prediction model can be divided into two categories: statistic-based models and machine learning-based models. The popular statistic-based models include autoregressive, moving average, and autoregressive moving average model. For example, it is found that Autoregressive Integrated Moving Average Model (ARIMA) has a high accuracy in predicting rail transit passenger flow [1]. Milenković et al. found a strong seasonal autocorrelation in time series and proposed a Seasonal Autoregressive Integrated Moving Average (SARIMA) method to predict railway passenger flow [2]. Tang et al. proposed a short-term passenger flow prediction framework and evaluated its performance with ARIMA, multiple linear regression, and support vector regression [3]. Zhang et al. built a two-step real-time prediction model, which first made rough prediction of bus passenger flow based on historical data, and then calibrated the rough prediction based on the extended Kalman filter (EKF) [4]. Gong et al. put forward a three-stage framework to predict the short-term passenger flow of bus stations. First, arrival passenger count (APC) is predicted based on SARIMA; then, departure passenger count (DPC) is predicted based on event algorithm, and finally, waiting passenger count (WPC) is predicted based on Kalman filter; the APC and DPC are used to update evolution functions in the third step [5]. To improve the reliability of subway passenger flow prediction, Li et al. proposed a hybrid model combining linear ARIMA model and nonlinear symbolic regression [6]; Ding et al. built their models based on joint ARIMA and generalized autoregressive conditional heteroscedasticity (GARCH) [7]. Wang et al. applied a hybrid model combining empirical pattern decomposition (EMD) and ARIMA to predict short-term traffic speeds on highways [8]. Some researchers combined ARIMA with other methods, such as bagging technique [9] and genetic programming [10], for improving prediction accuracy. However, with the increase of the data, the statistic-based models have some limitations. Firstly, the statistic-based models have some strong assumptions which might not be relevant to traffic data, so it is difficult to mine the useful features. Moreover, statistic-based models are not good at handling categorical variables in the massive data.The development of machine learning models gives us some new opportunities to improve passenger flow prediction. For example, Liu et al. designed a new deep learning architecture called modular convolutional neural network based on the experiment of decision tree-based models, to solve the large-scale bus passenger flow prediction problem [11]. Liu and Chen proposed an unsupervised training model based on the combination of stacked autoencoder (SAE) and deep neural network (DNN) to forecast hourly bus passenger flow [12]. Many researchers have studied the subway passenger flow forecast. Li et al. introduced a new dynamic radial basis function neural (RBF) network with dynamic input to predict the outbound passenger flow in subway stations [13]. Zhang et al. combined with Residual Network (ResNet), Graphic Convolutional Network (GCN), and Long and Short-Term Memory (LSTM) put forward a deep learning architecture [14]. Zhao et al. proposed a new three-stage framework based on a hierarchical clustering algorithm (AHC) and tree-based models to select the appropriate feature variables [15]. They proposed a hybrid spatial and temporal deep learning neural network (HSTDL-NET) [16]. Liu et al. developed an end-to-end deep learning architecture based on recurrent neural network (RNN) and LSTM [17]. Hao et al. proposed an end-to-end deep learning framework based on LSTM network to predict the number of passengers getting off at each station in the last few short-term periods [18]. Li et al. proposed a multistation passenger flow prediction method for subway stations, using a dynamic weight combination of Support Vector Machines (SVM) and RBF to improve the stability of the prediction model [19]. Zhang et al. proposed a channel-wise attentive split–convolutional neural network (CAS-CNN) to predict short-term OD flow. This is the first time that the split convolutional neural network is applied to short-term OD prediction in urban rail transit [20]. However, these models have been criticized for their poor interpretability and the need for a great deal of computing resource.The ensemble tree method was developed to solve the above deficiencies and has been widely applied during recent years. For example, Xu et al. [21] and Liu et al. [22] built a Gradient Boosting Decision Tree (GBDT) model to predict the bus passenger flow, so as to make the prediction more accurate. Zhang et al. applied the LightGBM model to predict the subway passenger flow, taking into account the influence of the transfer passenger flow on the prediction [23]. Liu et al. established a passenger flow forecasting model by using Random Forest [24]. In order to further improve the accuracy and efficiency of passenger flow forecasting, researchers combine other methods with ensemble tree model. A new model combining singular spectrum analysis with AdaBoost-weighted extreme learning machine is proposed [25]. Lin and Tian introduced a hybrid model combining Random Forest and LSTM to predict subway passenger flow [26]. Dong et al. proposed a traffic flow prediction model combining wavelet decomposition and reconstruction with the Extreme Gradient Boosting (XGBoost) algorithm [27]. Du et al. used the combined model of XGBoost and LSTM in the short-term traffic prediction of the base station [28]. Yun et al. built a local optimal fusion model based on LSTM, LightGBM, and dynamic regression device [29]. Wang et al. took Multivariable Linear Regression (MLR), k-nearest neighbor (KNN), XGBoost, and Gated Recurrent Unit (GRU) as four seed models to establish a regression integration model to accurately predict short-term passenger flows of urban public transport [30]. The aim of this paper is to develop a prediction using the massive bus card and bus operation data and find the importance of variables for the prediction accuracy, and therefore, XGBoost is implemented.


## 3. Methodology

In 2015, Chen et. al proposed an improved integrated learning algorithm called Extreme Gradient Boosting tree (XGBoost) [31]. Compared with other gradient boosting algorithms, XGBoost has a significant improvement in accuracy and speed for regression and classification problems, because the model can integrate multiple regression trees to make decisions under the framework of boosting. In this section, the theory of XGBoost will be introduced.


### 3.1. Regression Tree

Regression tree is a binary tree to solve regression problems. Assuming the built regression tree hasT leaf nodes, so the regression tree divides the input space into T units asR1,R2,⋯,RT. The formulation of regression tree model can be expressed as
(1)fx=∑j=1TwjIx∈Rj,where x is the sample; fx is the prediction value; Ix is the identify function which will return 1 if x is in the subset Rj; and w is the output value on the divided unit. To divide the input space best, the square error can be used to represent the prediction error of the training data which can be expressed as
(2)Squareerror=∑xi∈Rjyi−fxi2,where yi is the ith predicted value; to minimize the overall error of regression tree, it is only necessary to set the predicted value in each unit area to the mean value of the output of the sample set contained in the area:
(3)w^j=aveyi∣xi∈Rj,where avex is the function to obtain the average value of x. The details of the optimal procedure are described as below. Firstly, in the input space of the training data set, the dth feature xd and the corresponding value s is selected for each division. After dividing into two subregions, the samples with feature values less than s are divided into the left subtree, and the samples with feature values greater than s are divided into the right subtree:
(4)R1d,s=x∣xd≤s,R2d,s=x∣xd>s.Then, all input variables are traversed to find the optimal segmentation featurej and the optimal segmentation point s, constituting one pair d,s, by minimizing the loss function of the two subregions:
(5)mind,sminc1∑xi∈R1d,syi−w12+minc2∑xi∈R2d,syi−w22.Finally, the output value of each subregion can be determined by(6)w^1=aveyi∣xi∈R1d,s,w^2=aveyi∣xi∈R2d,s.The above process for the division of the input space is repeated until the division cannot be continued.


### 3.2. The Integration Process of the XGBoost Model

Boosting is an additive model and one of the methods for ensemble learning which complete learning tasks by constructing and combining multiple learners. There is a strong dependency between these individual learners, which must be generated serially, and each weak learner must be upgraded to a strong learner to reduce the bias of the model. XGBoost is one of the tree-based ensemble learning which grows a tree by continuously adding regression tree and splitting features. Each time, a tree is added, and the model learns a new function to fit the residual of the previous tree prediction; that is, thetth regression tree is obtained by training based on the model of the previous t−1 iterations. After the training is completed and t trees are obtained, the predicted value of each sample is obtained by falling into the corresponding leaf node of each tree according to the characteristics of the sample. The model obtained after the tth iteration is
(7)y^i0=0,y^it=∑k=1tfkxi=y^it−1+ftxi,where y^it is the predicted value of the ith sample in the tth round of the model, y^it−1 is the score of the ith sample in the model retained for the previous t−1 round, and ftxi is the score of the ith sample newly added to the regression tree. The detail of the model for passenger prediction is introduced in the following part.Assuming that the XGBoost model integratesK trees, the predicted value of each sample is
(8)yi=∑k=1Kfkxi,fk∈F,where F is the set of all regression trees and f is one of the regression trees in F. The integration process of the XGBoost model is illustrated in Figure 1.Figure 1
The integration process of the XGBoost model.In the passenger flow prediction problem, the goal is to find a suitable model and continuously optimize the parameters to minimize the difference between prediction and observation. Therefore, this paper defines the objective function of the XGBoost model and minimizes the objective function to find the best parameters.The objective function of the XGBoost model in this paper is expressed as(9)obj=∑i=1nlyi,y^it+∑k=1KΩfk.The objective function has two parts. The first part∑i=1nlyi,y^it is the loss function, which measures the fitting effect of the model on the training set. The smaller the value of the loss function, the better the fitting effect. The latter part ∑k=1KΩfk is the regular term, which measures the complexity of the model. Optimizing the regular term can avoid the weak generalization ability. The regular term Ωfk is expressed as
(10)Ωfk=γT+12λ∑j=1Twj2,where T is the number of leaf nodes of the tree, wj is the score of the jth leaf node, γT represents the complexity of the number of leaf nodes of the tree, λ∑j=1Twj2 represents the regular term of L2, and γ is the coefficient that controls the number of leaf nodes.The objective function of the XGBoost model obtained after thetth iteration is expressed as
(11)objt=∑i=1nlyi,y^it+∑k=1tΩfk=∑i=1nlyi,y^it−1+ftxi+Ωft+constant,where constant is the regularization penalty term of the previous t−1 iterations.After performing the second-order Taylor expansion on the error term of the objective function, the algorithm can be updated as(12)objt≈∑i=1nlyi,y^it−1+giftxi+12hift2xi+Ωft+constant,where gi is the first derivative of the error function and hi is the second partial derivative of the error function. The expressions are shown as follows:
(13)gi=∂y^it−1lyi,y^it−1,hi=∂y^it−12yi,y^it−1.Since the error term and regular term of the previoust−1 iterations are constant terms, they have no effect on the optimization of the objective function of the tth iteration, so they can be omitted. The simplified objective function of the tth iteration is
(14)objt≈∑i=1ngiftxi+12hift2xi+Ωft.In regression trees, the score of the sample will eventually fall into one leaf node, so it can be a collection of all samples of the same node. The mapping function of regression tree can be transformed into(15)ftxi=wqxi,w∈RT,q:Rd⟶1,2,⋯,T,where wq represents the sum of all sample scores of the qth leaf node.So far, the objective function can be expressed as follows:(16)objt≈∑i=1ngiftxi+12hift2xi+Ωft=∑i=1ngiwqxi+12hiwq2xi+γT+12λ∑j=1Twj2=∑j=1T∑i∈Ijgiwj+12∑i∈Ijhi+λwj2+γT=∑j=1TGjwj+12Hj+λwj2.Some definitions of the above formula are(17)Gj=∑i∈Ijgi,Hj=∑i∈Ijhi.Through the above formula, the problem of minimizing the objective function is transformed into a problem of finding the extreme value of a quadratic equation of one variable about the fractionw of leaf nodes. Therefore, the best score of the leaf nodes is
(18)wj∗=−GjHj+λ.Then, the objective function corresponding to this best score is(19)objt=−12∑j=1TGj2Hj+λ+γT.Equation (19) is the score of the tree structure in which objt is a function for scoring the tree structure. The lower the score, the better the tree structure.When the XGBoost model traverses all the feature points and splits the tree nodes, it uses the above objective function as the evaluation function. If the total value of the objective function of the left and right subtrees after the split is increased compared with the original and the increase value is greater than a certain threshold, the split point that can obtain the maximum value of the objective function would be found continuously. If the point does not exist, no split is performed. This maximum value of the objective function is the gain. Int iterations, when splitting a leaf node, the gain before and after splitting is defined as
(20)Gain=12GL2HL+λ+GR2HR+λ−GL+GR2HL+HR+λ−γ,where the first part in brackets is the score of the left subtree after the split, the second part in brackets is the score of the right subtree after the split, and the third part in brackets is the score before the split. γ represents the cost value of the complexity by adding a leaf node. The larger the value of Gain, the lower the value of the objective function after splitting, and the better the tree structure.


## 3.1. Regression Tree

Regression tree is a binary tree to solve regression problems. Assuming the built regression tree hasT leaf nodes, so the regression tree divides the input space into T units asR1,R2,⋯,RT. The formulation of regression tree model can be expressed as
(1)fx=∑j=1TwjIx∈Rj,where x is the sample; fx is the prediction value; Ix is the identify function which will return 1 if x is in the subset Rj; and w is the output value on the divided unit. To divide the input space best, the square error can be used to represent the prediction error of the training data which can be expressed as
(2)Squareerror=∑xi∈Rjyi−fxi2,where yi is the ith predicted value; to minimize the overall error of regression tree, it is only necessary to set the predicted value in each unit area to the mean value of the output of the sample set contained in the area:
(3)w^j=aveyi∣xi∈Rj,where avex is the function to obtain the average value of x. The details of the optimal procedure are described as below. Firstly, in the input space of the training data set, the dth feature xd and the corresponding value s is selected for each division. After dividing into two subregions, the samples with feature values less than s are divided into the left subtree, and the samples with feature values greater than s are divided into the right subtree:
(4)R1d,s=x∣xd≤s,R2d,s=x∣xd>s.Then, all input variables are traversed to find the optimal segmentation featurej and the optimal segmentation point s, constituting one pair d,s, by minimizing the loss function of the two subregions:
(5)mind,sminc1∑xi∈R1d,syi−w12+minc2∑xi∈R2d,syi−w22.Finally, the output value of each subregion can be determined by(6)w^1=aveyi∣xi∈R1d,s,w^2=aveyi∣xi∈R2d,s.The above process for the division of the input space is repeated until the division cannot be continued.


## 3.2. The Integration Process of the XGBoost Model

Boosting is an additive model and one of the methods for ensemble learning which complete learning tasks by constructing and combining multiple learners. There is a strong dependency between these individual learners, which must be generated serially, and each weak learner must be upgraded to a strong learner to reduce the bias of the model. XGBoost is one of the tree-based ensemble learning which grows a tree by continuously adding regression tree and splitting features. Each time, a tree is added, and the model learns a new function to fit the residual of the previous tree prediction; that is, thetth regression tree is obtained by training based on the model of the previous t−1 iterations. After the training is completed and t trees are obtained, the predicted value of each sample is obtained by falling into the corresponding leaf node of each tree according to the characteristics of the sample. The model obtained after the tth iteration is
(7)y^i0=0,y^it=∑k=1tfkxi=y^it−1+ftxi,where y^it is the predicted value of the ith sample in the tth round of the model, y^it−1 is the score of the ith sample in the model retained for the previous t−1 round, and ftxi is the score of the ith sample newly added to the regression tree. The detail of the model for passenger prediction is introduced in the following part.Assuming that the XGBoost model integratesK trees, the predicted value of each sample is
(8)yi=∑k=1Kfkxi,fk∈F,where F is the set of all regression trees and f is one of the regression trees in F. The integration process of the XGBoost model is illustrated in Figure 1.Figure 1
The integration process of the XGBoost model.In the passenger flow prediction problem, the goal is to find a suitable model and continuously optimize the parameters to minimize the difference between prediction and observation. Therefore, this paper defines the objective function of the XGBoost model and minimizes the objective function to find the best parameters.The objective function of the XGBoost model in this paper is expressed as(9)obj=∑i=1nlyi,y^it+∑k=1KΩfk.The objective function has two parts. The first part∑i=1nlyi,y^it is the loss function, which measures the fitting effect of the model on the training set. The smaller the value of the loss function, the better the fitting effect. The latter part ∑k=1KΩfk is the regular term, which measures the complexity of the model. Optimizing the regular term can avoid the weak generalization ability. The regular term Ωfk is expressed as
(10)Ωfk=γT+12λ∑j=1Twj2,where T is the number of leaf nodes of the tree, wj is the score of the jth leaf node, γT represents the complexity of the number of leaf nodes of the tree, λ∑j=1Twj2 represents the regular term of L2, and γ is the coefficient that controls the number of leaf nodes.The objective function of the XGBoost model obtained after thetth iteration is expressed as
(11)objt=∑i=1nlyi,y^it+∑k=1tΩfk=∑i=1nlyi,y^it−1+ftxi+Ωft+constant,where constant is the regularization penalty term of the previous t−1 iterations.After performing the second-order Taylor expansion on the error term of the objective function, the algorithm can be updated as(12)objt≈∑i=1nlyi,y^it−1+giftxi+12hift2xi+Ωft+constant,where gi is the first derivative of the error function and hi is the second partial derivative of the error function. The expressions are shown as follows:
(13)gi=∂y^it−1lyi,y^it−1,hi=∂y^it−12yi,y^it−1.Since the error term and regular term of the previoust−1 iterations are constant terms, they have no effect on the optimization of the objective function of the tth iteration, so they can be omitted. The simplified objective function of the tth iteration is
(14)objt≈∑i=1ngiftxi+12hift2xi+Ωft.In regression trees, the score of the sample will eventually fall into one leaf node, so it can be a collection of all samples of the same node. The mapping function of regression tree can be transformed into(15)ftxi=wqxi,w∈RT,q:Rd⟶1,2,⋯,T,where wq represents the sum of all sample scores of the qth leaf node.So far, the objective function can be expressed as follows:(16)objt≈∑i=1ngiftxi+12hift2xi+Ωft=∑i=1ngiwqxi+12hiwq2xi+γT+12λ∑j=1Twj2=∑j=1T∑i∈Ijgiwj+12∑i∈Ijhi+λwj2+γT=∑j=1TGjwj+12Hj+λwj2.Some definitions of the above formula are(17)Gj=∑i∈Ijgi,Hj=∑i∈Ijhi.Through the above formula, the problem of minimizing the objective function is transformed into a problem of finding the extreme value of a quadratic equation of one variable about the fractionw of leaf nodes. Therefore, the best score of the leaf nodes is
(18)wj∗=−GjHj+λ.Then, the objective function corresponding to this best score is(19)objt=−12∑j=1TGj2Hj+λ+γT.Equation (19) is the score of the tree structure in which objt is a function for scoring the tree structure. The lower the score, the better the tree structure.When the XGBoost model traverses all the feature points and splits the tree nodes, it uses the above objective function as the evaluation function. If the total value of the objective function of the left and right subtrees after the split is increased compared with the original and the increase value is greater than a certain threshold, the split point that can obtain the maximum value of the objective function would be found continuously. If the point does not exist, no split is performed. This maximum value of the objective function is the gain. Int iterations, when splitting a leaf node, the gain before and after splitting is defined as
(20)Gain=12GL2HL+λ+GR2HR+λ−GL+GR2HL+HR+λ−γ,where the first part in brackets is the score of the left subtree after the split, the second part in brackets is the score of the right subtree after the split, and the third part in brackets is the score before the split. γ represents the cost value of the complexity by adding a leaf node. The larger the value of Gain, the lower the value of the objective function after splitting, and the better the tree structure.


## 4. Data and Evaluation Criteria

### 4.1. The Format of Raw Data

In this study, the bus card data and vehicle operation data of 30 bus stations in Guangzhou from April 24 to May 20, 2018, were selected to evaluate the performance of the model. The formats of bus card data and vehicle operation data are listed in Tables1 and 2, respectively. From the raw data, the passenger flow cannot be obtained directly. Therefore, we need to match the bus card data with the vehicle operation data. In this paper, bus card data and vehicle operation data are matched using vehicle ID number. The format of the matched data is shown in Table 3.Table 1
The format of the bus card data.
NameDescriptionBus_noVehicle ID numberCardtypeThe type of cardLinenoBus line numberLogiccardnoCard IDTimBus card trading hoursTable 2
The format of the bus operation data.
NameDescriptionIDVehicle itinerary IDOBUIDVehicle ID numberROUTE_IDBus route IDROUTE_CODEBus route codeROUTE_NAMEBus route nameSERVICE_NUMBERUp or downTRIP_IDBus work shifts IDBUS_STOP_CODEBus stop codeROUTE_STA_IDThe ID of the bus stopSTATION_IDThe ID of the route stationSTATION_NAMEThe name of the bus stopAD_FLAGInbound or outboundAD_TIMEInbound or outbound timeTable 3
The format of the matched data.
NameExamplesLogiccardno5100000326361642Tim20180731000000BUSID1805210000069477OBUID989416ROUTE_ID765SERVICE_NUMBER0TRIP_ID001BUS_STOP_CODE211203ROUTE_STA_ID89500STATION_ID100004932STATION_NAMEHengjiao StationAD_FLAG0AD_TIME2018-05-21 00:00:06


### 4.2. The Preprocess of Data

From the raw dataset, we cannot get the number of passengers at a specific station during a prediction interval (30 min in this study), because the bus card data cannot reflect the actual arrival time of passengers. To obtain the real passenger flow data as much as possible, the arrival of passengers was assumed to follow a uniform distribution pattern according to previous studies. On the basis of this assumption, the number of passengers boarding the vehicle at a station is evenly distributed from the departure of the previous bus to the arrival of the current bus. The specific process of passenger flow calculation is as follows:Input: the specific route ID, the site ID, and the matched data in Table 3Output: the short-term passenger flow of the siteProcess: according to the data of the selected station in the selected bus route, find out the data corresponding to different bus work shifts, get the interval time of different bus work shifts and the number of passengers, distribute the number of passengers evenly to the interval time, and then, get short-term passenger flow data after accumulation. For the convenience of analysis, the prediction interval T of short-term passenger flow is set to 30 minutes. The process of passenger flow calculation is shown in Figure 2. According to the above calculation process, a total of 756 short-term passenger flow data for each route at a single station from 7 am to 9 pm every 30 minutes are calculated.Figure 2
The process of passenger flow calculation.


### 4.3. Evaluation Criteria

Mean absolute percentage error (MAPE), root mean square error (RMSE), and mean absolute error (MAE) have been commonly used as evaluation criteria in previous studies that can measure the quality of prediction models. The calculated time (TIME) is an evaluation index to measure the computational efficiency of prediction models.The formulas of MAPE, RMSE, MAE, and TIME are as follows:(21)MAPE=100%n∑i=1ny^i−yiy^i,(22)RMSE=1n∑i=1ny∧i−yi2,(23)MAE=1n∑i=1ny^i−yi,(24)TIME=Tend−Tstart,where n is the number of samples, y^i is the true value, yi is the predicted value, and Tstart and Tend represent the time when the model calculation starts and ends, respectively. The range of MAPE is [0, +∞). When the value of MAPE is 0%, it means there is no error. Root mean square error (RMSE) reflects the magnitude of the deviation between the predicted value and the true value. The unit of TIME is second.


## 4.1. The Format of Raw Data

In this study, the bus card data and vehicle operation data of 30 bus stations in Guangzhou from April 24 to May 20, 2018, were selected to evaluate the performance of the model. The formats of bus card data and vehicle operation data are listed in Tables1 and 2, respectively. From the raw data, the passenger flow cannot be obtained directly. Therefore, we need to match the bus card data with the vehicle operation data. In this paper, bus card data and vehicle operation data are matched using vehicle ID number. The format of the matched data is shown in Table 3.Table 1
The format of the bus card data.
NameDescriptionBus_noVehicle ID numberCardtypeThe type of cardLinenoBus line numberLogiccardnoCard IDTimBus card trading hoursTable 2
The format of the bus operation data.
NameDescriptionIDVehicle itinerary IDOBUIDVehicle ID numberROUTE_IDBus route IDROUTE_CODEBus route codeROUTE_NAMEBus route nameSERVICE_NUMBERUp or downTRIP_IDBus work shifts IDBUS_STOP_CODEBus stop codeROUTE_STA_IDThe ID of the bus stopSTATION_IDThe ID of the route stationSTATION_NAMEThe name of the bus stopAD_FLAGInbound or outboundAD_TIMEInbound or outbound timeTable 3
The format of the matched data.
NameExamplesLogiccardno5100000326361642Tim20180731000000BUSID1805210000069477OBUID989416ROUTE_ID765SERVICE_NUMBER0TRIP_ID001BUS_STOP_CODE211203ROUTE_STA_ID89500STATION_ID100004932STATION_NAMEHengjiao StationAD_FLAG0AD_TIME2018-05-21 00:00:06


## 4.2. The Preprocess of Data

From the raw dataset, we cannot get the number of passengers at a specific station during a prediction interval (30 min in this study), because the bus card data cannot reflect the actual arrival time of passengers. To obtain the real passenger flow data as much as possible, the arrival of passengers was assumed to follow a uniform distribution pattern according to previous studies. On the basis of this assumption, the number of passengers boarding the vehicle at a station is evenly distributed from the departure of the previous bus to the arrival of the current bus. The specific process of passenger flow calculation is as follows:Input: the specific route ID, the site ID, and the matched data in Table 3Output: the short-term passenger flow of the siteProcess: according to the data of the selected station in the selected bus route, find out the data corresponding to different bus work shifts, get the interval time of different bus work shifts and the number of passengers, distribute the number of passengers evenly to the interval time, and then, get short-term passenger flow data after accumulation. For the convenience of analysis, the prediction interval T of short-term passenger flow is set to 30 minutes. The process of passenger flow calculation is shown in Figure 2. According to the above calculation process, a total of 756 short-term passenger flow data for each route at a single station from 7 am to 9 pm every 30 minutes are calculated.Figure 2
The process of passenger flow calculation.


## 4.3. Evaluation Criteria

Mean absolute percentage error (MAPE), root mean square error (RMSE), and mean absolute error (MAE) have been commonly used as evaluation criteria in previous studies that can measure the quality of prediction models. The calculated time (TIME) is an evaluation index to measure the computational efficiency of prediction models.The formulas of MAPE, RMSE, MAE, and TIME are as follows:(21)MAPE=100%n∑i=1ny^i−yiy^i,(22)RMSE=1n∑i=1ny∧i−yi2,(23)MAE=1n∑i=1ny^i−yi,(24)TIME=Tend−Tstart,where n is the number of samples, y^i is the true value, yi is the predicted value, and Tstart and Tend represent the time when the model calculation starts and ends, respectively. The range of MAPE is [0, +∞). When the value of MAPE is 0%, it means there is no error. Root mean square error (RMSE) reflects the magnitude of the deviation between the predicted value and the true value. The unit of TIME is second.


## 5. Results

### 5.1. Optimization of the Prediction Model

#### 5.1.1. Input Variable Selection

Period. The distributions of the short-term passenger flow of buses are shown in Figure 3. It can be seen that the passenger flow of most routes is higher in the peak hours than nonpeak hours. The passenger flow of bus changes dynamically for one day; however, it shows a similar change between workday and weekend. The change of passenger flow in the weekend is different from that of workdays. It has also been proved by previous studies. Therefore, weekend or workday is also taken into consideration in the prediction model.Figure 3
Time distribution of short-term passenger flow.Passenger flow of previous period. The closest thing to the current state of passenger flow is the passenger flow of the adjacent previous period, and the short-term passenger flow of bus is related to the number of passenger flow of the adjacent previous period.The number of buses arriving on the predicted routes during the prediction interval. According to the calculation of passenger flow, it can be seen that there are fluctuations in the short-term passenger flow of conventional buses. In a prediction interval, the number of buses arriving of the same routes is higher than in the past and also is more than different considered routes, so the probability of passengers taking this route is higher than in the past; that is, the passenger flow on this route increases; otherwise, it decreases.The number of buses arriving on the other routes during the prediction interval. In this article, some routes that have successively repeated sites on a route are called different routes into consideration. In real life, passengers usually consider the different routes that arrive at the station first when taking a bus. The more buses on the different routes into consideration arrive, the more passenger flow will be divided, and the smaller the passenger flow of the select route.In the end, period, workday or weekend, passenger flow of previous period, the number of buses arriving on the predicted routes during the prediction interval, and the number of buses arriving on the other routes during the prediction interval are selected as the feature input of the conventional short-term passenger flow prediction model based on the XGBoost model.


#### 5.1.2. Model Parameter Settings

The parameters of the XGBoost model include general parameters, lifting parameters, and learning task parameters. The general parameters control the overall function. The learning task parameters guide the model to perform optimization. The promotion parameters control the regression tree at each step. The general parameters and learning task parameters of the XGBoost model includebooster, objective, and eval_metric as shown in Table 4. The goal of predicting passenger flow is a regression problem, and so the base learner of the XGBoost model used in this article is a regression tree. RMSE is used to evaluate the accuracy of the model.Table 4
Selection of general parameters and learning task parameters.
ParametersValueBoostergbtreeObjectivereg: lineareval_metricRMSEThe lifting parameters are selected using a grid search method. Take the process of adjusting the parametern_estimators as an example. The candidate values of n_estimators are 200, 300, 400, 500, and 600. Firstly, we change the value of n_estimators, while the other parameters remain unchanged, and we use cross-validation and RMSE to measure the performance of models. Then, the best parameter value is selected. According to RMSE, the optimal n_estimators is 300. According to the above steps, the following parameters of a forecast model of this route are selected in turn: min_child_weight, max_depth, gamma, subsample, subsample_bytree, reg_alpha, reg_lambda, learning_rate. The optimal values are shown in Table 5.Table 5
The best value of each parameter.
ParametersValueLearning_rate0.01n_estimators300max_depth8min_child_weight4Subsample0.8colsample_bytree0.8Gamma0.1reg_alpha1reg_lambda1After adjusting all the parameters, the construction of the short-term passenger flow prediction model for conventional public transportation based on the XGBoost model has been completed.


### 5.2. Comparison with Traditional Model

Currently, there are many prediction models for short-term passenger flow of conventional public transportation. Among them, the models that can perform multivariable short-term passenger flow prediction mainly include KNN, BP neural network, and LSTM. To show the better prediction effect of the proposed model, KNN, the BP neural network, and LSTM are established as benchmark models. Meanwhile, an XGBoost predicted model without the number of buses arriving is also implemented.


#### 5.2.1. KNN Regression Model

Usesklearn.neighbors.KNeighborsRegressor in Python to build a short-term passenger flow prediction model for conventional public transportation based on KNN regression. In the KNN regression model, the key parameters are n_neighbor and weight. Take No. 125 bus at the station of Zhongshan 8th Road Station Substation 1 as an example, and finally, get the value of n_neighbor as 5 and weight as uniform through training.


#### 5.2.2. BP Neural Network Model

Thekeras deep learning framework is used to build a short-term passenger flow prediction model for conventional public transportation based on BP neural network. Take the 125 bus at the substation of Zhongshan 8th Road Station as an example. After repeated experiments, the number of input layer nodes of the BP neural network model is selected as 70, the number of hidden layer nodes is 30, and the number of output layer nodes is 1; that is, the model structure is 70-30-1. Among them, the activation function of the hidden layer and the output layer is selected as the relu function. In addition, the number of iterations of the BP neural network is selected as 200, and the learning rate is 0.01.


#### 5.2.3. LSTM Model

Thekeras deep learning framework is used to build a short-term passenger flow prediction model for conventional public transportation based on LSTM. Take the 125 bus at the substation of Zhongshan 8th Road Station as an example. After repeated trials, the number of input layer nodes of the selected LSTM model is 20, the number of hidden layer nodes is 15, the number of output layer nodes is 1, the step size is 4, the activation function of the hidden layer and the output layer is the relu function, and the optimizer is adam. In addition, the number of iterations of LSTM is 50 times.


#### 5.2.4. XGBoost Model without the Number of Buses Arriving

Taking the 125 bus at the substation of Zhongshan 8th Road Station as an example, the best values of its parameters are shown in Table6.Table 6
The best value of each parameter of XGBoost without the number of buses arriving.
ParametersValueLearning_rate0.01n_estimators350max_depth8min_child_weight4Subsample0.8colsample_bytree0.8Gamma0.1reg_alpha1reg_lambda1The MAPE, RMSE, and MAE of the above prediction models for each bus route are shown in Figure4. It can be clearly seen that, regardless of indicators MAE, MAPE, or RMSE, the proposed model has the lowest value among most stations. For a quantitative analysis of the prediction results, Table 6 shows the comparison of the average values of the evaluation indicators of five prediction models.Figure 4
(a) MAPE results of 30 bus stations in five models. (b) RMSE results of 30 bus stations in five models. (c) MAE results of 30 bus stations in five models.
(a)(b)(c)From Table7, the proposed model has higher accuracy than other models, and the number of buses arriving as a feature input can improve the prediction effect of the XGBoost model. Among them, the accuracy of the proposed model is better than that of the KNN regression model and the BP neural network model, and it is significantly better than the XGBoost model without the number of buses arriving.Table 7
Comparison of the average value of the evaluation indicators of 30 bus stations.
ModelMAPE (%)RMSEMAETime (s)The proposed model42.904.763.5310.63XGBoost model without the number of buses arriving55.865.464.08—KNN regression model61.086.034.4411.78BP neural network model50.855.704.3140.21LSTM model44.116.174.6328.15The calculation time of the XGBoost model is slightly shorter than that of the KNN regression model, and it is much lower than the calculation time of the BP neural network model and the LSTM model. It is concluded that the XGBoost model is faster than the KNN regression model, BP neural network model, and LSTM model.


### 5.3. Robustness of the Model

To evaluate the robustness, we compare the performance of the proposed model.


#### 5.3.1. Analysis by Time Period

Firstly, the accuracy of the proposed model is compared under different time periods: peak hours and nonpeak hours. The results are shown in Table8. It can be seen that the MAPE of the proposed model during peak hours is significantly better than that during low peak periods. This may be caused by its relatively stable passenger flow distribution during peak hours which has less volatility and less influence by various factors. But at the same time, the absolute error (RMSE and MAE) in the low-peak period is relatively low. This is because the passenger flow in the low-peak period is much smaller than that in the peak period. It can be seen that the proposed model has a good prediction effect during peak hours.Table 8
Comparison of the average value of the evaluation index under the peak hours and the nonpeak hours.
Type of time periodMAPE (%)RMSEMAEPeak hours30.269.988.9Nonpeak hours43.93.762.95


#### 5.3.2. Analysis by the Type of Passenger Flow Distribution

Secondly, the accuracy of the proposed model is compared under different distributions. The distributions of passenger flow are divided as unimodal type, bimodal type, and other type. The comparison results are shown in Table9.Table 9
Comparison of the average value of evaluation indicators under different passenger flow types.
Passenger flow typeMAPE (%)RMSEMAEUnimodal type45.594.553.48Bimodal type43.264.683.42Other types39.855.073.69It can be seen that in the proposed model for the three types of passenger flow distribution, the prediction accuracy (MAPE) of the other types is better than that of the single-peak and double-peak types. This may be due to the fact that other types include multipeak passenger flow distribution types, which have more peak hours, and the passenger flow distribution during peak hours with less volatility is relatively stable and has been less affected by various factors. In general, other types of prediction accuracy are higher. The absolute error (RMSE and MAE) of other types is lower, which may be due to the fact that the average short-term passenger flow of other types is higher than that of the single-peak type and the double-peak type.


### 5.4. Influence Degree of Variables

For different stations, different XGBoost prediction models are built. We have analyzed the weight of each variable contributing to the passenger flow prediction. It can be found that the contribution of variables of different routes is similar, and so we use the average of the routes to take further analysis. The result is shown in Figure5. It can be seen that period contributes the most among all variables and following is the date type indicating the temporal correlation is strong in passenger flow data. Interestingly, the contribution of buses from other routes is greater than that of buses from the same route, indicating the competition between different routes is fierce. Also, the importance of other routes for the prediction is different. To mine the relationship between different routes should be worthy of study and concerns in the future work.Figure 5
Feature importance score of the prediction model of 30 routes.


## 5.1. Optimization of the Prediction Model

### 5.1.1. Input Variable Selection

Period. The distributions of the short-term passenger flow of buses are shown in Figure 3. It can be seen that the passenger flow of most routes is higher in the peak hours than nonpeak hours. The passenger flow of bus changes dynamically for one day; however, it shows a similar change between workday and weekend. The change of passenger flow in the weekend is different from that of workdays. It has also been proved by previous studies. Therefore, weekend or workday is also taken into consideration in the prediction model.Figure 3
Time distribution of short-term passenger flow.Passenger flow of previous period. The closest thing to the current state of passenger flow is the passenger flow of the adjacent previous period, and the short-term passenger flow of bus is related to the number of passenger flow of the adjacent previous period.The number of buses arriving on the predicted routes during the prediction interval. According to the calculation of passenger flow, it can be seen that there are fluctuations in the short-term passenger flow of conventional buses. In a prediction interval, the number of buses arriving of the same routes is higher than in the past and also is more than different considered routes, so the probability of passengers taking this route is higher than in the past; that is, the passenger flow on this route increases; otherwise, it decreases.The number of buses arriving on the other routes during the prediction interval. In this article, some routes that have successively repeated sites on a route are called different routes into consideration. In real life, passengers usually consider the different routes that arrive at the station first when taking a bus. The more buses on the different routes into consideration arrive, the more passenger flow will be divided, and the smaller the passenger flow of the select route.In the end, period, workday or weekend, passenger flow of previous period, the number of buses arriving on the predicted routes during the prediction interval, and the number of buses arriving on the other routes during the prediction interval are selected as the feature input of the conventional short-term passenger flow prediction model based on the XGBoost model.


### 5.1.2. Model Parameter Settings

The parameters of the XGBoost model include general parameters, lifting parameters, and learning task parameters. The general parameters control the overall function. The learning task parameters guide the model to perform optimization. The promotion parameters control the regression tree at each step. The general parameters and learning task parameters of the XGBoost model includebooster, objective, and eval_metric as shown in Table 4. The goal of predicting passenger flow is a regression problem, and so the base learner of the XGBoost model used in this article is a regression tree. RMSE is used to evaluate the accuracy of the model.Table 4
Selection of general parameters and learning task parameters.
ParametersValueBoostergbtreeObjectivereg: lineareval_metricRMSEThe lifting parameters are selected using a grid search method. Take the process of adjusting the parametern_estimators as an example. The candidate values of n_estimators are 200, 300, 400, 500, and 600. Firstly, we change the value of n_estimators, while the other parameters remain unchanged, and we use cross-validation and RMSE to measure the performance of models. Then, the best parameter value is selected. According to RMSE, the optimal n_estimators is 300. According to the above steps, the following parameters of a forecast model of this route are selected in turn: min_child_weight, max_depth, gamma, subsample, subsample_bytree, reg_alpha, reg_lambda, learning_rate. The optimal values are shown in Table 5.Table 5
The best value of each parameter.
ParametersValueLearning_rate0.01n_estimators300max_depth8min_child_weight4Subsample0.8colsample_bytree0.8Gamma0.1reg_alpha1reg_lambda1After adjusting all the parameters, the construction of the short-term passenger flow prediction model for conventional public transportation based on the XGBoost model has been completed.


## 5.1.1. Input Variable Selection

Period. The distributions of the short-term passenger flow of buses are shown in Figure 3. It can be seen that the passenger flow of most routes is higher in the peak hours than nonpeak hours. The passenger flow of bus changes dynamically for one day; however, it shows a similar change between workday and weekend. The change of passenger flow in the weekend is different from that of workdays. It has also been proved by previous studies. Therefore, weekend or workday is also taken into consideration in the prediction model.Figure 3
Time distribution of short-term passenger flow.Passenger flow of previous period. The closest thing to the current state of passenger flow is the passenger flow of the adjacent previous period, and the short-term passenger flow of bus is related to the number of passenger flow of the adjacent previous period.The number of buses arriving on the predicted routes during the prediction interval. According to the calculation of passenger flow, it can be seen that there are fluctuations in the short-term passenger flow of conventional buses. In a prediction interval, the number of buses arriving of the same routes is higher than in the past and also is more than different considered routes, so the probability of passengers taking this route is higher than in the past; that is, the passenger flow on this route increases; otherwise, it decreases.The number of buses arriving on the other routes during the prediction interval. In this article, some routes that have successively repeated sites on a route are called different routes into consideration. In real life, passengers usually consider the different routes that arrive at the station first when taking a bus. The more buses on the different routes into consideration arrive, the more passenger flow will be divided, and the smaller the passenger flow of the select route.In the end, period, workday or weekend, passenger flow of previous period, the number of buses arriving on the predicted routes during the prediction interval, and the number of buses arriving on the other routes during the prediction interval are selected as the feature input of the conventional short-term passenger flow prediction model based on the XGBoost model.


## 5.1.2. Model Parameter Settings

The parameters of the XGBoost model include general parameters, lifting parameters, and learning task parameters. The general parameters control the overall function. The learning task parameters guide the model to perform optimization. The promotion parameters control the regression tree at each step. The general parameters and learning task parameters of the XGBoost model includebooster, objective, and eval_metric as shown in Table 4. The goal of predicting passenger flow is a regression problem, and so the base learner of the XGBoost model used in this article is a regression tree. RMSE is used to evaluate the accuracy of the model.Table 4
Selection of general parameters and learning task parameters.
ParametersValueBoostergbtreeObjectivereg: lineareval_metricRMSEThe lifting parameters are selected using a grid search method. Take the process of adjusting the parametern_estimators as an example. The candidate values of n_estimators are 200, 300, 400, 500, and 600. Firstly, we change the value of n_estimators, while the other parameters remain unchanged, and we use cross-validation and RMSE to measure the performance of models. Then, the best parameter value is selected. According to RMSE, the optimal n_estimators is 300. According to the above steps, the following parameters of a forecast model of this route are selected in turn: min_child_weight, max_depth, gamma, subsample, subsample_bytree, reg_alpha, reg_lambda, learning_rate. The optimal values are shown in Table 5.Table 5
The best value of each parameter.
ParametersValueLearning_rate0.01n_estimators300max_depth8min_child_weight4Subsample0.8colsample_bytree0.8Gamma0.1reg_alpha1reg_lambda1After adjusting all the parameters, the construction of the short-term passenger flow prediction model for conventional public transportation based on the XGBoost model has been completed.


## 5.2. Comparison with Traditional Model

Currently, there are many prediction models for short-term passenger flow of conventional public transportation. Among them, the models that can perform multivariable short-term passenger flow prediction mainly include KNN, BP neural network, and LSTM. To show the better prediction effect of the proposed model, KNN, the BP neural network, and LSTM are established as benchmark models. Meanwhile, an XGBoost predicted model without the number of buses arriving is also implemented.


### 5.2.1. KNN Regression Model

Usesklearn.neighbors.KNeighborsRegressor in Python to build a short-term passenger flow prediction model for conventional public transportation based on KNN regression. In the KNN regression model, the key parameters are n_neighbor and weight. Take No. 125 bus at the station of Zhongshan 8th Road Station Substation 1 as an example, and finally, get the value of n_neighbor as 5 and weight as uniform through training.


### 5.2.2. BP Neural Network Model

Thekeras deep learning framework is used to build a short-term passenger flow prediction model for conventional public transportation based on BP neural network. Take the 125 bus at the substation of Zhongshan 8th Road Station as an example. After repeated experiments, the number of input layer nodes of the BP neural network model is selected as 70, the number of hidden layer nodes is 30, and the number of output layer nodes is 1; that is, the model structure is 70-30-1. Among them, the activation function of the hidden layer and the output layer is selected as the relu function. In addition, the number of iterations of the BP neural network is selected as 200, and the learning rate is 0.01.


### 5.2.3. LSTM Model

Thekeras deep learning framework is used to build a short-term passenger flow prediction model for conventional public transportation based on LSTM. Take the 125 bus at the substation of Zhongshan 8th Road Station as an example. After repeated trials, the number of input layer nodes of the selected LSTM model is 20, the number of hidden layer nodes is 15, the number of output layer nodes is 1, the step size is 4, the activation function of the hidden layer and the output layer is the relu function, and the optimizer is adam. In addition, the number of iterations of LSTM is 50 times.


### 5.2.4. XGBoost Model without the Number of Buses Arriving

Taking the 125 bus at the substation of Zhongshan 8th Road Station as an example, the best values of its parameters are shown in Table6.Table 6
The best value of each parameter of XGBoost without the number of buses arriving.
ParametersValueLearning_rate0.01n_estimators350max_depth8min_child_weight4Subsample0.8colsample_bytree0.8Gamma0.1reg_alpha1reg_lambda1The MAPE, RMSE, and MAE of the above prediction models for each bus route are shown in Figure4. It can be clearly seen that, regardless of indicators MAE, MAPE, or RMSE, the proposed model has the lowest value among most stations. For a quantitative analysis of the prediction results, Table 6 shows the comparison of the average values of the evaluation indicators of five prediction models.Figure 4
(a) MAPE results of 30 bus stations in five models. (b) RMSE results of 30 bus stations in five models. (c) MAE results of 30 bus stations in five models.
(a)(b)(c)From Table7, the proposed model has higher accuracy than other models, and the number of buses arriving as a feature input can improve the prediction effect of the XGBoost model. Among them, the accuracy of the proposed model is better than that of the KNN regression model and the BP neural network model, and it is significantly better than the XGBoost model without the number of buses arriving.Table 7
Comparison of the average value of the evaluation indicators of 30 bus stations.
ModelMAPE (%)RMSEMAETime (s)The proposed model42.904.763.5310.63XGBoost model without the number of buses arriving55.865.464.08—KNN regression model61.086.034.4411.78BP neural network model50.855.704.3140.21LSTM model44.116.174.6328.15The calculation time of the XGBoost model is slightly shorter than that of the KNN regression model, and it is much lower than the calculation time of the BP neural network model and the LSTM model. It is concluded that the XGBoost model is faster than the KNN regression model, BP neural network model, and LSTM model.


## 5.2.1. KNN Regression Model

Usesklearn.neighbors.KNeighborsRegressor in Python to build a short-term passenger flow prediction model for conventional public transportation based on KNN regression. In the KNN regression model, the key parameters are n_neighbor and weight. Take No. 125 bus at the station of Zhongshan 8th Road Station Substation 1 as an example, and finally, get the value of n_neighbor as 5 and weight as uniform through training.


## 5.2.2. BP Neural Network Model

Thekeras deep learning framework is used to build a short-term passenger flow prediction model for conventional public transportation based on BP neural network. Take the 125 bus at the substation of Zhongshan 8th Road Station as an example. After repeated experiments, the number of input layer nodes of the BP neural network model is selected as 70, the number of hidden layer nodes is 30, and the number of output layer nodes is 1; that is, the model structure is 70-30-1. Among them, the activation function of the hidden layer and the output layer is selected as the relu function. In addition, the number of iterations of the BP neural network is selected as 200, and the learning rate is 0.01.


## 5.2.3. LSTM Model

Thekeras deep learning framework is used to build a short-term passenger flow prediction model for conventional public transportation based on LSTM. Take the 125 bus at the substation of Zhongshan 8th Road Station as an example. After repeated trials, the number of input layer nodes of the selected LSTM model is 20, the number of hidden layer nodes is 15, the number of output layer nodes is 1, the step size is 4, the activation function of the hidden layer and the output layer is the relu function, and the optimizer is adam. In addition, the number of iterations of LSTM is 50 times.


## 5.2.4. XGBoost Model without the Number of Buses Arriving

Taking the 125 bus at the substation of Zhongshan 8th Road Station as an example, the best values of its parameters are shown in Table6.Table 6
The best value of each parameter of XGBoost without the number of buses arriving.
ParametersValueLearning_rate0.01n_estimators350max_depth8min_child_weight4Subsample0.8colsample_bytree0.8Gamma0.1reg_alpha1reg_lambda1The MAPE, RMSE, and MAE of the above prediction models for each bus route are shown in Figure4. It can be clearly seen that, regardless of indicators MAE, MAPE, or RMSE, the proposed model has the lowest value among most stations. For a quantitative analysis of the prediction results, Table 6 shows the comparison of the average values of the evaluation indicators of five prediction models.Figure 4
(a) MAPE results of 30 bus stations in five models. (b) RMSE results of 30 bus stations in five models. (c) MAE results of 30 bus stations in five models.
(a)(b)(c)From Table7, the proposed model has higher accuracy than other models, and the number of buses arriving as a feature input can improve the prediction effect of the XGBoost model. Among them, the accuracy of the proposed model is better than that of the KNN regression model and the BP neural network model, and it is significantly better than the XGBoost model without the number of buses arriving.Table 7
Comparison of the average value of the evaluation indicators of 30 bus stations.
ModelMAPE (%)RMSEMAETime (s)The proposed model42.904.763.5310.63XGBoost model without the number of buses arriving55.865.464.08—KNN regression model61.086.034.4411.78BP neural network model50.855.704.3140.21LSTM model44.116.174.6328.15The calculation time of the XGBoost model is slightly shorter than that of the KNN regression model, and it is much lower than the calculation time of the BP neural network model and the LSTM model. It is concluded that the XGBoost model is faster than the KNN regression model, BP neural network model, and LSTM model.


## 5.3. Robustness of the Model

To evaluate the robustness, we compare the performance of the proposed model.


### 5.3.1. Analysis by Time Period

Firstly, the accuracy of the proposed model is compared under different time periods: peak hours and nonpeak hours. The results are shown in Table8. It can be seen that the MAPE of the proposed model during peak hours is significantly better than that during low peak periods. This may be caused by its relatively stable passenger flow distribution during peak hours which has less volatility and less influence by various factors. But at the same time, the absolute error (RMSE and MAE) in the low-peak period is relatively low. This is because the passenger flow in the low-peak period is much smaller than that in the peak period. It can be seen that the proposed model has a good prediction effect during peak hours.Table 8
Comparison of the average value of the evaluation index under the peak hours and the nonpeak hours.
Type of time periodMAPE (%)RMSEMAEPeak hours30.269.988.9Nonpeak hours43.93.762.95


### 5.3.2. Analysis by the Type of Passenger Flow Distribution

Secondly, the accuracy of the proposed model is compared under different distributions. The distributions of passenger flow are divided as unimodal type, bimodal type, and other type. The comparison results are shown in Table9.Table 9
Comparison of the average value of evaluation indicators under different passenger flow types.
Passenger flow typeMAPE (%)RMSEMAEUnimodal type45.594.553.48Bimodal type43.264.683.42Other types39.855.073.69It can be seen that in the proposed model for the three types of passenger flow distribution, the prediction accuracy (MAPE) of the other types is better than that of the single-peak and double-peak types. This may be due to the fact that other types include multipeak passenger flow distribution types, which have more peak hours, and the passenger flow distribution during peak hours with less volatility is relatively stable and has been less affected by various factors. In general, other types of prediction accuracy are higher. The absolute error (RMSE and MAE) of other types is lower, which may be due to the fact that the average short-term passenger flow of other types is higher than that of the single-peak type and the double-peak type.


## 5.3.1. Analysis by Time Period

Firstly, the accuracy of the proposed model is compared under different time periods: peak hours and nonpeak hours. The results are shown in Table8. It can be seen that the MAPE of the proposed model during peak hours is significantly better than that during low peak periods. This may be caused by its relatively stable passenger flow distribution during peak hours which has less volatility and less influence by various factors. But at the same time, the absolute error (RMSE and MAE) in the low-peak period is relatively low. This is because the passenger flow in the low-peak period is much smaller than that in the peak period. It can be seen that the proposed model has a good prediction effect during peak hours.Table 8
Comparison of the average value of the evaluation index under the peak hours and the nonpeak hours.
Type of time periodMAPE (%)RMSEMAEPeak hours30.269.988.9Nonpeak hours43.93.762.95


## 5.3.2. Analysis by the Type of Passenger Flow Distribution

Secondly, the accuracy of the proposed model is compared under different distributions. The distributions of passenger flow are divided as unimodal type, bimodal type, and other type. The comparison results are shown in Table9.Table 9
Comparison of the average value of evaluation indicators under different passenger flow types.
Passenger flow typeMAPE (%)RMSEMAEUnimodal type45.594.553.48Bimodal type43.264.683.42Other types39.855.073.69It can be seen that in the proposed model for the three types of passenger flow distribution, the prediction accuracy (MAPE) of the other types is better than that of the single-peak and double-peak types. This may be due to the fact that other types include multipeak passenger flow distribution types, which have more peak hours, and the passenger flow distribution during peak hours with less volatility is relatively stable and has been less affected by various factors. In general, other types of prediction accuracy are higher. The absolute error (RMSE and MAE) of other types is lower, which may be due to the fact that the average short-term passenger flow of other types is higher than that of the single-peak type and the double-peak type.


## 5.4. Influence Degree of Variables

For different stations, different XGBoost prediction models are built. We have analyzed the weight of each variable contributing to the passenger flow prediction. It can be found that the contribution of variables of different routes is similar, and so we use the average of the routes to take further analysis. The result is shown in Figure5. It can be seen that period contributes the most among all variables and following is the date type indicating the temporal correlation is strong in passenger flow data. Interestingly, the contribution of buses from other routes is greater than that of buses from the same route, indicating the competition between different routes is fierce. Also, the importance of other routes for the prediction is different. To mine the relationship between different routes should be worthy of study and concerns in the future work.Figure 5
Feature importance score of the prediction model of 30 routes.


## 6. Conclusion

In this paper, we propose an ensemble tree method XGBoost to predict passenger flow of bus routes. Since the passenger flow of a station is highly influenced by the competition and complementation of other routes and buses of the same route, we take the number of routes and the number of buses during the predicted interval into the model to improve the accuracy. Comparing to the model, which does not consider the above two factors, the MAPE, RMSE, and MAE can be improved by 30.21%, 14.71%, and 15.58%, respectively. Moreover, the proposed model was compared to some benchmark models using the same data from Guangzhou; the results show it can achieve superior prediction performance. Surprisingly, XGBoost, consuming less computing resource than deep learning model LSTM, can achieve higher accuracy.Also, the proposed model has stronger reliability and interpretability than other benchmark models. We have evaluated the model under different passenger flow types and periods, and the proposed model can yield stable results. Moreover, the weights of variables contributing to passenger flow prediction are analyzed. It can be concluded that temporal information is critical to the prediction model. The competition of the different routes considered in the prediction model could improve the accuracy.In the future, we will take more variables, such as spatial variables and daily variables, into consideration in the model to further improve the accuracy. Also, we will work on extracting the passenger flow during shorter interval to build short-term prediction model.



---

*Source: 5872225-2022-01-07.xml*