Comparison of Random Forest and K-Nearest Neighbors in Heart Disease Prediction - Erni; Ibnu Alfarobi; Wawan Kurniawan (Yayasan Kita Menulis, 2026)
Heart disease is one of the leading causes of death worldwide, with a death toll reaching 17.9 million cases annually according to the World Health Organization (WHO) and a prevalence of 1.5% in Indonesia. This high mortality rate demonstrates the importance of early detection and accurate prediction to prevent more serious complications. The development of artificial intelligence technology, particularly machine learning, offers a new approach in the medical field through the ability to analyze clinical data quickly and efficiently. This study was conducted to compare the performance of two machine learning algorithms, namely Random Forest and K-Nearest Neighbors (KNN), in predicting heart disease using a clinical dataset from Kaggle containing 20 samples and 9 attributes related to the patient's physiological condition. The parameter optimization process in both algorithms was carried out using grid search techniques with cross-validation to obtain the best model that can perform optimally on a limited dataset. Performance evaluation was carried out using accuracy, recall, and precision metrics to comprehensively measure the quality of the model predictions. The results of the study showed that the Random Forest algorithm provided superior performance with an accuracy of 0.75, a recall of 0.88, and a precision of 0.86, compared to KNN which only achieved an accuracy of 0.50, a recall of 0.67, and a precision of 0.67. These findings indicate that Random Forest is more effective in identifying the presence of heart disease, especially in terms of sensitivity to positive cases and prediction consistency. Thus, Random Forest has the potential to be a more appropriate algorithm for implementation in machine learning-based clinical decision support systems, to support the process of diagnosing heart disease more accurately and efficiently.