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.
Copyrights © 2025