Performance Analysis of K-Nearest Neighbors (KNN) and Random Forest Algorithms for Classification of Weather Conditions

Authors

  • Agim Sahrija Asha Yuda
  • Muhammad Desfriyan Arif Rosady Universitas Muhammadiyah Riau
  • Nabil Ibrahim Faisal
  • Edi Ismanto

DOI:

https://doi.org/10.37859/coscitech.v6i2.9827
Keywords: K-Nearest Neighbors, Random Forest, Klasifikasi Cuaca, Pembelajaran Mesin, Evaluasi Kinerja : K-Nearest Neighbors, Random Forest, Weather Classification, Machine Learning, Performance Evaluation

Abstract

The development of information technology has encouraged the use of machine learning algorithms in various fields, including in the analysis and prediction of weather conditions. This study aims to analyze and compare the performance of two machine learning algorithms, namely K-Nearest Neighbors (KNN) and Random Forest, in the classification of weather conditions based on historical meteorological data. The dataset used includes features such as rainfall, maximum temperature, minimum temperature, and wind speed, with target categories in the form of weather types such as rain, sunny, fog, drizzle, and snow. The process includes data pre-processing, feature scaling, training and test data sharing, and model training using the scikit-learn library. Performance evaluations are conducted using accuracy, precision, recall, and F1-score metrics. The results showed that the Random Forest model had higher accuracy (82%) than KNN (78%), with more stable performance in the majority class. However, both models experienced significant performance declines in minority classes due to data imbalances. The study recommends further optimizations such as class balancing and model parameter selection to improve the overall accuracy of weather classification.

Downloads

Download data is not yet available.

References

M. Farouk, S. Asklany, M. Abd, M. Farouk MAli, S. A. Asklany, and M. Abd El-wahab, “Data Mining Algorithms for Weather Forecast Phenomena : Comparative Study,” IJCSNS Int. J. Comput. Sci. Netw. Secur., vol. 19, no. 9, p. 76, 2019, [Online]. Available: https://www.researchgate.net/publication/337797654

F. Q. Kareem, A. M. Abdulazeez, and D. A. Hasan, “Predicting Weather Forecasting State Based on Data Mining Classification Algorithms,” Asian J. Res. Comput. Sci., vol. 9, no. 3, pp. 13–24, 2021, doi: 10.9734/ajrcos/2021/v9i330222.

M. Abdulraheem, J. B. Awotunde, A. E. Adeniyi, I. D. Oladipo, and S. O. Adekola, “Weather prediction performance evaluation on selected machine learning algorithms,” IAES Int. J. Artif. Intell., vol. 11, no. 4, pp. 1535–1544, 2022, doi: 10.11591/ijai.v11.i4.pp1535-1544.

A. D. Putri, M. Al Haris, F. Fauzi, and S. Amri, “K-Nearest Neighbor ( KNN ) Method for Weather Data Prediction,” vol. 3, no. June, pp. 56–64, 2025.

R. Gunawan, R. Septiadi, F. Apri Wenando, H. Mukhtar, and Syahril, “K-Nearest Neighbor (KNN) untuk Menganalisis Sentimen terhadap Kebijakan Merdeka Belajar Kampus Merdeka pada Komentar Twitter,” J. CoSciTech (Computer Sci. Inf. Technol., vol. 3, no. 2, pp. 152–158, 2022, doi: 10.37859/coscitech.v3i2.3841.

M. Alidin et al., “Jurnal Computer Science and Information Technology ( CoSciTech ) Application of K-Nearest Neighbors to the Classification of Legal Cases in the Federal Courts of,” vol. 6, no. 1, pp. 85–93, 2025.

I. Riadi, A. Yudhana, and M. Rosyidi Djou, “Comparative Analysis of Naïve Bayes and K-NN in Determining Location of Mobile Population Services,” J. CoSciTech (Computer Sci. Inf. Technol., vol. 4, no. 3, pp. 733–742, 2024, doi: 10.37859/coscitech.v4i3.6543.

R. Meenal, P. A. Michael, D. Pamela, and E. Rajasekaran, “Weather prediction using random forest machine learning model,” Indones. J. Electr. Eng. Comput. Sci., vol. 22, no. 2, pp. 1208–1215, 2021, doi: 10.11591/ijeecs.v22.i2.pp1208-1215.

A. Mathew and J. Mathew, “Weather Forecasting Using the Random Forest Algorithm Analysis,” vol. 4, no. 1, pp. 3–5, 2022, doi: 10.5281/zenodo.6361990.

A. Oktian Permana and Sudin Saepudin, “Perbandingan algoritma k-nearst neighbor dan naïve bayes pada aplikasi shopee,” J. CoSciTech (Computer Sci. Inf. Technol., vol. 4, no. 1, pp. 25–32, 2023, doi: 10.37859/coscitech.v4i1.4474.

Downloads

Published

2025-09-19

How to Cite

Asha Yuda, A. S., Muhammad Desfriyan Arif Rosady, Nabil Ibrahim Faisal, & Edi Ismanto. (2025). Performance Analysis of K-Nearest Neighbors (KNN) and Random Forest Algorithms for Classification of Weather Conditions. Jurnal CoSciTech (Computer Science and Information Technology), 6(2), 337–343. https://doi.org/10.37859/coscitech.v6i2.9827