## 2 Methodology
### Classification Block
#### 2.1.2 K-Means  
K-Means is one of the most famous clustering algorithms, and is extensively used in unsupervised clustering tasks [11]. The key problem in K-Means is how to determine the value of \(K\). \(K\) is the number of clusters, which is also the number of station categories in this paper. Previous studies set \(K\) artificially [11], or used the elbow method [18]. To better determine \(K\) effectively, two novel evaluation metrics named same category rate (\(SCR\)) and average same category rate (\(ASCR\)) have been proposed. The ridership data used in our model are more than one week, and different weekly passenger flow at the same station may be similar. The clustering result is better if the same station of passenger flow in different weekly periods can be clustered into the same category. Inspired by this hypothesis, \(SCR\) and \(ASCR\) have been defined as Equations (16) and (17), respectively. \[SCR_{i}=1-\frac{N_{i}}{W} \tag{16}\]\[ASCR=\frac{\sum_{i=1}^{N}SCR_{i}}{N} \tag{17}\]  
where \(N_{i}\) represents the number of categories for the \(i\)th station with \(W\) different periodic weekly passenger flow data. \(W\) is the number of weeks, and \(N\) is the total number of stations in the network. The same station with different weekly passenger flow data may be classified into different categories. Thus, the larger the values are in \(SCR\) and \(ASCR\), the better the classification results are. For example, if \(W\) = 5, five weekly passenger flow data have been used. If the \(i\)th station with the different five weekly passenger flows has been clustered into two categories, \(N_{i}\) = 2 and \(SCR_{i}\) = 1 - 2/5 = 0.6. If the \(i\)th station with the different five weekly passenger flows has been clustered into one category, \(N_{i}\) = 1 and \(SCR_{i}\) = 1 - 1/5 = 0.8. The optimized result is 0.8, which indicates that 5-week passenger flow at the same station has been clustered in the same category, and the clustering result is quite good. Then, average all \(SCR_{i}\) as \(ASCR\) based on Equation (17). \(ASCR\) is the final evaluation result of all stations. It will be used to determine the number of categories for all stations, which is described in Section 3.4.1 in detail. The details of Algorithm 1 of K-Means for station classification are demonstrated below [11,12]. \(C=\{C_{1},C_{2},\ldots,C_{K}\}\) is the final result for station classification, and \(K^{\prime}\) is the number of categories. Notably, if the number of elements in \(\{C_{j}\}\) is 1 in Step 6, this means that there is a separate category including only one station. This station will be deleted because it is unsuitable for the later prediction block for multi-station passenger flow prediction. ```
Input:\(O_{TE}\) = \(\{x_{1},x_{2},\ldots,\ x_{S,iW}\}\), \(C_{t}=\emptyset\) (t=1, 2,..., K). Step1:for\(K\in[2,P]\) Step2: Select \(K\) samples \(\{\mu_{1},\mu_{2},\ldots,\mu_{K}\}\) from \(O_{TE}\) as the initialized clustering centers. Step3:for\(i\in[1,S*W]\) Step4:for\(j\in[1,K]\) Calculate the Euclidean distance \(d_{ij}\)=\(\sqrt{(x_{i}-\mu_{j})^{2}}\) between \(x_{i}\) and \(\mu_{j}\). if\(j\)=1 \(\{d_{min}=d_{ij},\ \lambda=1\}\) else if \(d_{min}>d_{ij}\) { \(d_{min}=d_{ij},\ \lambda=j\).} end if Step5:\(x_{i}\in\{C_{\lambda}\}\) end if Step6:for\(j\in[1,K]\) if (the number of elements in \(\{C_{j}\}\) is 1) {delete the element from \(O_{TE}\), K=K-1.} else {Calculate the new centroid of \(\{C_{j}\}\): \(\mu_{j}\)'. if \(\mu_{j}\)'=\(\mu_{j}\), Output the clustering result: \(C=\{C_{1},C_{2},\ldots,\ C_{K}\}\). else {\(\mu_{j}\)'= \(\mu_{j}\)' go to Step 3.} } end if Step7: Calculate \(ASCR_{K}\) based on Equations (16)-(17). end if Step8: Choose the highest value (Max) from \(\{ASCR_{K}\}\) (\(K\in[2,P]\)). Step9: The corresponding \(K^{\prime}\) in Max is the desired \(K\) in K-Means. Output: The result of station classification is \(C=\{C_{\
u},C_{2},\ldots,\ C_{K^{\prime}}\}\). All the stations are finally divided into the \(K^{\prime}\) categories. ```  
**Algorithm 1**K-Means for station classification.