Implementasi Grid Search CV KNN dengan Preprocessing Z-Score Outlier Removal untuk Sistem Prediksi Risiko Kehamilan - Anggita, Ivan Maulana; Naufal, Muhammad; Zami, Farrikh Al (Forum Kerjasama Pendidikan Tinggi, 2025)
This study aims to optimize the K-Nearest Neighbors (KNN) algorithm in predicting pregnancy risk levels using the “maternal health risk” dataset from the UCI Machine Learning Repository. The methodology includes data preprocessing through outlier detection and removal using Z-score, normalization with Standard Scaling, and categorical encoding on the target labels. Hyperparameter tuning is performed using GridSearchCV to identify the optimal combination of KNN parameters (number of neighbors, distance weight, and distance metric). The results show that the unoptimized KNN model achieved an accuracy of only 69.46%, whereas the optimized model reached an accuracy of 82.00%, with macro average precision of 81.91%, recall of 82.89%, and F1-score of 82.23%. Evaluation using a confusion matrix also revealed significant performance improvement, especially in the high-risk category. The optimized model was deployed as a web application using the Flask framework and Docker via Hugging Face Spaces, enabling real-time and efficient online pregnancy prediction. These findings indicate that combining KNN with GridSearchCV and data normalization significantly enhances prediction performance and offers practical application in healthcare decision support systems.