OriginalPaper | Open access | Published: December 1, 2026

Heart Disease Classification Using Random Forest and XGBoost Algorithms on The UCI Heart Disease Dataset

Hardianti Hafid, Nur Ikhwana, Ansari Saleh Ahmar
JINAV: Journal of Information and Visualization, Vol. 7 No. 3 (2026) https://doi.org/10.35877/454RI.jinav5046 Published: 2026-12-01
Get Permissions

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. 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. 2. BKPK. (2024). Survei Kesehatan Indonesia (SKI) 2023 dalam Angka. https://www.badankebijakan.kemkes.go.id/repositori/id/eprint/5539/
  3. 3. Breiman, L. (2001). Random Forests. Machine Learning, 45(1), 5–32. https://doi.org/https://doi.org/10.1023/A:1010933404324
  4. 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. 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. 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. 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. 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. 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. 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

How to Cite

Hafid, H., Ikhwana, N., & Ahmar, A. S. (2026). Heart Disease Classification Using Random Forest and XGBoost Algorithms on The UCI Heart Disease Dataset. JINAV: Journal of Information and Visualization, 7(3). https://doi.org/10.35877/454RI.jinav5046

Copyright & license

Copyright (c) 2026 Hardianti Hafid, Nur Ikhwana, Ansari Saleh Ahmar