Ensemble Learning Based on Bagging and Hybrid Sampling for Food Safety Risk Prediction
Dafang Li1,2, Zhengyong Zhang1,2,3, Qingchun Wu4
1School of Management Science and Engineering, Nanjing University of Finance and Economics, Nanjing 210023, China.
Foods (Basel, Switzerland)
|April 14, 2026
Summary
This study introduces a novel Bagging-Stacking framework to improve food safety risk prediction. The method enhances detection of high-risk samples in imbalanced datasets, boosting recall and precision for better supply chain safety.
Area of Science:
- Food Science
- Machine Learning
- Data Science
Background:
- Food safety sampling faces challenges with rare high-risk samples, hindering accurate prediction in complex supply chains.
- Conventional machine learning models struggle with severe class imbalance, limiting effectiveness in food safety risk assessment.
Purpose of the Study:
- To develop and evaluate a unified Bagging-Stacking framework to overcome class imbalance for improved food safety risk prediction.
- To enhance the detection of minority high-risk samples within food safety inspection data.
Main Methods:
- Proposed a unified Bagging-Stacking framework integrating stacking ensembles, bagging, and SMOTE-Tomek resampling.
- Employed a stacking ensemble with five tree-based base learners and Logistic Regression meta-learner.
- Incorporated probability-based threshold optimization and SHAP analysis for interpretability.
Main Results:
- The framework significantly improved high-risk recall and precision, achieving the highest F1 score among compared models.
- Demonstrated robust and consistent generalization performance across varying test set proportions.
- SHAP analysis identified key risk predictors including storage conditions, production month, and shelf life.
Conclusions:
- The proposed Bagging-Stacking framework offers accurate, robust, and interpretable support for food safety risk prediction.
- Provides practical value for proactive risk prevention and efficient allocation of regulatory resources.
- Addresses limitations of conventional models in handling imbalanced food safety data.

