K Value Effect on Accuracy Using the K-NN for Heart Failure Dataset

  • Alya Masitha Universitas Ahmad Dahlan, Yogyakarta, Indonesia
  • Muhammad Kunta Biddinika Universitas Ahmad Dahlan, Yogyakarta, Indonesia
  • Herman Herman Universitas Ahmad Dahlan, Yogyakarta, Indonesia
Keywords: Heart failure, K-Nearest Neighbors, Manhattan Distance, Preprocessing


Heart failure is included in the category of cardiovascular disease. Heart disease is not easy to detect, and its detection needs to be done by experienced and skilled medical professionals. Most patients with heart failure require hospitalization. Common symptoms of heart disease, such as chest pain and high or low blood pressure, vary from person to person. This study aims to find the most optimal k value based on the accuracy obtained based on calculations by testing different k values, namely 1, 3, 5, 7, and 9. After getting the results of the accuracy of the five k values, compare which accuracy has the highest value, best for K-Nearest Neighbor (K-NN) models. The classification process uses the K-NN algorithm. This algorithm is quite easy to use because some parameters work using distance metrics and k values. Therefore, the value of k in the K-NN algorithm greatly affects the accuracy that will be produced. In the results of this study, the accuracy obtained was k = 7 and k = 9, which are the most optimal results because they have the highest accuracy compared to other k values, with an accuracy of 88%. The expected benefit of this research is that it can make a scientific contribution to research in the field of machine learning classification, especially in predicting heart failure


Download data is not yet available.


[1] P. Mamatha Alex and S. P. Shaji, “Prediction and diagnosis of heart disease patients using data mining technique,” Proceedings
of the 2019 IEEE International Conference on Communication and Signal Processing, ICCSP 2019, pp. 848–852, 2019.
[2] B. Rahman, H. L. Hendric SpitsWarnars, B. Subirosa Sabarguna, andW. Budiharto, “Heart Disease Classification Model Using
K-Nearest Neighbor Algorithm,” 2021 6th International Conference on Informatics and Computing, ICIC 2021, 2021.
[3] D. Chicco and G. Jurman, “Machine learning can predict survival of patients with heart failure from serum creatinine and
ejection fraction alone,” BMC Medical Informatics and Decision Making, vol. 20, no. 1, 2020.
[4] H. Agrawal, J. Chandiwala, S. Agrawal, and Y. Goyal, “Heart Failure Prediction using Machine Learning with Exploratory Data
Analysis,” 2021 International Conference on Intelligent Technologies, CONIT 2021, 2021.
[5] C. Sowmiya and P. Sumitra, “Analytical study of heart disease diagnosis using classification techniques,” Proceedings of the
2017 IEEE International Conference on Intelligent Techniques in Control, Optimization and Signal Processing, INCOS 2017,
vol. 2018-Febru, pp. 1–5, 2018.
[6] R. Yunus, U. Ulfa, and M. D. Safitri, “Application of the K-Nearest Neighbors (K-NN) Algorithm for Classification of Heart
Failure,” Journal of Applied Intelligent System, vol. 6, no. 1, pp. 1–9, 2021.
[7] M. Alehegn, R. R. Joshi, and P. Mulay, “Diabetes analysis and prediction using random forest, KNN, Na¨ıve Bayes, and J48: An
ensemble approach,” International Journal of Scientific and Technology Research, vol. 8, no. 9, pp. 1346–1354, 2019.
[8] O. Terrada, B. Cherradi, A. Raihani, and O. Bouattane, “Atherosclerosis disease prediction using Supervised Machine Learning
Techniques,” 2020 1st International Conference on Innovative Research in Applied Science, Engineering and Technology,
IRASET 2020, 2020.
[9] I. Kumar, K. Dogra, C. Utreja, and P. Yadav, “A Comparative Study of Supervised Machine Learning Algorithms for Stock
Market Trend Prediction,” Proceedings of the International Conference on Inventive Communication and Computational Technologies,
ICICCT 2018, no. Icicct, pp. 1003–1007, 2018.
[10] A. Upadhyay, S. Nadar, and R. Jadhav, “Comparative study of SVM & KNN for signature verification,” Journal of Statistics
and Management Systems, vol. 23, no. 2, pp. 191–198, 2020.
[11] A. Almomany, W. R. Ayyad, and A. Jarrah, “Optimized implementation of an improved KNN classification algorithm using
Intel FPGA platform: Covid-19 case study,” Journal of King Saud University - Computer and Information Sciences, vol. 34,
no. 6, pp. 3815–3827, 2022.
[12] Z. Ma, Z., Li, H., & Wang, “Early detection of heart failure using k-nearest neighbors algorithm with feature selection,” International
Journal of Advanced Robotic Systems, vol. 17, no. 4, 2020.
[13] N. Jayapandian, C. P., & Sundararajan, “A comparative analysis of K-nearest neighbors and support vector machine algorithms
for heart disease prediction,” Journal of Ambient Intelligence and Humanized Computing, vol. 10, no. 10, pp. 4157–4167, 2019.
[14] A. Kishor and W. Jeberson, “Diagnosis of Heart Disease Using Internet of Things and Machine Learning Algorithms,” Lecture
Notes in Networks and Systems, vol. 203 LNNS, pp. 691–702, 2021.
[15] C. B. C. Latha and S. C. Jeeva, “Improving the accuracy of prediction of heart disease risk based on ensemble classification
techniques,” Informatics in Medicine Unlocked, vol. 16, p. 100203, 2019.
[16] S. Alam and N. Yao, “The impact of preprocessing steps on the accuracy of machine learning algorithms in sentiment analysis,”
Computational and Mathematical Organization Theory, vol. 25, no. 3, pp. 319–335, 2019.
[17] A. Murugan, S. A. H. Nair, and K. P. Kumar, “Detection of Skin Cancer Using SVM, Random Forest and kNN Classifiers,”
Journal of Medical Systems, vol. 43, no. 8, 2019.
[18] G. S. Reddy Thummala and R. Baskar, “Prediction of Heart Disease using Decision Tree in Comparison with KNN to Improve
Accuracy,” pp. 1–5, 2022.
[19] S. Uddin, A. Khan, M. E. Hossain, and M. A. Moni, “Comparing different supervised machine learning algorithms for disease
prediction,” BMC Medical Informatics and Decision Making, vol. 19, no. 1, 2019.
[20] Z. Mushtaq, A. Yaqub, S. Sani, and A. Khalid, “Effective K-nearest neighbor classifications for Wisconsin breast cancer data
sets,” Journal of the Chinese Institute of Engineers, Transactions of the Chinese Institute of Engineers,Series A, vol. 43, no. 1,
pp. 80–92, 2020.
[21] S. Uddin, I. Haque, H. Lu, M. A. Moni, and E. Gide, “Comparative performance analysis of K-nearest neighbour (KNN)
algorithm and its different variants for disease prediction,” Scientific Reports, vol. 12, no. 1, 2022.
How to Cite
Masitha, A., Biddinika, M., & Herman, H. (2023). K Value Effect on Accuracy Using the K-NN for Heart Failure Dataset. MATRIK : Jurnal Manajemen, Teknik Informatika Dan Rekayasa Komputer, 22(3), 593-604. https://doi.org/https://doi.org/10.30812/matrik.v22i3.2984