Objective To establish a vegetable safety risk prediction model based on the particle swarm optimization (PSO) algorithm and the stacked generalization (Stacking) model, and to predict the sampling results of fenthion in vegetables sold in Shanghai. Methods Based on the sampling data of fenthion in vegetables sold in Shanghai from 2021 to 2023, task type, sampling area, sampling link, sampling place, sampling month, testing institution, and vegetable variety were selected as feature variables. The target variable was whether the sampling results for fenthion in vegetables were qualified. The PSO-Stacking prediction model was constructed using ten-fold cross-validation to select effective machine learning models and resampling methods and optimized the model parameters using the PSO algorithm. Results Fenthion-positive samples were found in 55 out of 3889 vegetable samples, with an overall failure rate of 1.4%. Bean vegetables had the highest rate at 2.3%, followed by eggplant and fruiting vegetables at 0.2%. The base models were obtained through screening, including Random Forest (RF), categorical boosting (CatBoost), gradient boosting (GB), extreme gradient Boosting (XGBoost), and light gradient boosting machine (LGBM). The best resampling technique was adaptive synthetic sampling (ADASYN). The PSO-Stacking model achieved the highest precision (0.91), recall (0.83), F1 score (0.87), and area under the curve (AUC) value (0.91) on the test set. Conclusion The PSO-Stacking model effectively addresses imbalanced food safety sampling data, accurately predicts the unqualified fenthion samples in vegetables, and provides technical support for vegetable supervision, sampling and risk warning.
| 科 Family | 属数 Number of genus | 种数 Number of species | 占总种数比例 Percentage of total species (%) | 属 Genus | 种数 Number of species | 占总种数比例 Percentage of total species (%) |
|---|---|---|---|---|---|---|
| 鹅膏菌科Amanitaceae | 2 | 11 | 5.26 | 鹅膏菌属 Amanita | 10 | 4.78 |
| 小菇科 Mycenaceae | 2 | 12 | 5.74 | 丝盖伞属 Inocybe | 5 | 2.39 |
| 多孔菌科 Polyporaceae | 8 | 14 | 6.70 | 蜡蘑属 Laccaria | 5 | 2.39 |
| 红菇科 Russulaceae | 3 | 23 | 11.00 | 小皮伞属 Marasmius | 6 | 2.87 |
| 小菇属 Mycena | 11 | 5.26 | ||||
| 光柄菇属 Pluteus | 5 | 2.39 | ||||
| 红菇属 Russula | 17 | 8.13 | ||||
| 栓菌属 Trametes | 5 | 2.39 |