It should be noted that the Weibo data cover nationwide discussions, and the news reports also have cross-regional coverage, while the inspection data used in this section come from Gansu Province. To partly address this spatial mismatch, Weibo comments from Gansu users are extracted for comparison. Among Gansu users, positive, neutral, and negative sentiment accounted for 26.04%, 31.25%, and 42.71%, respectively. The negative share is lower than that in high-attention regions such as Guangdong, Tibet, and Shanghai, but the overall pattern still shows a notable proportion of negative sentiment. Therefore, the Gansu inspection data provides a provincial-level case for model validation, but the findings should not be interpreted as nationally representative.
5.1. Data Collection and Preprocessing
5.1.1. Selection of Research Subjects and Definition-Constrained Screening
Pre-made dishes did not receive a clear national regulatory definition until 21 March 2024. According to the joint notice issued by the State Administration for Market Regulation and other departments, pre-made dishes are pre-packaged dishes made from one or more edible agricultural products and their processed products. They are produced through industrial pre-processing, contain no preservatives, and are intended to be consumed after heating or cooking. The notice also excludes fresh-cut vegetables, staple foods, dishes prepared by central kitchens, and unpackaged bulk foods.
Since public inspection databases still lack a sufficiently large dedicated dataset for pre-made dishes, this study no longer uses broad food categories as the research object. Instead, the original inspection records are screened according to the official definition. The screening follows two principles. First, products clearly excluded by the official definition or weakly related to the pre-made dish supply chain are removed. These include flour, rice, dried noodles, instant noodles, steamed bread, pastries, bread, edible oils, condiments, beverages, fresh vegetables, and fresh fruits. Second, products closely related to industrial pre-processing, reheating or cooking, and the pre-made dish supply chain are retained. These include starch noodles, vermicelli, wide noodles, hotpot starch noodles, pickled vegetables, sauerkraut, canned foods, dried vegetables, edible fungi products, preserved fruit products, and dried aquatic products.
The retained records are not described as dedicated inspection data for strictly defined pre-made dishes. Instead, they are defined as “definition-constrained pre-made dish-associated products.” This wording better reflects the current data conditions and avoids equating broad traditional food categories with pre-made dishes. After screening, 2783 records are retained from 12,121 original records, including 1063 high-relevance products and 1720 general-relevance products. Among them, 185 are non-compliant, with a non-compliance rate of 6.65%.
5.1.2. Data Collection and Descriptions
According to the Gansu Province Food Safety Supervision and Sampling Inspection Work Plan, the obtained inspection data indicators include product name, judgment result, specification/model, production date, manufacturer address, notification date, and inspection level (national, provincial, or municipal). The sampling inspection scheme is dynamically adjusted based on food safety risks, flexibly allocating inspection efforts according to different seasons, regions, and food categories. During high-risk seasons, the inspection frequency for key food items is increased, inspection intensity is strengthened in regions with frequent issues, and the coverage of different food categories is optimized by combining historical data and risk assessments to ensure precise and efficient supervision.
A total of 12,121 food inspection records are obtained, including 668 non-compliant samples, with a non-compliance rate of 5.51%. After definition-constrained screening, 2783 pre-made dish-associated product records are retained. Among them, 185 are non-compliant, with a non-compliance rate of 6.65%. The retained samples are mainly concentrated in starch and starch products, fruit products, vegetable products, aquatic products, canned foods, and a small number of grain products. To further analyze the specific distribution characteristics of food safety risks, this study conducts a cross-sectional comparison of unqualified rates across different food categories.
Figure 1 and
Figure 2 provide the general risk background of the full inspection records. The subsequent modeling analysis uses only the definition-constrained pre-made dish-associated product records. From the perspective of food production license classification,
Figure 1 shows a horizontal comparison of the overall unqualified of top 15 food categories by the number of inspection batches from 2022 to 2024.
From a cross-sectional perspective, the unqualified rate ranges from zero to a maximum of 23.75%, reflecting uneven safety risks across different food categories and considerable risk fluctuations. Therefore, a uniform inspection standard and fixed inspection frequency cannot effectively cover all potential risk points, nor can they precisely target high-risk categories for prioritized inspections. Optimizing the sampling inspection scheme based on this uneven data allows regulatory authorities to focus on high-risk categories first, enhancing the precision of inspections under limited resources and budgets.
Moreover, to reveal the temporal trends of sampling qualification of major food categories in different years,
Figure 2 shows longitudinal analysis of the unqualified of 15 food categories from 2022 to 2024.
From a longitudinal perspective, the unqualified rates of different food categories vary from year to year. In 2022, sugar starch and its products exhibited higher unqualified rates. In 2023, issues were more prominent in frozen beverages and condiments. In 2024, problems were concentrated in convenience foods, fruit products, bee products, baked goods, puffed foods, canned foods, and beverages. High unqualified categories differ significantly across years. These annual differences are related to the focus of the inspection schemes in each year and may result from factors such as consumption trends, production technologies, or policy adjustments, which cause certain food categories to have more pronounced quality issues in specific years. This highlights the dynamic nature of food safety issues, requiring regulatory authorities to flexibly adjust inspection strategies to address food safety risks in different years. In this context, risk prediction based on food characteristics to optimize inspection schemes can improve inspection efficiency and the ability to detect risks.
5.1.3. Data Feature Attributes
There are significant differences in safety risk performance among food categories, and these risks are influenced by multiple factors.
Table 7 selects time, spatial, and stage-related variables closely associated with food production, circulation, and inspection processes, in order to more comprehensively represent the risk attributes of the food sampling data. The production region reflects the geographic distribution of food sources, which helps identify regional risks. The sampling stage distinguishes different phases such as production, circulation, and catering, capturing stage-specific risk attributes; in terms of packaging, pre-packed and bulk foods typically differ in hygiene conditions and risk levels; and by encoding production/purchase and sampling times into seasonal intervals, the effects of temperature and humidity on food quality are taken into account.
5.1.4. Data Preprocessing
Feature selection is based on the practical application needs of food safety inspection data. For example, regarding the production region, foods from different areas may experience variations in production environments, regulatory enforcement, and food processing standards. Concerning the sampling stage, foods face different safety risks at the production, circulation, and catering phases. As for the packaging type, bulk foods are generally more susceptible to external contamination. Finally, considering the production or purchase season and the sampling season, foods are more prone to spoilage during high-temperature periods, while cold seasons may affect storage conditions.
Table 8 shows the sample features, feature attributes and their assigned values of the inspection data samples.
5.2. Model Construction and Results Analysis
The modeling process is conducted around three main modules: data preprocessing, feature construction, and multi-model training and evaluation, with the specific workflow as follows:
(1) Data Preprocessing: Core fields including “Product Category,” “Sampling Unit Name,” “Inspection Result,” and “Manufacturer Address” are selected, and redundant information is removed. Categorical features are re-encoded, and the “Sampling Unit Name” is classified into three categories: Production, Distribution, and Catering, based on keyword matching. Keywords for the production category include factory, processing, workshop, and so on. For the distribution category, keywords include wholesaler, retailer, supermarket, warehouse, and so on. For the catering category, keywords include canteen, guesthouse, restaurant, as well as various types of small eateries. This process is supplemented with manual secondary review. Administrative region information is extracted from the “Manufacturer Address” field and mapped to region category codes. The “Inspection Level” and “Specification/Model” fields are standardized and mapped to discrete integer codes. “Production Date” and “Report Date” are converted into seasonal categories based on months. The “Inspection Result” field is mapped to 0 (qualified) and 1 (unqualified), with unidentifiable labels removed.
(2) Feature Construction: Six processed variables are selected as input features, including production area, inspection level, packaging status, production season, sampling season, and sampling stage. The “Inspection Result” (qualified status) is used as the supervised learning label. The classification of qualified versus unqualified directly corresponds to the official report’s “Inspection Result” column, without any subjective human judgment.
The selected features are all core items considered by food safety regulators when formulating inspection plans and correspond directly to risk points in the pre-made dish supply chain. Production region reflects differences in regulatory intensity and industrial concentration. Inspection stage corresponds to risk changes across production, distribution, and catering phases. Packaging type relates to the potential for secondary contamination of bulk foods. Production/purchase season and sampling season capture seasonal deterioration patterns driven by temperature and humidity.
(3) Model Training and Evaluation: For each category, six models are constructed, including two sampling approaches that over-sampling SMOTE (Synthetic Minority Over-sampling Technique) and under-sampling Random, and one cost-sensitive approach Weight and two classification algorithms that SVM and Random Forest. Grid search is implemented to tune the key hyperparameters of each model. For overfitting control, all models were evaluated through ten-fold stratified cross-validation to assess generalization performance. For weighted random forest, max_features was set to ‘sqrt’ and the maximum tree depth was limited. For class weights, the minority class weight in weighted SVM was set to the majority-to-minority sample ratio; for weighted random forest, it was empirically set to 2 or 3 and jointly tuned with other hyperparameters during grid search. Ten-fold stratified cross-validation is employed, where the original dataset is randomly split into 10 roughly equal subsets, with training and evaluation performed on different splits. For the weight settings, in weighted SVM, the minority class weight is set to the majority-to-minority sample ratio; in weighted Random Forest, the minority class weight is set to 2 or 3 based on relevant studies. The main evaluation metrics include Precision, Recall, and F1-score. To further evaluate model performance under class imbalance, this study also reports AUC-ROC, AUPRC, MCC, and Balanced Accuracy for the Weight + RF model.
Table 9 reports the classification performance of the six combined algorithms across the retained product categories. For starch and starch products, Weight + RF achieved the best overall result, with a Precision of 0.7857 and an F1 Score of 0.3929. For fruit products, Weight + RF obtained a relatively high Precision of 0.6071, but its Recall remained limited. For vegetable products, prediction is less stable because the number of non-compliant samples is small.
To provide a more complete evaluation under class imbalance, additional metrics are calculated for the Weight + RF mode in
Table 10. Starch and starch products achieves an AUC-ROC of 0.7778 and an MCC of 0.4429, indicating useful discriminative ability. Vegetable products recorded weak threshold-based classification results, but the AUC-ROC of 0.7265 suggests that the model still retained some ranking ability. These results indicate that model performance should be interpreted together with sample size and category imbalance.