## 2 Methodology
### Clustering Method Based on Dimensionality Reduction
#### 2.1.2 Clustering Method Based on K-Shape  
Clustering is an unsupervised method that can divide data sets into several groups based on the similarity and distance between the data without prior information [33]. We divide the residents into different clusters according to the annual load curve and established a separate model for each cluster. Existing clustering algorithms mainly include hierarchical clustering, partition-based clustering, density-based clustering, grid-based clustering, and model-based clustering. K-Shape is one of the most advanced time series clustering algorithms based on K-Means [34]. To cope with time series, K-Shape uses shape-based distance to evaluate thesimilarity between two curves. In addition, shape-based distance uses cross-correlation distance to identify the minimum distance between two curves, even if they are not properly aligned. Specifically, the K-Shape method is shown in the following steps:  
Step 1: K-Shape calculates the distance between two-time series by using the cross-correlation method. We suppose there are two-time series X and Y, both of length m. To achieve translational invariance, Y is set as the constant, and we delimit X step by step and calculate the difference between X and Y at each step. This is shown in the formula below:  
\[\overset{\rightarrow}{x_{l}}(s)=\left\{ \begin{array}{ll}\left(\overset{|s |}{0,\ldots,0},x_{1},x_{2},\ldots,x_{m-s}\right),&s\geq 0\\ \left(x_{1-s},\ldots,x_{m-1},x_{m},\underbrace{0,\ldots,0}_{|s|}\right),&s<0 \end{array} \right. \tag{5}\]  
Step 2: The difference depends on the number of cross-relations, which represents the number of K-Shape cross-relations \(CC_{\omega}\left(\overset{\rightarrow}{x},\overset{\rightarrow}{y}\right)=R _{\omega-m}\left(\overset{\rightarrow}{x},\overset{\rightarrow}{y}\right)\), including \(\omega\in\{1,2,\ldots,2m-1\}\). \(R_{\omega-m}\left(\overset{\rightarrow}{x},\overset{\rightarrow}{y}\right)\) can be divided into two cases, as shown in Equation (6):  
\[R_{\omega-m}\left(\overset{\rightarrow}{x},\overset{\rightarrow}{y}\right) =\left\{ \begin{array}{ll}\sum\limits_{l=1}^{m-k}x_{l}+k\cdot y_{l},&\omega- m\geq 0\\ R_{\omega-m}\left(\overset{\rightarrow}{y},\overset{\rightarrow}{x}\right),&\omega-m<0\end{array} \right. \tag{6}\]  
\(R_{\omega-m}\) is used to calculate the similarity between X and Y at each step. The dot product is calculated at the positions present in both X and Y. The final R is the sum of the dot products of the valid regions. It can be said that the larger R is, the more similar the two sequences are. Step 3: K-Shape defines the shape-based distance (\(SBD\)). The more the blocks overlap, the bigger the shape is like \(CC\). To compare the similarity values of all possible positions, we take the most similar Max (CC) and then use \(1-max(CC)\) to obtain \(SBD\), as shown in Equation (7):  
\[SBD\left(\overset{\rightarrow}{x},\overset{\rightarrow}{y}\right)=1-max_{ \omega}(\frac{CC_{\omega}\left(\overset{\rightarrow}{x},\overset{ \rightarrow}{y}\right)}{\sqrt{R_{0}\left(\overset{\rightarrow}{x},\overset{ \rightarrow}{x}\right)\cdot R_{0}\left(\overset{\rightarrow}{y},\overset{ \rightarrow}{y}\right)}}) \tag{7}\]  
Step 4: The more similar the shape, the smaller the distance \(SBD\) is. The normalized \(NCC\) value is between \([-1,1]\) and, therefore, the \(SBD\) value is between \([0,2]\). The \(NCC\) is calculated as shown in Equation (8):  
\[NCC_{q}\left(\overset{\rightarrow}{x},\overset{\rightarrow}{y}\right)= \left\{\begin{array}{ll}\frac{CC_{\omega}\left(\overset{\rightarrow}{x}, \overset{\rightarrow}{y}\right)}{m},&q=\text{``}b\text{''}(NCC_{b})\\ \frac{CC_{\omega}\left(\overset{\rightarrow}{x},\overset{\rightarrow}{y} \right)}{m-\  
Step 5: Once the distance is defined, you need to adjust the centroid algorithm based on the distance logic. By looking for \(\overset{\rightarrow}{\mu_{k}}^{*}\), K-Shape makes the similarity between \(\overset{\rightarrow}{\mu_{k}}^{*}\) and each sequence \(x_{i}\) of \(P_{k}\) as large as possible.