# Power Profiling of Smart Grid Users Using Dynamic Time Warping +
## 5 Power Profiling Model
### Load Data Analysis  
Power consumption patterns are extracted by measuring the similarity between daily load time series using DTW-based clustering. We implement DTW using the dtw-python package (PyPI package 1.5.3) [67] in Python due to its efficiency and robust handling of time distortions. The implementation was executed on a Windows 11 machine (following the official documentation available at [[https://dynamictimewarping.github.io/python/](https://dynamictimewarping.github.io/python/)]([https://dynamictimewarping.github.io/python/](https://dynamictimewarping.github.io/python/)), accessed on 5 August 2024). DTW is preferred for its ability to accommodate temporal variations in energy consumption (e.g., shifts in peak usage hours) while maintaining accurate pattern alignment. In our implementation, DTW employs the following:  
* Symmetric Point-to-Point (P2P) matching, ensuring temporal consistency between aligned pairs [68].
* A local continuity constraint, which allows for flexible time warping while preserving signal integrity [67].
* Empirical clustering thresholds, determined through experimentation to optimize classification accuracy and robustness against outliers.  
Figure 1 illustrates the DTW alignment process, where two load time series (each containing 144 data points) are compared. The DTW algorithm dynamically aligns the signals by minimizing the cumulative distance between corresponding data points, allowing for elastic matching despite fluctuations in energy usage timing.  
Although the ED metric is simple to implement, we could not select it for our classification model due to its sensitivity to phase shifts and misalignment between time series. ED is primarily sensitive to amplitude similarities, meaning that even slight temporal misalignment (e.g., time distortions) can significantly increase the calculated distance, leading to misleading similarity assessments [69]. Power consumption data often fluctuate due to user habits, environmental factors, or operational changes. Even when two time series exhibit similar patterns, small temporal shifts can cause a disproportionate increase in ED. Furthermore, ED requires time series to be of equal length, which poses a limitation when comparing time series of varying lengths.  
For example, Figure 2 illustrates two load data time series of different lengths. These time series represent load data from two separate days extracted from our dataset, AMPds2. Due to a technical issue (e.g., a communication error), some load measurement data are missing, resulting in fewer data points in the second time series (represented by the dotted curve). As a result, calculating the ED between these two time series produced a value error. In contrast, calculating the DTW distance between the same time series did not present any issues. By leveraging DTW's capability to adapt to temporal variations, our model achieves more reliable clustering and profiling of power consumption behaviors, leading to improved accuracy in power profiling.  
Figure 1: DTW time alignment to measure the distance between two load data time series.