Heart Disease Classification Using Random Forest and XGBoost Algorithms on The UCI Heart Disease Dataset
- Publication History
- Published online: December 1, 2026
- DOI
- https://doi.org/10.35877/454RI.jinav5046
- Copyright
- Copyright (c) 2026 Hardianti Hafid, Nur Ikhwana, Ansari Saleh Ahmar
- User License
- https://creativecommons.org/licenses/by-nc-sa/4.0
Abstract
Heart disease is a leading cause of death worldwide, making early detection based on routine clinical data a pressing need. Many machine learning models have been developed for heart disease classification, but their evaluation has generally been limited to a single data source with random data splitting. As a result, model generalisability and the influence of data quality on performance remain underexplored. This study aimed to build a Random Forest classifier for heart disease, compare it with XGBoost, and identify the most influential clinical attributes. The UCI Heart Disease dataset, covering 918 patients from four hospitals, was used. Attributes with more than half of their values missing were excluded, and missing values in the remaining attributes were imputed, so that all patients were retained for analysis. Model performance was assessed using a hold-out test set, nested cross-validation, and inter-hospital external validation, while attribute contributions were analysed using SHAP. Random Forest achieved an AUC of 0.891 on the test set and 0.878 in nested cross-validation, comparable to XGBoost (0.886 and 0.877). Chest pain type, exercise-induced angina, ST depression, and maximum heart rate were the most influential attributes. In external validation on hospitals excluded from training, AUC decreased to 0.73–0.77 and calibration deteriorated. In addition, zero cholesterol values that were not recoded as missing spuriously inflated the AUC and distorted the SHAP interpretation. These findings indicate that data quality and validation design determine model performance more than the choice of algorithm; therefore, external validation and recalibration are required before clinical implementation.
Keywords
References (23)
- 1. Bharti, R., Khamparia, A., Shabaz, M., Dhiman, G., Pande, S., & Singh, P. (2021). Prediction of Heart Disease Using a Combination of Machine Learning and Deep Learning. Computational Intelligence and Neuroscience, 2021. https://doi.org/10.1155/2021/8387680
- 2. BKPK. (2024). Survei Kesehatan Indonesia (SKI) 2023 dalam Angka. https://www.badankebijakan.kemkes.go.id/repositori/id/eprint/5539/
- 3. Breiman, L. (2001). Random Forests. Machine Learning, 45(1), 5–32. https://doi.org/https://doi.org/10.1023/A:1010933404324
- 4. Calster, B. Van, McLernon, D. J., Smeden, M. van, Wynants, L., & Steyerberg, E. W. (2019). Calibration: the Achilles heel of predictive analytics. BMC Medicine, 17(230). https://doi.org/10.1186/s12916-019-1466-7
- 5. Chen, T., & Guestrin, C. (2016). XGBoost: A Scalable Tree Boosting System. N Proc. 22nd ACM SIGKDD Int. Conf. Knowledge Discovery and Data Mining, 785–794. https://doi.org/10.48550/arXiv.1603.02754
- 6. Chicco, D., & Jurman, G. (2020). The advantages of the Matthews correlation coefficient (MCC) over F1 score and accuracy in binary classification evaluation. BMC Genomics, 21(1). https://doi.org/10.1186/s12864-019-6413-7
- 7. Christodoulou, E., Ma, J., Collins, G. S., Steyerberg, E. W., Verbakel, J. Y., & Van Calster, B. (2019). A systematic review shows no performance benefit of machine learning over logistic regression for clinical prediction models. Journal of Clinical Epidemiology, 110, 12–22. https://doi.org/10.1016/j.jclinepi.2019.02.004
- 8. Collins, G. S., Moons, K. G. M., Dhiman, P., Riley, R. D., Beam, A. L., Van Calster, B., Ghassemi, M., Liu, X., Reitsma, J. B., van Smeden, M., Boulesteix, A.-L., Camaradou, J. C., Celi, L. A., Denaxas, S., Denniston, A. K., Glocker, B., Golub, R. M., Harvey, H., Heinze, G., … Logullo, P. (2024). TRIPOD+AI statement: updated guidance for reporting clinical prediction models that use regression or machine learning methods. BMJ, 385, e078378. https://doi.org/10.1136/bmj-2023-078378
- 9. Detrano, R., Janosi, A., Steinbrunn, W., Pfisterer, M., Schmid, J.-J., Sandhu, S., Guppy, K. H., Lee, S., & Froelicher, V. (1989). International Application of a New Probability Algorithm for the Diagnosis of Coronary Artery Disease. The American Journal of Cardiology, 64(5), 304–310. https://doi.org/10.1016/0002-9149(89)90524-9
- 10. Futoma, J., Simons, M., Panch, T., Doshi-Velez, F., & Celi, L. A. (2020). The myth of generalisability in clinical research and machine learning in health care. The Lancet Digital Health, 2(9). https://doi.org/10.1016/S2589-7500(20)30186-2
- 11. Grinsztajn, L., Oyallon, E., & Varoquaux, G. (2022). Why do tree-based models still outperform deep learning on typical tabular data? Advances in Neural Information Processing Systems 35, 507–520. https://doi.org/10.52202/068431-0037
- 12. Janosi, A., Steinbrunn, W., Pfisterer, M., & Detrano, R. (1989). Heart disease [Data Set]. https://doi.org/10.24432/C52P4X
- 13. Kapoor, S., & Narayanan, A. (2023). Leakage and the reproducibility crisis in machine-learning-based science. Patterns, 4(9). https://doi.org/10.1016/j.patter.2023.100804
- 14. Lundberg, S. M., Allen, P. G., & Lee, S.-I. (2017). A Unified Approach to Interpreting Model Predictions. Advances in Neural Information Processing Systems, 4765–4774. https://github.com/slundberg/shap
- 15. Lundberg, S. M., Erion, G., Chen, H., DeGrave, A., Prutkin, J. M., Nair, B., Katz, R., Himmelfarb, J., Bansal, N., & Lee, S.-I. (2020). From local explanations to global understanding with explainable AI for trees. Nature Machine Intelligence, 2(1), 56–67. https://doi.org/10.1038/s42256-019-0138-9
- 16. Malley, J. D., Kruppa, J., Dasgupta, A., Malley, K. G., & Ziegler, A. (2012). Probability Machines: Consistent probability estimation using nonparametric learning machines. Methods of Information in Medicine, 51(1), 74–81. https://doi.org/10.3414/ME00-01-0052
- 17. Mohan, S., Thirumalai, C., & Srivastava, G. (2019). Effective Heart Disease Prediction Using Hybrid Machine Learning Techniques. IEEE Access, 7, 81542–81554. https://doi.org/10.1109/ACCESS.2019.2923707
- 18. Probst, P., Wright, M. N., & Boulesteix, A. (2019). Hyperparameters and tuning strategies for random forest. WIREs Data Mining and Knowledge Discovery, 9(3), e1301. https://doi.org/10.1002/widm.1301
- 19. Rodriguez, M. P., & Nafea, M. (2024). Centralized and Federated Heart Disease Classification Models Using UCI Dataset and their Shapley-value Based Intepretability. https://doi.org/10.48550/arXiv.2408.06183
- 20. Varma, S., & Simon, R. (2006). Bias in error estimation when using cross-validation for model selection. BMC Bioinformatics, 7. https://doi.org/10.1186/1471-2105-7-91
- 21. WHO. (2025). Cardiovascular Diseases (CVDs). https://www.who.int/news-room/fact-sheets/detail/cardiovascular-diseases-(cvds)
- 22. Wright, M. N., & Ziegler, A. (2017). Ranger: A fast implementation of random forests for high dimensional data in C++ and R. Journal of Statistical Software, 77(1). https://doi.org/10.18637/jss.v077.i01
- 23. Zech, J. R., Badgeley, M. A., Liu, M., Costa, A. B., Titano, J. J., & Oermann, E. K. (2018). Variable generalization performance of a deep learning model to detect pneumonia in chest radiographs: A cross-sectional study. PLoS Medicine, 15(11). https://doi.org/10.1371/journal.pmed.1002683
How to Cite
Copyright & license

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


