## 2 Methodology
### Unsupervised Method--The k-Means Clustering  
For the unsupervised part of this study, clustering was used, which is the task of organising a given set of unlabelled data objects to specific clusters (groups). Since clustering works with unlabelled data, ground truth data is not needed for training of the model, but in this work, measured occupancy was used for the verification of the results. The clustering method chosen for this work was \(k\)-means, which is one of the most popular clustering methods and it has been widely used for the clustering of raw datasets in the energy and built environment field and some of them have been reviewed in the introduction section.  
The \(k\)-means algorithm requires a predefined number of clusters, \(k\), in which data samples, or for this study day profiles, were placed. The algorithm uses the iterative scheme, where it first randomly selects the initial cluster centres around which it distributes the data samples. Then, cluster centres and the distribution of data samples are updated until the value of the objective function reaches a minimum [30]. To achieve the clustering process, the similarity of the data needs to be measured, which can be more difficult with the time-series data. In time-series, not only the magnitude of data points needs to be considered, but also the order of data points in the sequence. Traditionally with \(k\)-means, the Euclidean distance metric has been used as a similarity measure, but regarding time-series data, this measure is not accurate. A similarity measure that was developed explicitly for time-series is dynamic time warping (DTW) [31]. Given this similarity measure, clustering algorithms such as \(k\)-means also need an averaging method to be able to describe clusters that they form (cluster centres). The method used for averaging of time series in this work was dynamic time warping barycenter averaging (DBA) [32].  
The \(k\)-means algorithm used in this work was tslearn, which is a Python package that provides machine learning tools for time-series analysis [33]. The main parameter which needs to be set for the \(k\)-means algorithm is \(k\), the number of clusters. For this, the Elbow method was used, developed by [PERSON] [34]. The idea of the Elbow method is to calculate the \(k\)-means algorithm with the range of values for the \(k\). For each value of \(k\), the distortion score was calculated, the sum of square distances from each point to its assigned centre. With a plotted distortion score for each of the \(k\), it was possible to visually determine the best value for \(k\). The best value was the one located at the \"elbow\" of the curve (the point of the inflection on the curve). Detecting the \"elbow\" curve was done using the elbow detection algorithm (the kneedle), which finds a point of maximum curvature. The algorithm was developed by [PERSON] et al. [35], and in this work was applied using the Python package Yellowbrick [36].  
A summary of the unsupervised method is presented in Figure 3. It shows the selection of the optimal number of clusters as a step before the main clustering and finally, the verification of the whole process with the ground truth.  
Figure 3: Scheme of unsupervised data mining method for predicting the office occupancy level.