## 2 Related Research
### Machine Learning-Based K-Means Clustering Protocols for WSN
#### 2.2.2 K-Means Clustering  
K-means is a machine learning algorithm used for solving clustering problems by classifying a dataset into a specified number of clusters (\(K\) clusters). The algorithm begins by (1) initializing \(k\) centroids, ideally positioned as far from each other as possible. (2) Each data point is then assigned to the nearest centroid, (3) forming an initial grouping. (4) New centroids are calculated as the centers of mass of these clusters, and data points are reassigned to the nearest new centroids. (5) This process repeats in a loop, adjusting centroid positions until they stabilize and no longer move. The K-means clustering objective function is designed to minimize the sum of squared distances between data points and their respective cluster centroids, as defined in Equation (4). \[J(\mathbf{X};\mathbf{C})=\sum_{j=1}^{K}\sum_{i=1}^{n}\left\|\mathbf{x}_{i}^{(j)}-c^{(j)} \right\|^{2} \tag{4}\]  
where \(K\) is the number of clusters and \(x_{i}^{(j)}\) is the data point (location of a node) in the \(j\)-th cluster. A set of nodes' locations is defined as \(\mathbf{X}=\{x_{1},\ x_{2},\ \ldots,\ x_{n}\}\). The variable \(c^{(j)}\) is the centroid of the \(j\)-th cluster, and \(\left\|\mathbf{x}_{i}^{(j)}-c^{(j)}\right\|^{2}\) is the squared Euclidean distance between a data point) and its cluster centroid. This iterative method continues until the centroids reach a stable position, resulting in the formation of compact clusters (an optimized clustering) where data points are close to their respective centroids. The integration of K-means clustering with the LEACH protocol has demonstrated significant potential for enhancing energy efficiency in WSNs. The authors in [14] introduced an energy-efficient hybrid clustering algorithm that combines K-means with LEACH. Their approach leverages K-means for initial node classification and subsequently applies LEACH for refining CH selection, resulting in balanced energy distribution across the network. Similarly, in [15], a modified K-means clustering algorithm was proposed, incorporating the distances among CHs, member nodes, and the remaining energy of nodes. This method effectively reduces overall energy consumption and extends the network lifespan, making K-means a pivotal tool in WSN optimization. Machine learning (ML) provides practical solutions to complex distributed problems in WSNs, particularly those related to energy-efficient routing and clustering. ML algorithms iteratively learn the properties of the environment and adapt their behavior to optimize network performance. Commonly employed ML techniques in WSNs include neural networks, fuzzy logic (FL), evolutionary algorithms, reinforcement learning, and bio-inspired intelligence approaches. Among these, Particle Swarm Optimization (PSO) has been widely studied for WSN clustering, as evidenced in prior research [22; 23; 24]. PSO is recognized for its ability to optimize cluster head selection and routing paths with relatively low computational cost, making it suitable for resource-constrained devices like sensor nodes [22]. These ML-based approaches have shown superior performance in extending network lifetime and improving energy efficiency. Despite the strengths of ML methods, K-means clustering remains a preferred approach in WSNs due to its scalability, simplicity, and compatibility with the resource limitations of sensor nodes. Unlike computationally intensive ML techniques, such as neural networks or hierarchical clustering, K-means imposes minimal computational overhead while ensuring rapid convergence. This makes it well suited for large-scale WSNs with dynamic node densities. Additionally, K-means is highly adaptable, allowing for customization with parameters such as residual energy and communication distance to optimize clustering decisions. Its integration with adaptive protocols like LEACH has demonstrated significant improvements in energy balancing and network stability, further solidifying its position as a practical and efficient choice for clustering in WSNs.