Comparison of Random Forest and K-Nearest Neighbors in Heart Disease Prediction
DOI:
https://doi.org/10.59934/jaiea.v5i2.1942Keywords:
Heart Disease, Machine Learning, Random Forest, K-Nearest NeighborsAbstract
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.
Downloads
References
A. Agrawal, S., Gupta, R., & Kumar, “Comparative analysis of machine learning algorithms for heart disease prediction: A comprehensive study of Random Forest and KNN approaches.,” J. Biomed. Inform., pp. 104–118, 2023.
B. Kumar, S., Patel, A., & Sharma, “Deep comparative analysis of machine learning algorithms for cardiovascular disease prediction: Focus on ensemble and lazy learning methods.,” Biomed. Signal Process. Control, pp. 105–119, 2024.
S. Hassan, A., Ibrahim, K., & Ahmed, “Comparative analysis of supervised learning algorithms for heart disease classification using clinical datasets,” J. Healthc. Eng., 2022.
V. Gupta, M., Singh, R., & Arora, “Hybrid feature selection techniques for improving Random Forest and KNN performance in cardiac risk assessment,” IEEE Trans. Biomed. Eng., pp. 2245–2256, 2024.
N. Das, P., Sharma, K., & Patel, “Performance evaluation of ensemble methods vs. instance-based learning for cardiovascular disease prediction. Expert Systems with Applications,” Expert Syst. Appl., pp. 117–132, 2022.
P. Johnson, R., Thompson, D., & Wilson, “Evaluating the effectiveness of Random Forest versus K-Nearest Neighbors in predicting coronary artery disease,” Int. J. Med. Inform., pp. 105–118, 2023.
S. Lee, H., Park, J., & Kim, “No Optimization of hyperparameters in Random Forest and KNN algorithms for heart disease prediction using grid search and cross-validation.,” Appl. Sci., 2023.
M. Nakamura, T., Suzuki, Y., & Tanaka, “Performance comparison of machine learning classifiers for heart disease prediction: Random Forest vs. K-Nearest Neighbors analysis,” omputers Electr. Eng., pp. 107--120, 2022.
M. Chen, L., Wang, H., & Liu, “Enhanced heart disease prediction using optimized Random Forest and weighted K-Nearest Neighbors algorithms. Computers in Biology and Medicine,” Comput. Biol. Med., pp. 107–121, 2024.
Downloads
Published
How to Cite
Issue
Section
License
Copyright (c) 2026 Journal of Artificial Intelligence and Engineering Applications (JAIEA)

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.








