Path loss prediction (PLP) is an important feature of wireless communications because it allows a receiver to anticipate the signal strength that will be received from a transmitter at a given distance. The PLP is done by using machine learning models that take into account numerous aspects such as the frequency of the signal, the surroundings, and the type of antenna. Various machine learning methods are used to anticipate path loss propagation but it is difficult to predict path loss in unknown propagation conditions. In existing models rely on incomplete or outdated data, which can affect the accuracy and reliability of predictions and they do not take into account the effects of environmental factors, such as terrain, foliage, and weather conditions, on path loss. Furthermore, existing models are not robust enough to handle the real-world variability and uncertainty, leading to significant errors in predictions. To tackle this issue, a novel ultrahigh frequency (UHF) PLP based on K-nearest neighbors (KNNs) is developed for predicting and optimizing the path loss for UHF. In this proposed model, a KNN-based PLP has been used to predict the path loss in the UHF. This technique is used for high-accuracy PLP through KNN forecast route loss by determining the K-nearest data points to a particular test point based on a distance metric. Moreover, the existing models were not able to optimize path loss due to complex and large-scale machine learning models. Therefore, the stochastic gradient descent technique has been used to minimize the objective function, which is often a measure of the difference between the model’s predictions and the actual output that will fine-tune the parameters of the KNN model, by measuring the similarity between data points. This model is implemented using Python to make it a lot more convenient.