Comparison of Machine Learning Algorithms for Personalized Healthcare: A Data-Driven Approach to Predicting Heart Attack
Keywords:
Heart Attack, Heart Disease, Machine Learning, Decision Tree, K-Nearest Neighbor, Random ForestAbstract
Heart attack remains a leading cause of mortality worldwide; while traditional diagnostics like electrocardiography (ECG) and clinical evaluation have reduced death rates, they struggle with complex data and real‑time insights, prompting machine learning (ML) for prediction and explainability. This study compares three ML algorithms, k‑nearest neighbor (KNN), decision tree (DT), and random forest (RF), for heart‑attack prediction. The dataset, combined from Cleveland, Hungarian, Switzerland, Long Beach VA, and Stalog sources (Kaggle), contains 918 instances and 12 features. Categorical variables were converted to numeric using label encoder. Recursive Feature Elimination (RFE), Mutual Information, and Random Forest Gini importance consensually identified ST_Slope, ChestPainType, ExerciseAngina, MaxHR, and Oldpeak as the top five features. GridSearchCV tuned hyperparameters, and SHAP provided model explainability. Results: RF (GridSearchCV) achieved accuracy 83.7 %, 84.0% precision, recall 83.7 %, F1‑score 83.8 %; KNN (GridSearchCV) 83.3 % accuracy, 84.3 % precision, 83.3 % recall, 83.5 % F1‑score; DT (GridSearchCV) 79.0 % accuracy, 81.0 % precision, 79.0 % recall, 79.2 % F1‑score. ROC‑AUC scores were RF 0.905, KNN 0.876, DT 0.770; McNemar tests (RF p = 0.0008) confirmed RF’s edge with statistical similarity to KNN. SHAP waterfall highlighted ST_Slope and ChestPainType as strongest risk drivers. RF’s ensemble nature explains its superiority and better explainability via SHAP, making it preferable for clinical decision support. Future work should involve multi‑hospital cross‑validation, additional variables (labs, medications), hybrid methods, and more diverse datasets.