# EV Charging Behavior Analysis Using Hybrid Intelligence for 5G Smart Grid
## 4 Simulation
### HTTL Based K-Means Clustering for EV Driver Behavior  
K-means is an unsupervised learning algorithm, which means the data to be processed has no labels [31]. It divides data points into k clusters so that each point belongs to the cluster corresponding to his nearest mean [32]. The 'K' represents the number of clusters and the'means' represents the mean of the data objects in the cluster. The algorithm makes each point belong to the cluster corresponding to his nearest mean (this is the cluster center) and uses it as the standard of clustering. There are many ways to calculate distance. The most popular way in this algorithm uses Euclidean distance to measure distance. The formula is given below:  
\[,dict(x_{i},y_{i})=\sqrt{\sum_{i=1}^{n}(x_{i}-y_{i})^{2}} \tag{2}\]  
In this formula, \(x_{i}\) and \(y_{i}\) are two points in a \(n\)-dimensional Euclidean space. In the beginning of K-means algorithm, m objects are randomly selected from n data objects as the initial cluster center, and then the distance between each object and the cluster center is calculated and the corresponding object is re-divided according to the minimum distance. Finally, the mean of each cluster as a new cluster center is recalculated. The kth iteration cluster center is updated as follows:  
\[Center_{k}=\frac{1}{|C_{k}|}\sum_{x_{i}\in C_{k}}x_{i}, \tag{3}\]  
where \(|C_{k}|\) represents the number of data points in \(k\)th cluster, center \(k\) is a vector containing D attributes as shown as below:  
\[Center_{k}=(Center_{k,1},\ Center_{k,2},\ \dots,Center_{k,D}). \tag{4}\]  
Moreover, the K-means algorithm requires constant iteration to re-divide the clusters and update the cluster center. In this article, we use the sum of squared errors (SSE) to determine when to terminate the iteration. The SSE is as follows:  
\[SSE=\sum_{k=1}^{K}\sum_{x_{i}\in C_{k}}dist(x_{i},Center_{k}), \tag{5}\]  
where \(K\) represents the number of clusters. When the difference of SSE between two iterations is less than a certain threshold \(\delta\), the iteration is terminated. The main disadvantage of this algorithm is that the random selection of the initial K point may lead to local convergence. Therefore, we used hybrid intelligence to refine the results. In this work, the use of HTTL helped refine the classification and clustering results. After clustering the data with the K-means algorithm, we used manual methods to check and re-mark the data at the boundary [33], so that we could obtain a better result. The detailed description of the HTTL-based K-means algorithm is shown in Figure 6.  
Before classification, we first normalized the data. As mentioned before, the user data were processed into the same tuple structure is as follows:  
\[\mu:=(t_{charge},\sigma_{charge},\sigma_{connect}). \tag{6}\]  
To find the best number of clusters, we used the elbow algorithm to get the K-SSE curve, as shown in Figure 7.  
When the number of clusters is approaching the ideal cluster number, SSE shows a rapid decline. However, when the number of clusters exceeds the ideal cluster number, SSE will continue to decline. At the meantime, the rate of decline will slow down. By plotting the K-SSE curve and finding the inflection point on the way down, the \(K\) value can be better determined. Therefore, our goal is to determine a small value of \(k\) that still has a low SSE, and the elbow usually represents where increasing \(k\) provides diminishing returns. By observing the curve, the clustering effect is better when the number of classifications \(k=3\). Next, on the basis of clustering, we used manual discriminant methods to check and re-mark the data at the boundary, with final results shown in Figure 8.  
After clustering, human intelligence is used to assign labels to user behavior.