# Feature Construction Using Persistence Landscapes for Clustering Noisy IoT Time Series
## 7 Clustering Temperature Time Series  
We clustered long streams of temperatures, measured by sensors in various weather stations in the US. We considered time series of maximum daily temperatures (TMAX) from 11 December 2016 to 30 September 2019 (\(T=1024\)). The length \(T\) is a power of two, which was ideal for estimating the second-order spectrum using a Fast Fourier Transform (FFT). In addition, the time span included days from all four seasons in the US. Data for these locations were obtained from the National Oceanic and Atmospheric Administration (www.ncdc.noaa.gov (accessed on 1 October 2019)), and were preprocessed by (i) excluding the series if there were more than 100 missing values, and (ii) imputing a smaller number of missing values in the series, using the function na_se adec() in the R package **imputeTS**. We then fitted a linear trend regression model to the time series in \(N=63\) locations, in order to remove the long-term trend. Figure 1 shows the raw preprocessed temperature series (black) and the detrended series (blue) at four randomly selected locations. Each of the detrended time series at different locations showed a strong annual cycle. The levels and ranges of temperatures varied between locations: for instance, in Albany, the time series exhibited amplitudes ranging from 20 to 100 degrees Celsius, while Albert Lea had amplitudes ranging from \(-20\) to around 80 degrees Celsius. The locations also exhibited different patterns of temporal dependence. We implemented Algorithm 1, to select persistence landscapes of optimal order as features, and then used the K-means algorithm to cluster the \(N=63\) temperature time \begin{table}
\begin{tabular}{c c c c c c c c c c} \hline \hline
**Scenarios** & \multicolumn{3}{c}{**Scenario 1 (\(\
u^{\texttt{opt}}=4\))**} & \multicolumn{3}{c}{**Scenario 2 (\(\
u^{\texttt{opt}}=3\))**} & \multicolumn{3}{c}{\(M_{p}=1\) (\(\
u^{\texttt{opt}}=3\))**} \\ \hline SNR & 0.5 & 1.5 & 3 & 0.5 & 1.5 & 3 & 0.5 & 1.5 & 3 \\ \hline \(I_{n}(\omega_{j})\) & 0.97 & 0.9735 & 0.9735 & 0.505 & 0.5075 & 0.5045 & 0.9615 & 0.9645 & 0.964 \\ \hline PL(1) & 0.9295 & 0.9655 & 0.977 & 0.9275 & 0.9615 & 0.967 & 0.9615 & 0.9795 & 0.9875 \\ \hline PL(\(\
u\)), \(\
u=1\ldots\texttt{opt}\) & 0.94 & 0.981 & 0.991 & 0.928 & 0.962 & 0.9685 & 0.9615 & 0.9795 & 0.988 \\ \hline PL(\(\
u\)), \(\
u=1\ldots 40\) & 0.94 & 0.981 & 0.991 & 0.928 & 0.962 & 0.9685 & 0.9615 & 0.9795 & 0.988 \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Comparisons of the average accuracy of clustering. Different PL orders corresponding to three SNR Values. series based on these features. The red circle in each plot in Figure 2 denotes the selected order \(v^{\text{opt}}\) from the elbow method. The method converged quickly (at iteration 5) and chose \(v^{\text{opt}}=3\). Note that, because \(v^{\text{opt}}=3\) held for two successive iterations, this value was picked as the optimum order for these data. We constructed the persistence landscapes of orders \(\
u=1,2,3\), and used these as features in the K-means algorithm. We showed the computing times on a MacBook Pro (16-inch, 2019 with a 2.3 GHz 8-Core Intel Core i9). The code for the optimum \(v^{\text{opt}}=3\) landscapes was 27.92 seconds versus 6.04 minutes to run \(\
u=40\) landscapes: that is, using the optimum landscapes produced a speed-up of approximately 13 times. Figure 1: Raw temperatures (blue) and detrended temperatures (black) from four locations. Figure 2: Persistence landscape (PL) order selection for temperature time series using the elbow method. The number of clusters in the K-means method was chosen to be \(C=3\), using the average silhouette method [33] (see Figure 3). The profiles of the daily temperatures within the three clusters are shown in Figure 4. The titles of each plot show the number of time series in each cluster, i.e., \(C_{1}=21\), \(C_{2}=9\), and \(C_{3}=33\). In each plot, the black lines are the time-wise median of the time series, while the blue dots denote the maximum and minimum over time within the cluster.