The Wireless Sensor Network is a network formed in areas human beings cannot access. The data need to be sensed by the sensor and transferred to the sink node. Many routing protocols are designed to route data from a single node to the sink node. One of the routing protocols is the hierarchical routing protocol, which passes on the sensed data hierarchically. The Low Energy Adaptive Clustering Hierarchy (LEACH) is one of the hierarchical methods in which communication happens in two steps: the setup phase and the steady-state phase. The efficiency of the LEACH has to be optimized to improve the network lifetime. Therefore, the k-means clustering algorithm, which comes under the unsupervised machine learning method, is incorporated with the LEACH algorithm and has shown better results. But the selection of cluster head needs to improvise because it will transfer the summed-up data to the sink node, so it is to be efficient enough. So, this paper proposes the modified k-means algorithm with LEACH protocol for optimizing the Wireless Sensor Network. In the modified k-means algorithm, the weight of the cluster head is tested and elected, and the clusters are formed using the Euclidean distance formula. The proposed work yields 48.85% efficiency compared to the existing protocol. It is also proven that the proposed work showed more successful data transfer to the sink node. The cluster head selection process elects the more efficient node as the head with less failure rate. The proposed work optimistically balanced the whole network in terms of energy and successful data transfer.