The critical need for faster, more accurate diagnosis of diabetes mellitus by machine learning classification models is highlighted by the exponential growth in the global incidence of the disease. The predominance of clinical traits and an unequal class distribution, among other problems, usually make it difficult for these models to forecast results. This research investigates the comparative performance of K-Nearest Neighbor (KNN) and Random Forest (RF) algorithms in diagnosing diabetes using a unified pipeline. The methodology encompasses several stages: data preprocessing (including the treatment of missing values, normalization, and encoding), feature selection via backward elimination, class rebalancing using the Synthetic Minority Over-sampling Technique (SMOTE), and performance assessment through a 5-fold cross-validation protocol. The dataset from Mendeley Data was separated into two categories: those with diabetes and those without. Based on the results, the RF algorithm achieved 97.10% accuracy, 99.52% precision, 98.26% F1-score, and 99.50% ROC-AUC, outperforming KNN in most evaluation criteria. However, KNN also shows a competitive ability to categorize data with a high precision rate of 99.15%. These results show that feature selection and data balance techniques should be part of every classification pipeline if we want more consistent and accurate models. The research concludes that Random Forest is more appropriate for clinical diabetes classification and suggests the systematic use of structured preprocessing in developing systems for early detection of chronic illnesses.
Copyrights © 2025