# A Traffic Information Detection Method at Single Intersection Based on Wi-Fi Data
## 3 Methodology
### Calculation of Intersection Data
#### 3.3.2 Distinguish the Road Target Travel Mode  
The K-means clustering algorithm is selected to distinguish the travel modes of the road targets. Pedestrian and non-motor vehicle speeds are low, generally distributed below 10 km/h, and there is a big difference with motor vehicles. During peak traffic periods, intersections are congested, and vehicles queue up for a long time. The speed of pedestrians and non-motor vehicles less affected by congestion may exceed that of motor vehicles, but the speed difference of pedestrians and non-motor vehicles through the intersection is not significant. Therefore, the travel speed of the entrance section, the travel speed of the exit section, and the travel speed difference between the entrance section and the exit section of the road target are selected as the clustering characteristics to distinguish the travel mode of the target. Firstly, the K-means algorithm is used to distinguish low-speed travel modes of walking and non-motor vehicle travel from motor vehicle travel. Secondly, the road target travel mode of motor vehicle travel is further divided into private car travel and public transport travel according to the spatial-temporal correlation analysis. The specific steps of road target travel mode differentiation are as follows:  
Step 1: Select the road target data set \(obj-dataset\). For the road target sample \(obj_{o}\) in the data set, the speed \(v_{o}^{in}\) of the entrance section, the speed \(v_{o}^{out}\) of the exit section, and the speed difference \(v_{o}^{diff}\) of the entrance and exit section are obtained as the clustering feature. The \(v_{o}^{diff}\) can be obtained as follows:  
\[v_{o}^{diff}=\left|v_{o}^{in}-v_{o}^{out}\right| \tag{10}\]  
Step 2: Determine the initial number of cluster centers \(K\). The \(K\) value is determined using the elbow method. The reason is that the actual intersection traffic environment is complex, and it is a better way to determine the value K by using the internal correlation of the data set itself. The \(K\) value corresponding to the obvious inflection point of the SSE value decline is selected as the clustering \(K\) value. Step 3: Profile the data set \(obj-dataset\) and then adjust it. The MAC address matching range of the collected data is wide, the low-speed target is easy to miss the report, and the sample distribution among clusters is unbalanced, which leads to the deviation of the cluster center. In addition, the travel speed of the road target of motor vehicle travel is vastly different, the distribution range is wide, and the cohesion is not strong when clustering. The data set is preliminarily classified. When the travel speed of the entrance section or the travel speed of the exit section of the sample exceeds the motor vehicle speed threshold \(v_{thr}\), its travel mode is directly marked as motor vehicle travel. When the adjusted average silhouette coefficient of the data set reaches its maximum value, it is the selected vehicle speed threshold \(v_{thr}\). Step 4: K-means clustering is performed on the remaining unlabeled samples in \(obj-dataset\). The sample travel modes in the class with the largest central speed characteristic value after clustering are labeled as motor vehicle travel, and the rest are labeled as walking and non-motor vehicle travel. Step 5: Add a bus attribute value of \(N_{bus}\) to all samples in \(obj-dataset\), indicating that the sample is the passenger of the \(N_{bus}\) TH bus target found. When \(N_{bus}\) is 0, it means that the sample travel mode is not bus. The samples of all travel modes in the data set are taken as a data set, denoted as \(obj-dataset^{\prime}\), and the counting variable m is initialized as 1. Step 6: For sample obj\({}_{x}\), whose bus attribute value \(N_{bus}\) is null in the data set \(obj-dataset^{\prime}\), traverse other samples whose bus attribute value \(N_{bus}\) is null in the data set.