Implementation of KNN, RF, and XGB Algorithms for Food Allergen Detection in Indonesian Recipes - Ramadhani Nur Sarjito; Eliyani Eliyani (Universitas Mercu Buana, 2026)
Food allergies are a growing public health concern, especially in countries like Indonesia where traditional recipes often contain hidden allergens. This study aims to develop a machine learning-based system to detect food allergens in Indonesian recipes using K-Nearest Neighbors (KNN), Random Forest (RF), and Extreme Gradient Boosting (XGB) algorithms. A total of 7,840 recipes were collected from Cookpad.com using web scraping and labeled with five allergen categories, which include milk, peanuts, eggs, seafood, and wheat. The dataset was preprocessed using natural language processing techniques such as tokenization, stemming, and TF-IDF feature extraction. The models were trained and evaluated using accuracy, precision, recall, and F1-score. Experimental results show that XGBoost with hyperparameter tuning via GridSearchCV achieved the best performance, with the highest average recall of 0.9672 and F1-score of 0.9826. RF also showed strong performance, while KNN had the lowest accuracy and recall among the three models. The system was deployed using Streamlit to allow users to input recipe ingredients or URLs and receive real-time allergen predictions. The novelty of this study lies in the development of a large-scale Indonesian-language allergen dataset (7,840 recipes) that was unavailable in prior works, together with a multilabel allergen classification specifically tailored to the Indonesian culinary context. Unlike previous studies that predominantly rely on English-language datasets and non-Southeast Asian food cultures, this research contributes a localized allergen detection system that is directly integrated into a web-based interface. This approach offers a practical tool to support individuals with food allergies in identifying risky ingredients within local dishes and contributes to improving food safety awareness in Indonesia.