Method and device for analyzing influencing factors of food comprehensive risk rating

By processing food inspection results and using integrated learning models, the problem of existing technologies being unable to understand the impact of food risk level factors has been solved. This has enabled accurate analysis of important factors and reduction of risk levels, thus ensuring food safety.

CN115456050BActive Publication Date: 2026-08-04HUBEI PROVINCIAL INST FOR FOOD SUPERVISION & TEST
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUBEI PROVINCIAL INST FOR FOOD SUPERVISION & TEST
Filing Date
2022-08-25
Publication Date
2026-08-04

AI Technical Summary

Technical Problem

Current technology cannot provide a comprehensive understanding of the impact of various factors on the formation of food risk levels, nor can it reduce food risk levels by specifically adjusting key influencing factors, thus affecting food safety.

Method used

By processing food inspection results, including resampling, feature construction, and unique heat coding, an ensemble learning model is built to determine the degree of influence of influencing factors on risk levels.

Benefits of technology

Accurately and comprehensively identify the impact of key influencing factors on food risk levels, helping to make targeted adjustments to reduce risk levels and ensure food safety.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115456050B_ABST
    Figure CN115456050B_ABST
Patent Text Reader

Abstract

The application relates to the food technology field and provides a food comprehensive risk grade influencing factor analysis method and device. The method comprises the following steps: obtaining a first comprehensive risk grade of a single food according to a food inspection result in first to-be-processed data; resampling food data with a few comprehensive risk grades to obtain second to-be-processed data; performing feature construction and one-hot encoding according to the second to-be-processed data to obtain third to-be-processed data; performing influencing factor classification on the third to-be-processed data to obtain a to-be-processed data set; constructing an integrated learning model; inputting the to-be-processed data set into the integrated learning model to obtain a second comprehensive risk grade of a single food category; and determining the influence degree of an influencing factor on the second comprehensive risk grade according to the relationship between the second comprehensive risk grade and the corresponding influencing factor. The method provided by the application can more accurately and comprehensively obtain the influence degree of important influencing factors on the comprehensive risk grade of food.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of food technology, specifically to a method and apparatus for analyzing factors influencing the comprehensive risk level of food. Background Technology

[0002] Currently, there are various evaluation methods for classifying food risk levels. However, these classifications can only indicate the level of safety risk inherent in the food itself. They cannot provide a deeper understanding of the influence of various factors on the formation of food risk levels. Consequently, they cannot reduce food risk levels and ensure the food safety of the people by making targeted adjustments to key influencing factors. Summary of the Invention

[0003] This application provides a method and apparatus for analyzing the influencing factors of comprehensive food risk level, which solves the technical problem that the prior art cannot understand the degree of influence of various factors on the formation of food risk level, and cannot reduce food risk level by targeted adjustment of important influencing factors, so as to ensure the food safety of the people.

[0004] In a first aspect, embodiments of this application provide a method for analyzing factors influencing the overall risk level of food, including:

[0005] The first comprehensive risk level of a single food item is obtained based on the food inspection results in the first data to be processed. The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level. The order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level.

[0006] The food data of the few comprehensive risk levels are resampled, and the resampled data is added to the first data to be processed to obtain the second data to be processed.

[0007] Based on the second data to be processed, feature construction and one-hot encoding are performed to obtain the third data to be processed;

[0008] The third set of data to be processed is classified according to influencing factors to obtain the dataset to be processed;

[0009] Construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category;

[0010] Based on the relationship between the second comprehensive risk level and the corresponding influencing factors, the degree of influence of the influencing factors on the second comprehensive risk level is determined.

[0011] In one embodiment, obtaining the first comprehensive risk level of a single food item based on the food inspection results in the first data to be processed includes:

[0012] The risk level of the test results of multiple items corresponding to a single food in the first data to be processed is classified to obtain the risk level of the multiple test items corresponding to the single food.

[0013] The risk levels of the multiple inspection items are weighted, and the weighted risk levels of the multiple inspection items are input into the softmax function to obtain the first comprehensive risk level of the individual food.

[0014] In one embodiment, the step of constructing features and performing one-hot encoding based on the second data to be processed to obtain the third data to be processed includes:

[0015] The food freshness of a single food item is constructed based on the food sampling date, food production date, and food shelf life in the second data to be processed.

[0016] The month in the production date of the food is uniquely encoded to obtain the encoded month.

[0017] The food freshness of the individual food and the coded month are added to the second data to be processed, and the food sampling date and the food production date are removed from the second data to be processed to obtain the third data to be processed.

[0018] In one embodiment, constructing the food freshness of a single food item based on the food sampling date, food production date, and food shelf life in the second data to be processed includes:

[0019] If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is greater than 1 day, then the freshness of the single food item is 0.

[0020] If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is equal to 1 day, then the freshness of the single food item is 1.

[0021] If the sampling date of a single food item is inconsistent with the production date, then the freshness of the single food item is the ratio of the number of days obtained by subtracting the production date from the sampling date to the shelf life of the single food item.

[0022] In one embodiment, constructing the ensemble learning model includes:

[0023] Utilize decision tree algorithms, extreme gradient boosting algorithms, or random forest algorithms to construct ensemble learning models.

[0024] In one embodiment, after constructing the ensemble learning model, the following is included:

[0025] The hyperparameters of the ensemble learning model are tuned using Bayesian optimization.

[0026] In one embodiment, before obtaining the first comprehensive risk level of a single food item based on the food inspection results in the first data to be processed, the process includes:

[0027] The sampled data is cleaned to obtain the first set of data to be processed.

[0028] Secondly, embodiments of this application provide a device for analyzing factors influencing the comprehensive risk level of food, comprising:

[0029] The first comprehensive risk level calculation module is used to: obtain the first comprehensive risk level of a single food based on the food inspection results in the first data to be processed. The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level, wherein the order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level.

[0030] The resampling module is used to: resampling the food data of the few comprehensive risk levels, and adding the resampled data to the first data to be processed to obtain the second data to be processed.

[0031] The feature construction and one-hot encoding module is used to: construct features and perform one-hot encoding based on the second data to be processed to obtain the third data to be processed;

[0032] The influencing factor classification module is used to classify the influencing factors of the third data to be processed to obtain the dataset to be processed.

[0033] An ensemble learning module is used to: construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category;

[0034] The influencing factor analysis module is used to determine the degree of influence of the influencing factors on the second comprehensive risk level based on the relationship between the second comprehensive risk level and the corresponding influencing factors.

[0035] Thirdly, embodiments of this application provide an electronic device, including a processor and a memory storing a computer program, wherein the processor executes the program to implement the steps of the method for analyzing the influencing factors of the comprehensive risk level of food as described in the first aspect.

[0036] Fourthly, embodiments of this application provide a computer program product, including a computer program that, when executed by a processor, implements the steps of the food comprehensive risk level influencing factor analysis method described in the first aspect.

[0037] The method and apparatus for analyzing the influencing factors of the comprehensive risk level of food provided in this application embodiment obtains the first comprehensive risk level of a single food based on the food inspection results in the first data to be processed. It then resamples the food data for a few comprehensive risk levels and adds the resampled data to the first data to be processed to obtain the second data to be processed. Based on the second data to be processed, it performs feature construction and one-hot encoding to obtain the third data to be processed. It then classifies the influencing factors in the third data to obtain the dataset to be processed. An ensemble learning model is constructed, and the dataset to be processed is input into the ensemble learning model to obtain the second comprehensive risk level of a single food category. Finally, based on the relationship between the second comprehensive risk level and the corresponding influencing factors, it determines the degree of influence of the influencing factors on the second comprehensive risk level. This application's embodiments resample food data for a small number of comprehensive risk levels to avoid neglecting small sample data and fully uncover important influencing factors across all risk levels. Feature construction of the data allows for the discovery and characterization of important influencing factors that cannot be directly used. One-hot encoding of the data effectively expands the dimensions of influencing factors. Therefore, by inputting the resampled, feature-constructed, and one-hot encoded data into the ensemble learning model, the influence of important influencing factors on the comprehensive risk level of food can be obtained more accurately and comprehensively. This helps to reduce food risk levels by specifically adjusting important influencing factors, thereby ensuring the food safety of the public. Attached Figure Description

[0038] To more clearly illustrate the technical solutions in this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0039] Figure 1 This is one of the flowcharts illustrating the method for analyzing the influencing factors of the comprehensive risk level of food provided in the embodiments of this application;

[0040] Figure 2 This is the second flowchart illustrating the method for analyzing the influencing factors of the comprehensive risk level of food provided in this application embodiment;

[0041] Figure 3 This is the third flowchart illustrating the method for analyzing the influencing factors of the comprehensive risk level of food provided in this application embodiment;

[0042] Figure 4 This is a ranking diagram of influencing factors before unique heat coding in the food comprehensive risk level influencing factor analysis method provided in this application embodiment;

[0043] Figure 5This is a ranking diagram of influencing factors after unique heat coding in the food comprehensive risk level influencing factor analysis method provided in the embodiments of this application;

[0044] Figure 6 A schematic diagram of the structure of the food comprehensive risk level influencing factor analysis device provided in the embodiments of this application;

[0045] Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation

[0046] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below with reference to the accompanying drawings of the embodiments. Obviously, the described embodiments are only some embodiments of this application, not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0047] Figure 1 This is one of the flowcharts illustrating the method for analyzing the influencing factors of the comprehensive risk level of food provided in this application. (Refer to...) Figure 1 This application provides a method for analyzing the influencing factors of the comprehensive risk level of food, which may include:

[0048] 101. Obtain the first comprehensive risk level of a single food item based on the food inspection results in the first set of data to be processed;

[0049] The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level. The number of foods in the majority comprehensive risk level is on a much larger scale than the number of foods in the minority comprehensive risk level. For example, if there are tens of thousands of foods in the first comprehensive risk level 1, and only a few thousand, a few hundred, a few dozen, or a few foods in the first comprehensive risk level 2, then foods in the first comprehensive risk level 1 are considered foods in the majority comprehensive risk level, and foods in the first comprehensive risk level 2 are considered foods in the minority comprehensive risk level. In this embodiment, the food can be meat products, which can include various categories of meat products such as cooked meat products and pre-prepared meat products.

[0050] 102. Resample a small number of food data with comprehensive risk levels, and add the resampled data to the first data to be processed to obtain the second data to be processed.

[0051] The first comprehensive risk level, from 1 to 5, represents: safe (no contamination during inspection, all indicators meet standards), no alarm (small amount of hazardous substances present), slightly alarm (hazardous substances within acceptable range), moderate alarm (hazardous substances affect health to some extent), and severely alarm (hazardous substances seriously harm health). Since a large proportion of actual meat products are at risk level 1, meaning most sampled foods are safe and alarm-free, containing little or no hazardous substances that pose a threat to human health, the model assumes a balanced amount of data across different risk levels. If there are significant differences in data volume between these levels, the training model, in pursuit of higher accuracy, may favor the larger number of samples at the risk level while neglecting smaller ones. This can lead to the overlooking of important influencing factors within the smaller risk level samples, preventing the full identification of crucial factors across all risk levels. Therefore, it is necessary to resample the food data for a small number of comprehensive risk levels. That is, in the first set of data to be processed, the food data for each level other than the first comprehensive risk level of 1 are resampled to increase the amount of food data for a small number of comprehensive risk levels.

[0052] In this embodiment, taking the national meat product sampling data published by the Market Supervision Administration and the testing data from the Hubei Provincial Food Inspection Institute as examples, the first set of data to be processed totaled 38,315 items. Among them, 29,770 items were meat products with a first comprehensive risk level of 1, accounting for 77.7% of the total. The data for meat products with first comprehensive risk levels of 2, 3, 4, and 5 were 1,001, 1,686, 4,713, and 1,145 items, respectively. The total number of meat products with first comprehensive risk levels of 2 and 5 accounted for less than 3% of the total number of all first comprehensive risk level data. Due to the severe imbalance in the samples, although the unsampled data showed a high accuracy in the classification model, samples with first comprehensive risk levels other than 1 were ignored. Therefore, the imbalance problem can be solved by resampling. The amount of data for level 1 meat products remains unchanged, while the amount of data for levels 2, 3, 4, and 5 meat products is randomly expanded to two-eighths of the amount of level 1 meat products, or to three-sevenths of the amount of level 1 meat products, or to four-sixths of the amount of level 2, 3, 4, and 5 meat products. The resampled data amounts are shown in Table 1.

[0053] Table 1. Data volume after resampling

[0054]

[0055] 103. Based on the second data to be processed, perform feature construction and one-hot encoding to obtain the third data to be processed;

[0056] 104. Classify the influencing factors of the third set of data to be processed to obtain the dataset to be processed;

[0057] Because there are too many variables affecting the overall risk level of meat products, inputting all variables into the training model would lead to low training efficiency and overly dispersed influencing factors. Therefore, the third set of data to be processed is classified into influencing factors, and the variables affecting the overall risk level of meat products are regrouped, with each group designated as an influencing factor. For example, the provinces producing meat products can be divided into eight major categories based on their geographical location, with those produced outside of China classified as overseas. These eight categories are then designated as influencing factor areas. Information such as the sampling location of meat products is similarly processed and classified as influencing factor location. The third set of data to be processed after classification is the dataset to be processed, which includes various variables affecting the second overall risk level.

[0058] 105. Construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category;

[0059] 106. Based on the relationship between the second comprehensive risk level and the corresponding influencing factors, determine the degree of influence of the influencing factors on the second comprehensive risk level.

[0060] The input of the ensemble learning model is various variables that affect the second comprehensive risk level, and the output is the corresponding second comprehensive risk level. Based on the different second comprehensive risk levels and corresponding variables for different food types, the relationship between different second comprehensive risk levels and corresponding influencing factors can be obtained, thereby obtaining the importance of different influencing factors in the formation of the second comprehensive risk level. By ranking the importance of different influencing factors, the degree of influence of different influencing factors on the second comprehensive risk level can be determined.

[0061] The method for analyzing the influencing factors of the comprehensive risk level of food provided in this embodiment obtains the first comprehensive risk level of a single food based on the food inspection results in the first data to be processed. It then resamples the food data for a few comprehensive risk levels and adds the resampled data to the first data to be processed, obtaining the second data to be processed. Based on the second data to be processed, it performs feature construction and one-hot encoding to obtain the third data to be processed. It then classifies the influencing factors in the third data to obtain the dataset to be processed. An ensemble learning model is constructed, and the dataset to be processed is input into the ensemble learning model to obtain the second comprehensive risk level of a single food category. Finally, based on the relationship between the second comprehensive risk level and the corresponding influencing factors, it determines the degree of influence of the influencing factors on the second comprehensive risk level. This embodiment resamples food data from a small number of comprehensive risk levels to avoid neglecting small sample data and fully uncover important influencing factors across all risk levels. It also constructs features from the data to uncover and characterize important influencing factors that cannot be directly used. Furthermore, it performs one-hot encoding on the data to effectively expand the dimensions of the influencing factors. Therefore, by inputting the resampled, feature-constructed, and one-hot encoded data into the ensemble learning model, the influence of important influencing factors on the comprehensive risk level of food can be obtained more accurately and comprehensively. This helps to reduce food risk levels by specifically adjusting important influencing factors, thereby ensuring the food safety of the public.

[0062] Figure 2 This is the second flowchart illustrating the method for analyzing the influencing factors of the comprehensive risk level of food provided in this application. (Refer to...) Figure 2 In one embodiment, obtaining a first comprehensive risk level for a single food item based on food inspection results in the first data to be processed may include:

[0063] 201. Divide the test results of multiple items corresponding to a single food in the first data to be processed into risk levels to obtain the risk levels of multiple test items corresponding to the single food.

[0064] There are many types of meat products, such as smoked and cooked sausages, ham products, braised meat products, cured meat products, seasoned meat products, dried cooked meat products, smoked and grilled products, and fermented meat products. The required testing items differ and are not unique for different types of meat products. The classification of meat product testing items is shown in the table below:

[0065] Table 2 Inspection Items for Meat Products

[0066]

[0067]

[0068] Although the testing items are the same for the same type of meat products, such as the same type of smoked sausages, the test results may differ for individual smoked sausage products within that category. Suppose a smoked sausage product is tested for three items; then the results of these three items are graded. For example, the risk level of the result for item A is level 1, the risk level of the result for item B is level 2, and the risk level of the result for item C is level 3. This gives the risk level of the three test items corresponding to that single smoked sausage product.

[0069] 202. Weight the risk levels of the multiple inspection items, and input the weighted risk levels of the multiple inspection items into the softmax function to obtain the first comprehensive risk level of a single product.

[0070] For example, the risk levels of three inspection items corresponding to a certain smoked sausage product are weighted, and the risk levels of the three weighted inspection items are input into the softmax function to obtain the first comprehensive risk level of the smoked sausage product.

[0071] It should be noted that if a risk level of 5 is found in the detection of pathogenic microorganism Salmonella or any other item, the first comprehensive risk level of that single product will be directly determined to be level 5, and the risk levels of multiple test items will no longer be weighted and summed using a function.

[0072] This embodiment classifies the risk levels of multiple test results for a single food item, then weights the resulting multiple risk levels, and uses the softmax function to obtain the first comprehensive risk level for that single food item. This allows the risk level corresponding to important test results to be used as the main criterion for determining the first comprehensive risk level, so that the first comprehensive risk level can more accurately represent the test results of the single food item.

[0073] Figure 3 This is the third flowchart illustrating the method for analyzing the influencing factors of the comprehensive risk level of food provided in this application. (Refer to...) Figure 3 In one embodiment, the process of constructing features and performing one-hot encoding based on the second data to be processed to obtain the third data to be processed may include:

[0074] 301. Construct the food freshness of a single food item based on the food sampling date, food production date, and food shelf life in the second set of data to be processed;

[0075] Since the data representation of food sampling date and food production date in the second set of data to be processed cannot be identified in the model, the food freshness of a single food can be constructed using the food sampling date, food production date, and food shelf life. This allows the food freshness to be identified by the model and represents the attributes of the food sampling date and food production date.

[0076] 302. Perform unique thermal coding on the month in the food production date to obtain the coded month;

[0077] One-hot encoding, also known as one-bit effective encoding, can handle non-continuous data features. It not only expands the feature dimension to a certain extent but also handles missing data. It's a process of converting categorical variables into a form easily utilized by machine learning algorithms. Currently, one-hot encoding is widely used to process features as input variables to improve the model's classification accuracy, decision quality, and computation time. This embodiment uses one-hot encoding to process the month in the food production date, which not only effectively increases the dimension of the month data but also allows for a more specific analysis of the impact of each month on the second comprehensive risk level.

[0078] It should be noted that one-hot encoding can also be performed on other variables in the second set of data to be processed. There is no limitation here, but caution should be exercised when selecting variables for one-hot encoding. Blindly expanding all variables can easily cause the curse of dimensionality and seriously affect the model performance.

[0079] 303. Add the freshness of the individual food and the month after coding to the second data to be processed, and remove the food sampling date and food production date from the second data to be processed to obtain the third data to be processed.

[0080] Since food freshness has already been used to characterize the attributes of food sampling date and food production date, the food sampling date and food production date can be removed from the second set of data to be processed.

[0081] It should be noted that in practical applications, there is no strict timing relationship between steps 301 and 302; that is, they can be executed simultaneously, or either step can be executed first, depending on the actual needs, and no restrictions are imposed here.

[0082] This embodiment constructs features from the food sampling date and food production date in the second data to be processed, and performs unique hot coding on the month in the second data to be processed. This allows the food sampling date and food production date to be substituted into the analysis of factors affecting the second comprehensive risk level based on food freshness. At the same time, the expanded month is substituted into the analysis of factors affecting the second comprehensive risk level, making the analysis of factors affecting the second comprehensive risk level more comprehensive and accurate.

[0083] In one embodiment, constructing the food freshness of a single food item based on the food sampling date, food production date, and food shelf life in the second data to be processed may include...

[0084] If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is greater than 1 day, then the freshness of the single food item is 0.

[0085] If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is equal to 1 day, then the freshness of the single food item is 1.

[0086] If the sampling date of a single food item is inconsistent with the production date, the freshness of that single food item is the ratio of the number of days obtained by subtracting the production date from the sampling date to the shelf life of that single food item.

[0087] This means that the shelf life of food and the value of the food sampling date minus the food production date both need to be converted into days for calculation.

[0088] This embodiment constructs the food freshness of a single food by using the relationship between the food sampling date and the food production date, as well as the food shelf life in days. This not only fully reflects the food's attributes in the time dimension, but also transforms them into variables that the model can recognize.

[0089] In one embodiment, the variables of the dataset to be processed obtained after classifying the influencing factors of the third dataset to be processed can be shown in the following table:

[0090] Table 3 Description of variables in the dataset to be processed

[0091]

[0092]

[0093]

[0094] Figure 4 This is a ranking diagram of influencing factors before unique heat coding in the food comprehensive risk level influencing factor analysis method provided in this application embodiment;

[0095] Figure 5 This is a ranking diagram of influencing factors after unique heat coding in the food comprehensive risk level influencing factor analysis method provided in the embodiments of this application;

[0096] Reference Figure 4-5 In one embodiment, an ensemble learning model can be constructed using a decision tree algorithm, an extreme gradient boosting algorithm, or a random forest algorithm.

[0097] Ensemble learning accomplishes learning tasks by building and combining multiple learners, sometimes referred to as a multi-classifier system. Combining multiple learners often yields significantly better generalization performance than a single learner. Based on the method of generating individual learners, it can be divided into two categories: Boosting and Bagging. In Boosting, individual learners have strong dependencies and must be generated sequentially, while in Bagging, individual learners do not have strong dependencies and multiple learners are generated simultaneously in parallel.

[0098] Individual learners are also called base learners. When individual learners are the same, it is called a "homogeneous" ensemble. When individual learners are different, it is called a "heterogeneous" ensemble.

[0099] Decision tree (DT) is a common machine learning method, mainly consisting of feature selection, decision tree generation, and decision tree pruning. Feature selection in decision trees is based on relevant information theory, corresponding to the partitioning of the feature space and the generation of the decision tree. Decision tree pruning uses a validation dataset to prune the generated tree and select the optimal subtree. Feature selection is the core of the decision tree algorithm; the first step in selecting features for partitioning is to determine the information content of that attribute. Classic decision tree algorithms include ID3, C4.5, and CART, which use information gain, information gain ratio, and Gini coefficient for feature selection, respectively. Decision trees have low computational complexity, easy-to-understand outputs, are insensitive to missing values, and can handle irrelevant data.

[0100] Extreme Gradient Boosting Tree (XGBOOST) is a classic example of Boosting algorithms. The base model is built-in stepwise, with a regularization term added to the training set. The loss function is transformed at each iteration, and the next iteration only begins after the previous one is completed. This not only improves speed and accuracy but also effectively suppresses overfitting. In this embodiment, the base model uses a CART tree, iterating through multiple trees sequentially. The final output is the second comprehensive risk level.

[0101] Random Forest (RF) is an extended variant of bagging, using decision trees as base learners to build bagging ensembles and further introducing random attribute selection during decision tree training. The Random Forest algorithm boasts high accuracy, good generalization ability, and can effectively handle large datasets, demonstrating powerful performance in many real-world tasks. This embodiment uses the dataset to be processed as the input variable. First, a subset containing K attributes (K ≥ 1) is randomly selected. Then, decision trees are constructed from N (N ≥ 2) subsets containing different subsets. Finally, a voting mechanism is used to determine the second comprehensive risk level.

[0102] For each of the above models, the influence of influencing factors on the second comprehensive risk level can be evaluated using the feature importance index, where "feature" in feature importance refers to the influencing factor.

[0103] In tree-based ensemble models, the importance of a feature is the average of its importance across all trees in the model. The importance of a feature on a single tree is calculated by summing the reduction in squared loss after splitting that feature; that is, summing the number of nodes where that feature appears across all trees. The more times a feature appears across all trees, the more important it is. Based on the influencing factors in Table 3, the extreme gradient boosting tree algorithm is used as an example to evaluate the impact of these factors on the second comprehensive risk level of meat products. The results are as follows: Figure 4 and Figure 5 As shown.

[0104] from Figure 4 As can be seen, the top three factors influencing the second comprehensive risk level are lasting time, month, and shelf life, while the impact of whether a production enterprise is a large-scale producer or a large-scale distributor is minimal. This is because the data before one-hot coding lacked specific classification of production and distribution enterprises, such as failing to categorize them as small and medium-sized enterprises, resulting in a coarse classification and low identifiability of this influencing factor. Month has a significant impact on the second comprehensive risk level of meat products; therefore, after one-hot coding of the month, the extreme gradient boosting tree algorithm was used to process the influencing factors after one-hot coding. The results are as follows: Figure 5 As shown.

[0105] according to Figure 5 The influencing factors can be divided into three levels:

[0106] 1. Lasting: This indicator directly reflects the freshness of the sampled food, and also indirectly includes complex factors that are difficult to obtain, such as transportation and storage. The position of this indicator to a certain extent reflects that there are many uncertain risks in food safety.

[0107] 2. Shelf life and area: The difference between the two is not significant. However, the length of the shelf life has different limitations on preservatives and storage conditions. Food safety issues may also occur under different environments, so the impact of this aspect should also be taken seriously.

[0108] 3. Food type, location, province_consistency, month_7, month_6, month_8, month_5: Food type and sampling location indicate differences in production conditions and other factors, significantly impacting the second comprehensive risk level of food. Province_consistency also has a high impact on the second comprehensive risk level. This indicator shows whether the production province and the sampling province are consistent, including information on the transportation time and distance experienced by the product before sampling. The results show that it has a significant impact on food safety. Using unique heat coding allows for a detailed understanding of the impact of each month on the classification of the second comprehensive risk level of food. The months ranked highest are July, May, June, and August. Months, as direct variables representing seasonal factors, include complex factors that are difficult to collect, such as the external temperature environment throughout the year, seasonal demand, and seasonal production. The importance of the months before and after unique heat coding fully demonstrates the large amount of information contained within and the significant impact on the safety risks of meat products.

[0109] In addition, other influencing factors can be encoded using one-hot encoding, which is not limited here, but care should be taken to avoid the curse of dimensionality.

[0110] It should be noted that the classification performance of the second comprehensive risk level classification can also be evaluated based on the confusion matrix and performance evaluation metrics. These performance evaluation metrics may include accuracy, precision, recall, and F1 score (the harmonic mean of precision and recall).

[0111] This embodiment utilizes decision tree algorithms, extreme gradient boosting algorithms, or random forest algorithms to construct an ensemble learning model, which can accurately and effectively determine the degree of influence of various influencing factors on the second comprehensive risk level.

[0112] In one embodiment, after constructing the ensemble learning model, Bayesian optimization can be used to adjust the hyperparameters of the ensemble learning model.

[0113] Since the parameter configurations of various algorithms differ, key parameters for different models are adjusted using Bayesian optimization to tune hyperparameters. Bayesian optimization finds the optimal parameter combination to improve model performance. This method is more efficient, faster, and more robust than grid search CV in sklearn. The hyperparameter tuning for each model is shown in the table below.

[0114] Table 4 Hyperparameter tuning for different models

[0115]

[0116] This embodiment uses Bayesian optimization to adjust the hyperparameters of the ensemble learning model, thereby improving the model's performance.

[0117] In one embodiment, the training set accuracy, test set accuracy, and F1 score can be used to evaluate the three models respectively. This embodiment uses the dataset variables obtained from the sampling data of the aforementioned meat products as an example. Based on a training set to test set ratio of 8:2, the specific details of the three models are shown in the table below:

[0118] Table 5 Comparison of Evaluation Indicators for Different Models

[0119]

[0120]

[0121] The following can be derived from the training set accuracy, test set accuracy, and F1 score of each model:

[0122] 1. After resampling, the classification performance of each model reached over 80% in F1 score, indicating good overall performance. The training set accuracy of the models reached over 94%, showing good learning performance and no significant difference in training performance among the models. However, the test set accuracy reflects the difference in generalization ability of different models. Among them, XGBOOST had the smallest average error between the test set accuracy and the training set accuracy. In terms of the comprehensive index F1 score, XGBOOST scored the highest. In comparison, XGBOOST is more suitable for the second comprehensive risk level evaluation analysis of meat product sampling data.

[0123] 2. Analysis based on different resampling scenarios reveals that the learning ability of the models significantly improves with an increase in the proportion of small samples. Under severely imbalanced sample conditions, the training set accuracy of all three models is higher than after resampling, reaching approximately 95%, while the test set accuracy is between 70% and 80%. While accuracy alone is acceptable for classifying performance, the F1 score (combining precision and recall) is noticeably worse, averaging only 35.20%. This indicates that relying solely on accuracy as a model evaluation criterion in imbalanced samples has low reliability. Resampling significantly improves the F1 score. When the resampling ratio increases from 8:2 to 6:4, the average F1 score increases by 7.73%, with DT, XGBOOST, and RF increasing by 9.13%, 7.06%, and 7.02%, respectively. Although DT shows the highest overall improvement, XGBOOST consistently achieves the highest F1 score across all resampling ratios. Comprehensive analysis shows that the ensemble learning model performs well in the classification of the second comprehensive risk level of meat products. Among them, XGBOOST performs better than single DT and RF in the evaluation and analysis of the second comprehensive risk level of meat products. Moreover, the performance of the model is significantly improved with the treatment of imbalanced categories.

[0124] In one embodiment, the sampling data may be cleaned to obtain the first comprehensive risk level of a single food item before the food inspection results in the first data to be processed are obtained.

[0125] Data cleaning mainly includes removing duplicate values, standardizing data size, correcting data logic, compressing data, filling in missing or null values, and discarding outliers. This process effectively improves data quality and ensures data integrity, uniqueness, and validity. Data cleaning is a complex and tedious task, taking up a significant amount of time in the overall project and impacting the final analysis results.

[0126] This embodiment performs data cleaning on meat product data. Meat product sampling data is diverse, with varying specifications, inspection items, and production dates for each food item. The shelf life field contains multiple records such as 30 days, 6 months, 12 months (vacuum-packed below 25℃), and 1 year. This embodiment uses daily units and removes other conditions such as temperature and packaging integrity to convert the shelf life time, ensuring uniformity in specifications and standards across all shelf life data. For meat product data without recorded shelf life, to ensure data accuracy and validity, all foods without recorded shelf life information are deleted without filling in any gaps. There is overlap in sampling province and sampling city information, and while province information is relatively complete, county-level records contain a large amount of missing data. Redundant information is removed by region based on province. For outliers with obvious errors, if it can be determined that they were entered incorrectly during manual recording, the correct values ​​are corrected instead of being deleted, preserving as much original information as possible to ensure data integrity. After cleaning, 38,315 of the 40,052 sampled data were retained, with a utilization rate of 95.66% of the original data. The amount of data loss was small, and the integrity of the data was preserved to the maximum extent.

[0127] This embodiment improves data quality and ensures data integrity by cleaning the sampled data.

[0128] The following describes the food comprehensive risk level influencing factor analysis device provided in the embodiments of this application. The food comprehensive risk level influencing factor analysis device described below and the food comprehensive risk level influencing factor analysis method described above can be referred to in correspondence.

[0129] Figure 6 A schematic diagram of the food comprehensive risk level influencing factor analysis device provided in this application embodiment. (Refer to...) Figure 6 This application provides a device for analyzing factors influencing the comprehensive risk level of food, which may include:

[0130] The first comprehensive risk level calculation module 601 is used to: obtain the first comprehensive risk level of a single food based on the food inspection results in the first data to be processed, wherein the first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level, and the order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level.

[0131] The resampling module 602 is used to: resampling the food data of the minority comprehensive risk level, and adding the resampled data to the first data to be processed to obtain the second data to be processed.

[0132] The feature construction and one-hot encoding module 603 is used to: perform feature construction and one-hot encoding based on the second data to be processed to obtain the third data to be processed;

[0133] The influencing factor classification module 604 is used to: classify the influencing factors of the third data to be processed to obtain the dataset to be processed;

[0134] The ensemble learning module 605 is used to: construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category;

[0135] The influencing factor analysis module 606 is used to: determine the degree of influence of the influencing factor on the second comprehensive risk level based on the relationship between the second comprehensive risk level and the corresponding influencing factor.

[0136] The food comprehensive risk level influencing factor analysis device provided in this embodiment obtains the first comprehensive risk level of a single food based on the food inspection results in the first data to be processed. It then resamples the food data for a few comprehensive risk levels and adds the resampled data to the first data to be processed, obtaining the second data to be processed. Based on the second data to be processed, it performs feature construction and one-hot encoding to obtain the third data to be processed. It then classifies the influencing factors in the third data to obtain the dataset to be processed. An ensemble learning model is constructed, and the dataset to be processed is input into the ensemble learning model to obtain the second comprehensive risk level of a single food category. Based on the relationship between the second comprehensive risk level and the corresponding influencing factors, it determines the degree of influence of the influencing factors on the second comprehensive risk level. This embodiment resamples food data from a small number of comprehensive risk levels to avoid neglecting small sample data and fully uncover important influencing factors across all risk levels. It also constructs features from the data to uncover and characterize important influencing factors that cannot be directly used. Furthermore, it performs one-hot encoding on the data to effectively expand the dimensions of the influencing factors. Therefore, by inputting the resampled, feature-constructed, and one-hot encoded data into the ensemble learning model, the influence of important influencing factors on the comprehensive risk level of food can be obtained more accurately and comprehensively. This helps to reduce food risk levels by specifically adjusting important influencing factors, thereby ensuring the food safety of the public.

[0137] In one embodiment, the first comprehensive risk level calculation module 601 is specifically used for:

[0138] The test results of multiple items corresponding to a single food in the first data to be processed are classified into risk levels to obtain multiple risk levels corresponding to the single food.

[0139] The multiple risk levels are weighted, and the weighted risk levels are input into the softmax function to obtain the first comprehensive risk level of the individual food.

[0140] In one embodiment, the feature construction and one-hot encoding module 603 is specifically used for:

[0141] The food freshness of a single food item is constructed based on the food sampling date, food production date, and food shelf life in the second data to be processed.

[0142] The month in the production date of the food is uniquely encoded to obtain the encoded month.

[0143] The food freshness of the individual food and the coded month are added to the second data to be processed, and the food sampling date and the food production date are removed from the second data to be processed to obtain the third data to be processed.

[0144] In one embodiment, the feature construction and one-hot encoding module 603 is specifically used for:

[0145] If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is greater than 1 day, then the freshness of the single food item is 0.

[0146] If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is equal to 1 day, then the freshness of the single food item is 1.

[0147] If the sampling date of a single food item is inconsistent with the production date, then the freshness of the single food item is the ratio of the number of days obtained by subtracting the production date from the sampling date to the shelf life of the single food item.

[0148] In one embodiment, the integrated learning module 605 is specifically used for:

[0149] Utilize decision tree algorithms, extreme gradient boosting algorithms, or random forest algorithms to construct ensemble learning models.

[0150] In one embodiment, a hyperparameter adjustment module (not shown in the figure) is further included for:

[0151] The hyperparameters of the ensemble learning model are tuned using Bayesian optimization.

[0152] In one embodiment, a data cleaning module (not shown in the figure) is further included, for:

[0153] The sampled data is cleaned to obtain the first set of data to be processed.

[0154] Figure 7 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 7 As shown, the electronic device may include: a processor 710, a communication interface 720, a memory 730, and a communication bus 740, wherein the processor 710, the communication interface 720, and the memory 730 communicate with each other via the communication bus 740. The processor 710 can call a computer program in the memory 730 to execute the steps of the food comprehensive risk level influencing factor analysis method, such as including:

[0155] The first comprehensive risk level of a single food item is obtained based on the food inspection results in the first data to be processed. The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level. The order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level.

[0156] The food data of the few comprehensive risk levels are resampled, and the resampled data is added to the first data to be processed to obtain the second data to be processed.

[0157] Based on the second data to be processed, feature construction and one-hot encoding are performed to obtain the third data to be processed;

[0158] The third set of data to be processed is classified according to influencing factors to obtain the dataset to be processed;

[0159] Construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category;

[0160] Based on the relationship between the second comprehensive risk level and the corresponding influencing factors, the degree of influence of the influencing factors on the second comprehensive risk level is determined.

[0161] Furthermore, the logical instructions in the aforementioned memory 730 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0162] On the other hand, this application also provides a computer program product, which includes a computer program that can be stored on a non-transitory computer-readable storage medium. When the computer program is executed by a processor, the computer can perform the steps of the food comprehensive risk level influencing factor analysis method provided in the above embodiments, such as including:

[0163] The first comprehensive risk level of a single food item is obtained based on the food inspection results in the first data to be processed. The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level. The order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level.

[0164] The food data of the few comprehensive risk levels are resampled, and the resampled data is added to the first data to be processed to obtain the second data to be processed.

[0165] Based on the second data to be processed, feature construction and one-hot encoding are performed to obtain the third data to be processed;

[0166] The third set of data to be processed is classified according to influencing factors to obtain the dataset to be processed;

[0167] Construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category;

[0168] Based on the relationship between the second comprehensive risk level and the corresponding influencing factors, the degree of influence of the influencing factors on the second comprehensive risk level is determined.

[0169] On the other hand, embodiments of this application also provide a processor-readable storage medium storing a computer program for causing a processor to perform the steps of the methods provided in the above embodiments, such as including:

[0170] The first comprehensive risk level of a single food item is obtained based on the food inspection results in the first data to be processed. The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level. The order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level.

[0171] The food data of the few comprehensive risk levels are resampled, and the resampled data is added to the first data to be processed to obtain the second data to be processed.

[0172] Based on the second data to be processed, feature construction and one-hot encoding are performed to obtain the third data to be processed;

[0173] The third set of data to be processed is classified according to influencing factors to obtain the dataset to be processed;

[0174] Construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category;

[0175] Based on the relationship between the second comprehensive risk level and the corresponding influencing factors, the degree of influence of the influencing factors on the second comprehensive risk level is determined.

[0176] The processor-readable storage medium can be any available medium or data storage device that the processor can access, including but not limited to magnetic memory (e.g., floppy disk, hard disk, magnetic tape, magneto-optical disk (MO)), optical memory (e.g., CD, DVD, BD, HVD), and semiconductor memory (e.g., ROM, EPROM, EEPROM, non-volatile memory (NAND FLASH), solid-state drive (SSD)).

[0177] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.

[0178] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.

[0179] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method of analyzing factors influencing the overall risk rating of a food product, characterized in that, include: The first comprehensive risk level of a single food item is obtained based on the food inspection results in the first data to be processed. The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level. The order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level. The first comprehensive risk level includes safe, no alarm, slight alarm, moderate alarm, and severe alarm. The food data of the few comprehensive risk levels are resampled, and the resampled data is added to the first data to be processed to obtain the second data to be processed. Based on the second data to be processed, feature construction and one-hot encoding are performed to obtain the third data to be processed, including: The food freshness of a single food item is constructed based on the food sampling date, food production date, and food shelf life in the second data to be processed, including: If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is greater than 1 day, then the freshness of the single food item is 0. If the sampling date of a single food item is the same as the production date of the food item, and the shelf life of the single food item is equal to 1 day, then the freshness of the single food item is 1. The month in the production date of the food is uniquely encoded to obtain the encoded month. The food freshness of the individual food and the coded month are added to the second data to be processed, and the food sampling date and the food production date are removed from the second data to be processed to obtain the third data to be processed. The third set of data to be processed is classified according to influencing factors to obtain the dataset to be processed; Construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category; Based on the relationship between the second comprehensive risk level and the corresponding influencing factors, the degree of influence of the influencing factors on the second comprehensive risk level is determined.

2. The food integrated risk level influencing factor analysis method according to claim 1, characterized by, The process of obtaining the first comprehensive risk level of a single food item based on the food inspection results in the first set of data to be processed includes: The risk level of the test results of multiple items corresponding to a single food in the first data to be processed is classified to obtain the risk level of the multiple test items corresponding to the single food. The risk levels of the multiple inspection items are weighted, and the weighted risk levels of the multiple inspection items are input into the softmax function to obtain the first comprehensive risk level of the individual food.

3. The food integrated risk level influencing factor analysis method according to claim 1, characterized by, The process of constructing the food freshness of a single food item based on the food sampling date, food production date, and food shelf life in the second data to be processed also includes: If the sampling date of a single food item is inconsistent with the production date of the food item, then the freshness of the single food item is the ratio of the number of days obtained by subtracting the production date from the sampling date of the single food item to the shelf life of the single food item in days.

4. The food integrated risk level influencing factor analysis method according to claim 1, characterized by, The construction of the ensemble learning model includes: Utilize decision tree algorithms, extreme gradient boosting algorithms, or random forest algorithms to construct ensemble learning models.

5. The food integrated risk level influencing factor analysis method according to claim 4, characterized by, After constructing the ensemble learning model, the following is included: The hyperparameters of the ensemble learning model are tuned using Bayesian optimization.

6. The food integrated risk level influencing factor analysis method according to claim 1, characterized by, Before obtaining the first comprehensive risk level of a single food item based on the food inspection results in the first data to be processed, the process includes: The sampled data is cleaned to obtain the first set of data to be processed.

7. A food integrated risk level influencing factor analysis device characterized by comprising: The method for analyzing the influencing factors of the comprehensive risk level of food as described in claim 1 includes: The first comprehensive risk level calculation module is used to: obtain the first comprehensive risk level of a single food based on the food inspection results in the first data to be processed. The first comprehensive risk level includes a majority comprehensive risk level and a minority comprehensive risk level, wherein the order of magnitude of the number of foods in the majority comprehensive risk level is greater than the order of magnitude of the number of foods in the minority comprehensive risk level. The resampling module is used to: resample the food data of the few comprehensive risk levels, and add the resampled data to the first data to be processed to obtain the second data to be processed. The feature construction and one-hot encoding module is used to: construct features and perform one-hot encoding based on the second data to be processed to obtain the third data to be processed; The influencing factor classification module is used to classify the influencing factors of the third data to be processed to obtain the dataset to be processed. An ensemble learning module is used to: construct an ensemble learning model, input the dataset to be processed into the ensemble learning model, and obtain the second comprehensive risk level of a single food category; The influencing factor analysis module is used to determine the degree of influence of the influencing factors on the second comprehensive risk level based on the relationship between the second comprehensive risk level and the corresponding influencing factors.

8. An electronic device comprising a processor and a memory having a computer program stored therein, characterized in that, When the processor executes the computer program, it implements the steps of the method for analyzing the influencing factors of the comprehensive risk level of food as described in any one of claims 1 to 6.

9. A computer program product comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the method for analyzing the influencing factors of the comprehensive risk level of food as described in any one of claims 1 to 6.