## 3 Materials and Methods
### Prediction  
#### 3.1.1 K-Means Clustering  
For many years, the main topic of data-mining studies has been cluster analysis, which has been a useful tool in data science. In addition, it is a well-known method for identifying homogeneous subsets from predictors in a dataset. K-medoids, k-means, and other clustering algorithms are widely used in many statistical analyses. K-means clustering is one of the most common and simple unsupervised learning methods in machine learning, which is used to solve various problems in statistics, computer science, genetics, and engineering. This algorithm partitions the dataset into K distinct and non-overlapping clusters. Therefore, the data within clusters have similar characteristics while between clusters they have different characteristics. The data within clusters are grouped based on similarity and squared Euclidean distance criteria. The input parameter in the k-means algorithm, which is used to determine the number of clusters, requires an optimal value for k, which is obtained using the Gap statistic [22] in the NbClust package [23]. After specifying the number of clusters, the k-means algorithm dedicates each observation to exactly one of k clusters. The minimization of the residual sum squares (RSS) can be used to determine the center of the clusters. In principle, k-means clustering is an optimization problem aimed at minimizing the objective function among groups. Although both clustering and classification divide the dataset into different classes, clustering, unlike classification, does not predict the variables; it just divides the dataset into homogeneous groups.  
Suppose the dataset \(D=\left\{x_{1},x_{2},\ldots,x_{p}\right\}\) contains N points. Suppose the clusters obtained after applying k-means are \(C=\left\{C_{1},C_{2},\ldots,C_{K}\right\}\). The RSS objective function to determine the value of the clusters is defined as follows:  
\[RSS=\sum_{k=1}^{K}\sum_{i,j\in C_{k}}x_{ij}-x_{ij}^{2} \tag{1}\]  
where \(|C_{k}|\), \(C_{k}\), \(x_{ij}\), \(i\in C_{k}\), and K show the number of observations in the k-th cluster, the clusters, ij-th variable, the i-th observation in the k-th cluster, and the number of clusters, respectively.  
By minimizing Equation (1), the minimization problem of the k-means clustering is solved as follows.  
\[\begin{array}{c}minimize\\ C_{1},C_{2},\ldots,C_{K}\sum_{k=1}^{K}\frac{1}{|C_{k}|}\sum_{i,j\in C_{k}}x_{ ij}-x_{ij}^{2}\end{array} \tag{2}\]  
The k-means clustering steps are as follows:  
1. The selection of the number of clusters;
2. The initialization of the cluster centers;
3. The data are assigned to the closest cluster based on the distance criterion. The data proximity is determined by their distance from the cluster centroids. The distance measure of all data from centroids within each cluster is the square Euclidean distance;
4. The centers of the clusters are the averages of the clusters and are updated with clusters obtained from the previous step. Additionally, there are other methods such as k-medoid and k-median that can be used to determine the centers of the clusters based on each method;
5. The two previous steps continue until the centers of the clusters do not change and the criterion of convergence is satisfied [24].