Implementation of KNN, RF, and XGB Algorithms for Food Allergen Detection in Indonesian Recipes

Authors

  • Ramadhani Nur Sarjito Universitas Mercu Buana, Indonesia
  • Eliyani Eliyani Universitas Mercu Buana, Indonesia

DOI:

https://doi.org/10.22441/fifo.2026.v18i1.010

Abstract

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.

Downloads

Download data is not yet available.

References

[1] C. M. Warren, S. Sehgal, S. H. Sicherer, and R. S. Gupta, “Epidemiology and the Growing Epidemic of Food Allergy in Children and Adults Across the Globe,” Curr Allergy Asthma Rep, vol. 24, no. 3, pp. 95–106, Mar. 2024, doi: 10.1007/s11882-023-01120-y.

[2] World Allergy Organization. (2020). White book on allergy: Update 2020. https://www.worldallergy.org/WhiteBook

[3] Sudarmo, S. M., Setyawan, S., & Tridjaja, B. (2022). Prevalence of cow’s milk allergy in Indonesian children. Asia Pacific Allergy, 12(3), e27. https://doi.org/10.5415/apallergy.2022.12.e27

[4] Yulianti, S. (2019). Food allergy awareness in Indonesian pediatric practice. Indonesian Journal of Pediatrics, 6(2), 55–60.

[5] E. Gupta et al., “Food Allergy, Nutrition, Psychology, and Health,” J Allergy Clin Immunol Pract, vol. 13, no. 4, pp. 773-782.e2, Apr. 2025, doi: 10.1016/j.jaip.2024.09.036.

[6] G. H. Rennie et al., “Influence of Lifestyle and Dietary Habits on the Prevalence of Food Allergies: A Scoping Review,” Foods, vol. 12, no. 17, p. 3290, Sep. 2023, doi: 10.3390/foods12173290.

[7] G. H. Rennie et al., “Influence of Lifestyle and Dietary Habits on the Prevalence of Food Allergies: A Scoping Review,” Foods, vol. 12, no. 17, p. 3290, Sep. 2023, doi: 10.3390/foods12173290.

[8] Primanda, Y., & Wibowo, D. (2021). Traditional Indonesian food: A hidden risk for allergy sufferers? Jurnal Gizi dan Pangan, 16(3), 145–154. https://doi.org/10.25182/jgp.2021.16.3.145-154

[9] M. Martínez-Pineda and C. Yagüe-Ruiz, “The Risk of Undeclared Allergens on Food Labels for Pediatric Patients in the European Union,” Nutrients, vol. 14, no. 8, p. 1571, Apr. 2022, doi: 10.3390/nu14081571.

[10] Setyawan, R. (2023). Consumer knowledge of allergen labeling in Indonesian food products. Indonesian Food Journal, 5(2), 89–97.

[11] T. A. Bingemann, J. LeBovidge, L. Bartnikas, J. L. P. Protudjer, and L. J. Herbert, “Psychosocial Impact of Food Allergy on Children and Adults and Practical Interventions,” Curr Allergy Asthma Rep, vol. 24, no. 3, pp. 107–119, Mar. 2024, doi: 10.1007/s11882-023-01121-x.

[12] Fiocchi, A., Brozek, J., Schünemann, H., Bahna, S. L., von Berg, A., Beyer, K., ... & Rancé, F. (2010). World Allergy Organization (WAO) diagnosis and rationale for action against cow's milk allergy (DRACMA) guidelines. The World Allergy Organization Journal, 3(4), 57–161. https://doi.org/10.1097/WOX.0b013e3181defeb7

[13] Lee, A. J., Thalayasingam, M., & Lee, B. W. (2013). Anaphylaxis from hidden allergens in Asian cuisine: A series of cases. Allergy, Asthma & Clinical Immunology, 9(1), 7. https://doi.org/10.1186/1710-1492-9-7

[14] Liu, Y., Zhang, Y., & Xu, H. (2020). Machine learning approaches for food allergen detection: A systematic review. Computers in Biology and Medicine, 124, 103962. https://doi.org/10.1016/j.compbiomed.2020.103962

[15] Zhang, Y., Wang, C., & Liu, M. (2021). Comparison of machine learning algorithms for allergen classification. Journal of Food Science, 86(7), 2593–2603. https://doi.org/10.1111/1750-3841.15757

[16] Shaukat, A., Aslam, S., & Khan, I. (2021). Efficient allergen classification using machine learning algorithms. Journal of Food Informatics, 4(1), 12–19.

[17] Ismail, M., Nugroho, T., & Lestari, A. (2023). The Chef’s Choice: System for Allergen and Style Classification in Recipes. IEEE Access, 11, 67019–67030. https://doi.org/10.1109/ACCESS.2023.3276451

[18] Chen, Y., Wang, J., & Li, X. (2022). Limitations of cross-cultural allergen detection systems. Journal of Biomedical Informatics, 132, 104114. https://doi.org/10.1016/j.jbi.2022.104114

[20] Wulandari, N. (2024). Common food allergens in Indonesian cuisine: A review. Jurnal Kesehatan Masyarakat Indonesia, 10(1), 12–20.

[21] Manning, C. D., Raghavan, P., & Schütze, H. (2008). Introduction to information retrieval. Cambridge University Press. https://nlp.stanford.edu/IR-book/

[22] Jurafsky, D., & Martin, J. H. (2019). Speech and language processing (3rd ed.). Pearson. https://web.stanford.edu/~jurafsky/slp3/

[23] Streamlit Inc. (2024). Streamlit documentation. https://docs.streamlit.io/

[24] Nugroho, T., Handayani, P. W., & Azzahro, F. (2022). Designing accessible AI interfaces for food allergy detection. International Journal of Information and Communication Technology (IJICT), 6(1), 45–52.

[25] World Health Organization. (2021). Food safety and public health priorities. https://www.who.int/news-room/fact-sheets/detail/food-safety

[26] B. Indrayana, S. Hartati, and D. R. I. Setiadi, “Text classification on Indonesian news using support vector machine and feature selection,” *Jurnal RESTI*, vol. 5, no. 1, pp. 1–7, 2021.

[27] A. F. Wicaksono and H. Prabowo, “Comparative study of stemming and stopword removal on Indonesian text classification,” *Jurnal Ilmu Komputer dan Informasi (JIKI)*, vol. 13, no. 2, pp. 107–115, 2020.

[28] M. Zhang and Z. Zhou, “ML-KNN: A lazy learning approach to multi-label learning,” Pattern Recognit., vol. 40, no. 7, pp. 2038–2048, Jul. 2007, doi: 10.1016/j.patcog.2006.12.019.

[29] R. Subramanian et al., “A comparative study of machine learning algorithms for multi-label classification of food allergen ingredients,” Procedia Comput. Sci., vol. 172, pp. 148–155, 2020.

[30] L. Breiman, “Random forests,” Mach. Learn., vol. 45, no. 1, pp. 5–32, Oct. 2001, doi: 10.1023/A:1010933404324.

[31] S. Brahimi, “AI-powered dining: text information extraction and machine learning for personalized menu recommendations and food allergy management,” International Journal of Information Technology, vol. 17, no. 4, pp. 2107–2115, May 2025, doi: 10.1007/s41870-024-02154-9.

[32] S. Hidayatullah and H. Santoso, “Random Forest-Based Assessment of Mangrove Degradation Utilizing NDVI Feature Extraction in Spatio-Temporal Analysis,” Jurnal Nasional Pendidikan Teknik Informatika (JANAPATI), vol. 13, no. 1, pp. 58–65, Mar. 2024, doi: 10.23887/janapati.v13i1.71173.

[33] T. Chen and C. Guestrin, “XGBoost: A scalable tree boosting system,” in Proc. 22nd ACM SIGKDD Int. Conf. Knowl. Discov. Data Min., 2016, pp. 785–794, doi: 10.1145/2939672.2939785.

[34] Y. Wang et al., “Multilabel food allergen prediction using gradient boosting classifiers,” IEEE Access, vol. 10, pp. 54778–54788, 2022, doi: 10.1109/ACCESS.2022.3177438.

[35] M. M. Hasan et al., “Food allergen detection using machine learning approaches: A review,” IEEE Access, vol. 9, pp. 53789–53804, 2021, doi: 10.1109/ACCESS.2021.3070612.

[36] K. G. Ayu, D. W. Sari, I. Farida, D. Harsono, R. W. Kosaman, I. H. Sumitro, F. N. Iman, M. Mansuri, E. R. Kaburuan, and M. A. Fitri, "Classification of Employee Competency Assessment Using Naïve Bayes and K-Nearest Neighbor (KNN) Algorithms," Journal of Advances in Information Technology, vol. 15, no. 7, pp. 879–885, Jul. 2024. doi: 10.12720/jait.15.7.879-885

Downloads

Published

2026-07-03

How to Cite

[1]
R. Nur Sarjito and E. Eliyani, “Implementation of KNN, RF, and XGB Algorithms for Food Allergen Detection in Indonesian Recipes”, FIFO, vol. 18, no. 1, Jul. 2026.

Issue

Section

Articles