Food safety traceability detection method and system based on machine learning
Through the food safety traceability detection method based on machine learning, the problem that small food producers and operators are difficult to supervise and analyze food supply chain data is solved, accurate prediction and rapid traceability of food safety risks is achieved, and the efficiency and accuracy of food safety testing is improved. sex.
Patent Information
- Application Number
- CN202411527801.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-30
- Publication Date
- 2025-02-21
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Due to small scale and poor conditions, small food producers and operators have difficulty effectively supervising and analyzing food supply chain data, which makes it difficult to predict and trace food safety risks, which increases the occurrence of food safety accidents.
Using machine learning-based food safety traceability detection method, we collect and preprocess food supply chain data, analyze and detect characteristic data, build a food safety risk prediction model, and improve the accuracy and efficiency of the model through optimization algorithms.
Accurate prediction and rapid traceability of food safety risks has been achieved, the efficiency and accuracy of food safety testing has been improved, the occurrence of food safety accidents has been reduced, and the health of consumers has been protected.
Smart Images

Figure CN119494667A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of food safety supervision, and in particular to a food safety traceability detection method and system based on machine learning. Background Art
[0002] For small-scale food producers and operators, small workshops, small grocery stores, small restaurants, and small vendors with small production and operation scales cannot meet the requirements that can only be met by large-scale food production and operation enterprises due to their own conditions. However, the business activities carried out by these small-scale food producers and operators are not only conducive to the development of the traditional food industry, but also increase employment opportunities for the masses and greatly enrich the daily lives of consumers. However, these small-scale food operations are accompanied by the shortcomings of scattered production and operation sites, poor production and operation environment, and non-compliant operations. If supervision is not in place, it is particularly easy to cause food safety problems, cause mass incidents, and directly endanger the lives of the masses. In the past, once a problem with a certain food was detected, the problematic food was immediately removed from the shelves to prevent it from continuing to circulate in the market, but the source of the problem was not traced back, resulting in the possibility that problematic food would continue to appear after re-production.
[0003] However, when conducting source tracing supervision and rectification of food safety issues for such “numerous, scattered and small” small food production and operation stores, it is not convenient to process and analyze large amounts of food supply chain data, and it is not convenient to predict potential food safety risk factors, which increases the occurrence of food safety accidents. At the same time, when products that do not meet food safety standards are found, due to the “numerous, scattered and small” small food production and operation stores, it is not convenient to quickly trace the source of the problem, and the problematic products cannot be isolated in time, causing the problem to expand.
[0004] Currently, no effective solution has been proposed for the problems in the related technologies. Summary of the invention
[0005] In view of the shortcomings of the prior art, the present invention proposes a food safety traceability detection method and system based on machine learning, which solves the problem that the existing food safety problem traceability supervision and rectification mentioned in the above background technology is not convenient for processing and analyzing a large amount of food supply chain data, and is not convenient for predicting potential food safety risk factors, thereby increasing the occurrence of food safety accidents. At the same time, when products that do not meet food safety standards are found, due to the "many, scattered and small" small food production and operation stores, it is not convenient to quickly trace the source of the problem, and the problem products cannot be isolated in time, causing the problem to expand.
[0006] To achieve the above objectives, the present invention is implemented through the following technical solutions:
[0007] According to one aspect of the present invention, a food safety traceability detection method based on machine learning is provided, and the food safety traceability detection method based on machine learning comprises the following steps:
[0008] S1. Collect various data in the food supply chain and pre-process them to obtain corresponding detection feature data;
[0009] S2. Analyze the obtained detection feature data through an analysis algorithm to obtain a food safety risk detection index;
[0010] S3. Based on the obtained food safety risk detection indicators, a food safety risk prediction model is constructed using a machine learning algorithm;
[0011] S4. Optimizing the constructed food safety risk prediction model through an optimization algorithm, and conducting safety testing on food samples through the optimized food safety risk prediction model;
[0012] S5. Based on the safety test results, determine whether the food meets the food safety standards. If it does, it will be marked as safe and allowed to enter the market. If it does not, the food sample will be isolated, the traceability procedure will be initiated, and corresponding measures will be taken;
[0013] Analyzing the obtained detection feature data through an analysis algorithm to obtain food safety risk detection indicators includes the following steps:
[0014] S21. Obtaining and identifying abnormal detection feature data that affects food safety risk detection efficiency from the obtained detection feature data;
[0015] S22. Determine the measurement method for food safety risk detection efficiency, set a preset threshold as the best acceptable detection efficiency, and set a correction strategy;
[0016] S23. If it is found that the abnormal detection feature data causes the food safety risk detection efficiency to exceed the preset threshold, the data is corrected using the set correction strategy;
[0017] S24, determining the objective function and constraint conditions, and establishing an optimization model;
[0018] S25. Apply the analysis algorithm to the optimization model to find the best solution that satisfies the constraint conditions, and use it as a basis for determining whether the abnormal detection feature data causes the food safety risk detection efficiency to exceed a preset threshold;
[0019] S26. Apply the results of the optimization model to the actual food safety risk detection process and generate food safety risk detection indicators.
[0020] Furthermore, collecting various data in the food supply chain and preprocessing them to obtain corresponding detection feature data includes the following steps:
[0021] S11. Obtain duplicate data corresponding to various types of data in the food supply chain, and perform denoising, filtering and smoothing on the duplicate data;
[0022] S12. Connect the unprocessed data rows in various data in the food supply chain to generate a new data table, associate different data tables through external key values, generate a complete data table, and obtain an accurate data set;
[0023] S13. Extract features from the accurate data set and obtain corresponding detection feature data.
[0024] Furthermore, the analysis algorithm is applied to the optimization model to find the best solution that meets the constraints, and as a basis for judging whether the abnormal detection feature data causes the food safety risk detection efficiency to exceed the preset threshold, the following steps are included:
[0025] S251, whitening the anomaly detection feature data to obtain whitened anomaly detection feature data that meets preset conditions;
[0026] S252, initializing the parameters of the analysis algorithm and setting the initial anomaly detection feature data correction strategy;
[0027] S253. Calculate the food safety risk detection efficiency corresponding to each abnormal detection feature data correction strategy through the established objective function, and update the status;
[0028] S254, optimizing, testing and adjusting each abnormal detection feature data correction strategy according to preset conditions, and updating the status;
[0029] S255. If the preset number of iterations is reached or the food safety risk detection efficiency reaches the preset threshold, execute step S256; otherwise, return to step S253 to continue optimizing the abnormal detection feature data correction strategy;
[0030] S256, determining a globally optimal anomaly detection feature data correction strategy as a corrected anomaly detection feature data correction strategy;
[0031] S257. Apply the corrected anomaly detection feature data correction strategy to re-test the food samples for safety risks, and compare the food safety risk detection results before and after the correction to analyze the effectiveness of the optimal anomaly detection feature data correction strategy.
[0032] Furthermore, based on the obtained food safety risk detection indicators, constructing a food safety risk prediction model using a machine learning algorithm includes the following steps:
[0033] S31, input the original data set of food safety risk detection indicators, and initialize several mapping tasks for building an isolation tree;
[0034] S32, using the Hadoop distributed framework, distributes several mapping tasks to each computing node in the cluster;
[0035] S33, perform random sampling through sampling techniques, and construct a sample subspace for each isolated tree;
[0036] S34, Hadoop creates and runs a processing job for the original data set of food safety risk detection indicators, sends it to the job tracker, and each computing node will execute the mapping task in parallel;
[0037] S35. After all mapping tasks for building isolated trees are completed, each tree is persisted in an output file, and an isolated forest is obtained as a food safety risk prediction model.
[0038] Further, optimizing the constructed food safety risk prediction model through an optimization algorithm, and conducting safety testing on food samples through the optimized food safety risk prediction model includes the following steps:
[0039] S41. Testing the constructed food safety risk prediction model and collecting the test results of the food safety risk prediction model;
[0040] S42. Define optimization objectives and constraints based on test results and food safety requirements;
[0041] S43, using an optimization algorithm to find an optimal solution in the parameter space of the food safety risk prediction model, and generating an optimized food safety risk prediction model;
[0042] S44. Conduct simulation tests on the optimized food safety risk prediction model, collect and analyze the performance data of the food safety risk prediction model when processing various types of food samples, and verify whether the optimization results meet the preset food safety testing standards and performance requirements;
[0043] S45. If the optimized food safety risk prediction model does not meet the preset safety testing standards and performance requirements, return to step S43, adjust the food safety risk prediction model parameters, and re-optimize. If the optimized food safety risk prediction model meets all preset conditions and performance requirements, it is used as the final food safety risk prediction model;
[0044] S46. Use the final food safety risk prediction model to conduct safety testing on actual food samples.
[0045] Further, using an optimization algorithm to find the optimal solution in the parameter space of the food safety risk prediction model, generating an optimized food safety risk prediction model includes the following steps:
[0046] S431, initializing the optimization algorithm and setting the initial food safety risk prediction model parameters;
[0047] S432, repeating steps S433 to S436 according to the set initial food safety risk prediction model parameters;
[0048] S433, randomly perturbing the initial food safety risk prediction model parameters to generate new food safety risk prediction model parameters;
[0049] S434, calculating the difference between the fitness value of the new food safety risk prediction model parameter and the fitness value of the initial food safety risk prediction model parameter;
[0050] S435. If the fitness value of the new food safety risk prediction model parameter is greater than the fitness value of the initial food safety risk prediction model parameter, the new food safety risk prediction model parameter is accepted as the new initial food safety risk prediction model parameter; otherwise, the acceptance probability of the new food safety risk prediction model parameter is calculated according to the acceptance criteria;
[0051] S436. If the acceptance probability is greater than the random number, the new food safety risk prediction model parameters are accepted as new initial food safety risk prediction model parameters; otherwise, the initial food safety risk prediction model parameters are retained;
[0052] S437. If the set termination condition is met, the initial food safety risk prediction model parameters are output as the optimal food safety risk prediction model parameters; otherwise, the food safety risk prediction model parameters are attenuated by the attenuation function and then the process returns to step S432;
[0053] S438. Repeat steps S433 to S437 until the optimal food safety risk prediction model parameters are found, and an optimized food safety risk prediction model is generated.
[0054] Furthermore, the calculation formula of the fitness value is:
[0055]
[0056] Among them, S(T m ) represents the fitness value of the food safety risk prediction model parameter set;
[0057] T m Represents the parameter set of food safety risk prediction model;
[0058] H represents weight;
[0059] H 1 and H 2 Represent the weights corresponding to accuracy and difference respectively;
[0060] K m Indicates T m The precision value of
[0061] Q represents the performance test index;
[0062] Both m and n represent indexes;
[0063] Q nm Indicates T m Performance test indicators compared with other food safety risk prediction model parameter sets;
[0064] m stands for T m The index of
[0065] n represents the index of other food safety risk prediction model parameter sets.
[0066] Furthermore, the formula for the attenuation function is:
[0067]
[0068] Among them, p h It is represented as the parameter of the food safety risk prediction model at the ath iteration;
[0069] P 0 It is represented as the initial food safety risk prediction model parameter;
[0070] a represents the number of iterations.
[0071] Furthermore, based on the safety test results, it is determined whether the food meets the food safety standards. If it does, it is marked as safe and allowed to enter the market. If it does not, the food sample is isolated, the traceability procedure is initiated, and corresponding measures are taken, including the following steps:
[0072] S51. Determine the key safety parameters of the food samples to be tested and set the initial food safety standard range;
[0073] S52, preset an initial value of the detection time, and preset the number of detections as the termination condition of the detection process;
[0074] S53, through internal circulation, continuously conduct safety tests on food samples, and adjust and optimize the testing process and parameters based on the test results;
[0075] S54. Use statistical methods to test the safety of food samples after each test;
[0076] S55. Calculate the safety score based on the safety and food safety standards after each test;
[0077] S56, comparing the safety score calculated each time with the safety score calculated last time, and selecting the result that better meets the food safety standard as the current best result;
[0078] S57, increasing the initial value of the detection time, and if the preset maximum number of detection times has been reached, terminating the detection process;
[0079] S58. Analyze the key safety parameters of food samples after testing and compare them with food safety standards to determine whether the food samples meet all set food safety standards. If they do, they will be marked as safe and allowed to enter the market. If they do not, the food samples will be isolated, the traceability procedure will be initiated, and corresponding measures will be taken.
[0080] According to another aspect of the present invention, there is also provided a food safety traceability detection system based on machine learning, the food safety traceability detection system based on machine learning comprising:
[0081] The data collection and processing module is used to collect various data in the food supply chain and perform preprocessing to obtain corresponding detection feature data;
[0082] A data analysis module is used to analyze the obtained detection feature data through an analysis algorithm to obtain food safety risk detection indicators;
[0083] A prediction model building module is used to build a food safety risk prediction model using a machine learning algorithm based on the obtained food safety risk detection indicators;
[0084] The model optimization and detection module is used to optimize the constructed food safety risk prediction model through the optimization algorithm, and to perform safety detection on food samples through the optimized food safety risk prediction model;
[0085] The result judgment and management measures module is used to judge whether the food safety standards are met based on the safety test results. If so, it is marked as safe and allowed to enter the market. If not, the food samples are isolated, the traceability procedure is initiated, and corresponding measures are taken;
[0086] Among them, the data collection and processing module is connected with the prediction model construction module through the data analysis module, and the prediction model construction module is connected with the model optimization and detection module and the result judgment and management measures module.
[0087] The beneficial effects of the present invention are:
[0088] 1. The present invention can accurately identify key factors affecting food safety by analyzing detection feature data, and optimize the model by setting preset thresholds and using analysis algorithms, so as to improve the detection efficiency while ensuring the detection quality. By continuously testing and optimizing the food safety risk prediction model, the accuracy of the model in practical applications can be improved, ensuring that the model can more reliably predict the safety risks of food samples. By using the final food safety risk prediction model to perform safety detection on actual food samples, and by continuously testing and comparing key safety parameters, it can be accurately determined whether the food samples meet the food safety standards, thereby effectively preventing unsafe food from entering the market and protecting the health of consumers.
[0089] 2. The present invention analyzes the obtained detection feature data through an analysis algorithm, thereby processing abnormal detection feature data, including the application of whitening processing and correction strategies, effectively reducing the negative impact of abnormal data on food safety detection results, ensuring the objectivity and accuracy of the detection results, and optimizing the model by setting preset thresholds and using analysis algorithms, so that the detection efficiency can be improved while ensuring the detection quality, and the accuracy, efficiency and dynamic adaptability of food safety risk detection can be improved by applying the results of the model to actual food safety risk detection.
[0090] 3. The present invention optimizes the constructed food safety risk prediction model through an optimization algorithm, so that through continuous testing and optimization of the food safety risk prediction model, the accuracy of the model in practical applications can be improved, ensuring that the model can more reliably predict the safety risks of food samples, and defining optimization objectives and constraints, which helps to clarify the direction and objectives of model optimization, thereby making the model more suitable for actual food safety monitoring needs. At the same time, the final food safety risk prediction model is used to conduct safety testing on actual food samples, thereby improving the accuracy and adaptability of the model.
[0091] 4. The present invention determines whether food safety standards are met through safety test results, so that by continuously testing and comparing key safety parameters, it can accurately determine whether food samples meet food safety standards, thereby helping to prevent unsafe food from entering the market and protecting the health of consumers. If it is found that a food sample does not meet safety standards, the traceability procedure will be immediately initiated and corresponding measures will be taken to isolate the food sample, thereby timely controlling food safety risks and preventing the occurrence of food safety incidents. BRIEF DESCRIPTION OF THE DRAWINGS
[0092] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0093] Figure 1 is a flow chart of a food safety traceability detection method based on machine learning according to an embodiment of the present invention;
[0094] Figure 2 It is a principle block diagram of a food safety traceability detection system based on machine learning according to an embodiment of the present invention.
[0095] In the figure:
[0096] 1. Data collection and processing module; 2. Data analysis module; 3. Prediction model building module; 4. Model optimization and detection module; 5. Result judgment and management measures module. DETAILED DESCRIPTION
[0097] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments.
[0098] In the description of the present invention, unless otherwise specified, the meaning of "plurality" is two or more. In addition, the terms "first", "second", "third", etc. are only used for descriptive purposes and cannot be understood as indicating or implying relative importance.
[0099] According to an embodiment of the present invention, a food safety traceability detection method and system based on machine learning are provided.
[0100] The present invention is further described with reference to the accompanying drawings and specific embodiments. Figure 1 As shown, according to the food safety traceability detection method based on machine learning according to an embodiment of the present invention, the food safety traceability detection method based on machine learning includes the following steps:
[0101] S1. Collect various data in the food supply chain and pre-process them to obtain corresponding detection feature data;
[0102] Specifically, the various types of data include food raw material data (including the origin, type, quality grade, production date, etc. of the raw materials), production process data (including production technology, production environment, such as temperature, humidity, etc., the status of production equipment, the operations of production personnel, etc.), storage and transportation data (including storage conditions, such as temperature, humidity, etc., transportation method, environmental conditions during transportation, product packaging conditions, etc.), sales and consumption data (including sales channels, sales date, consumer feedback, etc.), etc.
[0103] Specifically, the corresponding detection characteristic data include physical property data (such as food color, shape, size, weight, etc.), chemical property data (such as pH value, protein content, sugar content, harmful substances such as pesticide residues, additives content, etc.), biological property data (such as bacteria content, virus content, etc.), environmental property data (such as temperature and humidity of storage and transportation environment), process characteristic data (such as duration and frequency of each link of production, storage, transportation, sales, etc.), etc.
[0104] S2. Analyze the obtained detection feature data through an analysis algorithm to obtain a food safety risk detection index;
[0105] Specifically, food safety risk detection indicators are a series of indicators obtained by analyzing the detection feature data collected in the food supply chain. These indicators are used to detect food safety and determine whether there are potential risks in food.
[0106] Specifically, food safety risk detection indicators include pollutant content indicators (detecting the content of harmful substances in food, such as heavy metals, pesticide residues, excessive additives, etc., these indicators reflect the potential level of chemical hazards in food), microbial indicators (including the number and types of microorganisms such as bacteria, viruses, and molds. These indicators are used to detect possible biological hazards in food), nutritional component indicators (the content of protein, fat, sugar, vitamins, etc., these indicators help to detect the nutritional value of food and whether it meets the standards), physical property indicators (such as food texture, color, shape, etc., these indicators can sometimes reflect whether the food is properly handled and stored), environmental indicators (such as environmental conditions to which food is exposed during production, storage and transportation, such as temperature, humidity, etc.), safety compliance indicators (checking whether the food complies with relevant food safety standards and regulatory requirements), etc.
[0107] S3. Based on the obtained food safety risk detection indicators, a food safety risk prediction model is constructed using a machine learning algorithm;
[0108] S4. Optimizing the constructed food safety risk prediction model through an optimization algorithm, and conducting safety testing on food samples through the optimized food safety risk prediction model;
[0109] S5. Based on the safety test results, determine whether the food meets the food safety standards. If it does, it will be marked as safe and allowed to enter the market. If it does not, the food sample will be isolated, the traceability procedure will be initiated, and corresponding measures will be taken;
[0110] Specifically, the isolation of food samples includes physical isolation (removing substandard food samples from normal products and storing them in special areas or containers to avoid mixing with compliant foods), marking and recording (clearly marking isolated food samples and recording their detailed information, such as production batches, test results, isolation time, etc.), and safe processing (deciding whether to destroy or further process the food to meet safety standards based on the nature of the food and the risks it contains).
[0111] Specifically, the traceability procedure refers to tracking and investigating the source and production process of food samples that do not meet safety standards to determine the root cause of food safety problems, including:
[0112] Traceability of raw materials: Determine the origin of all raw materials used in food and check whether the raw materials meet the standards.
[0113] Production process review: Analyze the food manufacturing process, including the production line, process flow, operators, etc., to identify possible problems that may occur during the production process.
[0114] Check storage and transportation records: Understand the conditions of food during storage and transportation to determine if there is any improper handling or substandard conditions.
[0115] Supply Chain Management: Analyze supply chain management, including supplier selection, quality control, etc., to identify potential problems in the supply chain.
[0116] Analyzing the obtained detection feature data through an analysis algorithm to obtain food safety risk detection indicators includes the following steps:
[0117] S21. Obtaining and identifying abnormal detection feature data that affects food safety risk detection efficiency from the obtained detection feature data;
[0118] S22. Determine the measurement method for food safety risk detection efficiency, set a preset threshold as the best accepted detection efficiency, and set a correction strategy;
[0119] S23. If it is found that the abnormal detection feature data causes the food safety risk detection efficiency to exceed the preset threshold, the data is corrected using the set correction strategy;
[0120] S24, determining the objective function and constraint conditions, and establishing an optimization model;
[0121] S25. Apply the analysis algorithm to the optimization model to find the best solution that satisfies the constraint conditions, and use it as a basis for determining whether the abnormal detection feature data causes the food safety risk detection efficiency to exceed a preset threshold;
[0122] S26. Apply the results of the optimization model to the actual food safety risk detection process and generate food safety risk detection indicators.
[0123] It should be explained that, taking milk testing as an example, the chemical composition data in milk samples are obtained through high performance liquid chromatography (HPLC) technology. By comparing with historical data, data points that are significantly different from the normal range are automatically identified, which may be caused by equipment errors or sample contamination. The measurement of detection efficiency is set as accuracy and sensitivity. The preset threshold may be set to an accuracy of not less than 95% and a sensitivity of not less than 90%. For equipment or methods that do not meet the standards, correction strategies such as calibration or replacement of reagents are adopted. If statistical analysis finds that the accuracy and sensitivity of a batch of data are lower than the threshold, the detection equipment can be recalibrated or the reagents can be replaced. A linear or nonlinear optimization model is established. The objective function is to maximize the accuracy and sensitivity of the detection. The constraints include resource constraints, time and cost. Genetic algorithms or simulated annealing algorithms are used to find the optimal combination of accuracy and sensitivity under the set constraints. The results of the optimization model are implemented in the actual detection process, such as adjusting the detection parameters, optimizing the sample processing process, etc., and finally a detailed food safety risk detection indicator report is generated.
[0124] Preferably, collecting various data in the food supply chain and preprocessing them to obtain corresponding detection feature data includes the following steps:
[0125] S11. Obtain duplicate data corresponding to various types of data in the food supply chain, and perform denoising, filtering and smoothing on the duplicate data;
[0126] S12. Connect the unprocessed data rows in various data in the food supply chain to generate a new data table, associate different data tables through external key values, generate a complete data table, and obtain an accurate data set;
[0127] S13. Extract features from the accurate data set and obtain corresponding detection feature data.
[0128] It should be explained that, taking milk testing as an example, in the milk supply chain, the data from dairy farmers to processing plants may include temperature records, transportation time, and preliminary chemical test results of milk. First, remove duplicate data records, such as duplicate temperature logs. Next, filter the data, such as using a low-pass filter to remove high-frequency noise caused by equipment failure. Finally, smooth the data, such as using a moving average or exponential smoothing method, to balance short-term fluctuations in temperature and time, thereby providing a more stable data input and merging the data sets of the production, transportation, and processing stages of milk. For example, the external key value of the cow health record is connected with the daily data table provided by the dairy farmer, and then the transportation data (such as temperature, transportation time) is linked to generate a complete data table containing all relevant information. This process may involve database technology, such as SQL JOIN operations, to ensure the consistency and integrity of the data, and extract the most influential features for milk quality testing from the integrated data set. For example, extract features such as the average, maximum, and volatility of temperature from time series data; extract the concentration of specific chemicals from chemical test results. These feature data will be used for further analysis and modeling to detect whether the milk meets food safety standards.
[0129] Preferably, applying the analysis algorithm to the optimization model to find the best solution that satisfies the constraints and serving as a basis for determining whether the abnormal detection feature data causes the food safety risk detection efficiency to exceed a preset threshold comprises the following steps:
[0130] S251, whitening the anomaly detection feature data to obtain whitened anomaly detection feature data that meets preset conditions;
[0131] Specifically, whitening is a signal processing technique used to eliminate redundant information in data and reduce the correlation between features. In the present invention, the purpose of whitening is to prepare the anomaly detection feature data so that it meets the input requirements of the analysis algorithm.
[0132] S252, initializing the parameters of the analysis algorithm (i.e., initializing the fish school algorithm parameters), and setting the initial abnormal detection feature data correction strategy (i.e., artificial fish);
[0133] S253, calculating the food safety risk detection efficiency (i.e., negative entropy) corresponding to each abnormal detection feature data correction strategy (i.e., each artificial fish) through the established objective function, and updating the state;
[0134] Specifically, the objective function refers to a mathematical expression, which is used to measure the impact of each anomaly detection feature data correction strategy (i.e., each artificial fish) on the efficiency of food safety risk detection.
[0135] S254, performing optimization (i.e., foraging behavior), detection (i.e., clustering behavior) and adjustment (rear-end behavior) on each abnormal detection feature data correction strategy according to preset conditions, and updating the status;
[0136] S255. If the preset number of iterations is reached or the food safety risk detection efficiency reaches the preset threshold, execute step S256; otherwise, return to step S253 to continue optimizing the abnormal detection feature data correction strategy;
[0137] S256, determining a globally optimal anomaly detection feature data correction strategy as a corrected anomaly detection feature data correction strategy;
[0138] S257. Apply the corrected anomaly detection feature data correction strategy to re-test the food samples for safety risks, and compare the food safety risk detection results before and after the correction to analyze the effectiveness of the optimal anomaly detection feature data correction strategy.
[0139] It needs to be explained that, taking the detection of milk as an example, the initial data obtained by chromatographic analysis may contain multiple highly correlated chemical indicators. Through whitening, these data can be transformed so that the correlation between each feature is reduced and the data becomes more independent. This step is to convert the covariance matrix of the original data into a unit matrix through linear transformation, so as to achieve the effect of reducing data redundancy and enhancing model stability. The artificial fish school algorithm is used for parameter optimization, and the initialization includes the position of each artificial fish (representing different detection strategy parameters), visual range, step length, etc. This intelligent optimization algorithm simulates the behavior of the fish school, and finds the optimal solution through group cooperation. The set objective function may be to maximize the accuracy and sensitivity of the detection. Each artificial fish calculates the efficiency of food safety risk detection according to its position (i.e., the current detection strategy). If a better strategy is found, its own state is updated to improve the overall detection performance. In the artificial fish school algorithm, each artificial fish will adjust its position according to the current environment (i.e., the state and position of other artificial fish), simulate foraging, clustering and tail-chasing behavior, find a better solution, and repeat steps S253 and S254 until the preset number of iterations is reached or the detection efficiency meets the preset threshold. Finally, the globally optimal correction strategy is determined to ensure the optimal performance of the detection method. The determined optimal correction strategy is applied to the actual milk safety risk detection, the antibiotic residue test is re-conducted, and the data is compared with the data before correction to verify the effectiveness of the strategy.
[0140] Specifically, the analysis algorithm is the fish school algorithm, which is an optimization algorithm based on swarm intelligence. It is inspired by the foraging, clustering and following behaviors of fish in nature. The algorithm imitates the collective behavior of fish in finding food and avoiding danger.
[0141] Preferably, based on the obtained food safety risk detection indicators, constructing a food safety risk prediction model using a machine learning algorithm comprises the following steps:
[0142] S31, input the original data set of food safety risk detection indicators, and initialize several mapping tasks for building an isolation tree;
[0143] Specifically, we first need to prepare the original data set for inputting food safety risk detection indicators. The data set contains data of various indicators that the system needs to detect. At the same time, before building the isolation tree, we need to initialize several mapping tasks to prepare for subsequent distributed processing.
[0144] S32, using the Hadoop distributed framework, distributes several mapping tasks to each computing node in the cluster;
[0145] Specifically, Hadoop is an open source distributed computing framework for processing the storage and analysis of large-scale data sets. In the Hadoop distributed framework, the distribution of mapping tasks to computing nodes in the cluster is implemented through Hadoop's MapReduce programming model, including:
[0146] Map Reduce programming model: Map Reduce programming model is a distributed computing model for processing and generating large-scale data sets. Hadoop uses Map Reduce programming model to implement distributed computing. The model includes Map phase (mapping phase) and Reduce phase (reduction phase).
[0147] Map phase: In this phase, the raw data of food safety risk detection indicators is split into several small blocks, each of which is processed by a Mapper. The mapping task is usually performed by a user-defined Map function, which maps the input data into key-value pairs.
[0148] Distributed distribution of tasks: The Hadoop framework is responsible for distributing mapping tasks to the various computing nodes in the cluster, and is coordinated and managed by Job Tracker (Job Tracker, which is a master node in the Hadoop cluster and is responsible for tracking and scheduling the execution process of the entire job) and Task Tracker (Task Tracker, which is a working node in the Hadoop cluster and runs on each computing node and is responsible for executing tasks assigned by the Job Tracker, namely Map tasks or Reduce tasks). The Job Tracker is responsible for tracking and scheduling jobs, while the Task Tracker executes tasks on each computing node.
[0149] Data locality: The Hadoop framework distributes mapping tasks to the computing nodes that store the corresponding data blocks to reduce the overhead of data transmission. This is called data locality and is an important consideration for Hadoop performance optimization.
[0150] Execute map tasks: The Task Tracker on each compute node executes the map tasks assigned to it. In this phase, the Map function processes local data and generates intermediate key-value pairs.
[0151] S33, perform random sampling through sampling techniques, and construct a sample subspace for each isolated tree;
[0152] Specifically, the sampling technique is a subsampling algorithm, which is a commonly used technique in machine learning and statistics. Its main purpose is to extract subsets from the original data set for model training, verification or testing. By selecting subsets of data at different stages, the performance of the model can be improved, the computational burden can be reduced, and the generalization ability of the model can be increased.
[0153] S34, Hadoop creates and runs a processing job for the original data set of food safety risk detection indicators, sends it to the job tracker, and each computing node will execute the mapping task in parallel;
[0154] S35. After all mapping tasks for building isolated trees are completed, each tree is persisted in an output file, and an isolated forest is obtained as a food safety risk prediction model.
[0155] Specifically, persisting each tree to an output file means saving each constructed isolated tree to a file in a computer file system, where a file is a container for storing data that can be re-read and used at a later time.
[0156] Specifically, by persisting the isolated tree to a file, the following goals can be achieved:
[0157] Model saving: Save the trained model for future prediction or detection on new data.
[0158] Model sharing: Allows other people or systems to use the same model without retraining.
[0159] Model deployment: Embed the model into actual applications for real-time prediction or risk detection.
[0160] Preferably, optimizing the constructed food safety risk prediction model by an optimization algorithm, and performing safety testing on food samples by using the optimized food safety risk prediction model comprises the following steps:
[0161] S41. Testing the constructed food safety risk prediction model and collecting the test results of the food safety risk prediction model;
[0162] S42. Define optimization objectives and constraints based on test results and food safety requirements;
[0163] Specifically, the optimization goal refers to the goal or objective function of the food safety system, a quantitative indicator that is maximized or minimized during the optimization process. This indicator is a performance metric that needs to be optimized, such as reducing costs, improving efficiency, and enhancing food safety levels.
[0164] Specifically, constraints refer to restrictions or conditions that need to be met during the optimization process. These conditions can be restrictions on the system, resources, or food safety standards. For example, existing constraints include cost constraints, resource availability, regulatory requirements, food safety standards, etc.
[0165] S43, using an optimization algorithm to find an optimal solution in the parameter space of the food safety risk prediction model, and generating an optimized food safety risk prediction model;
[0166] S44. Conduct simulation tests on the optimized food safety risk prediction model, collect and analyze the performance data of the food safety risk prediction model when processing various types of food samples, and verify whether the optimization results meet the preset food safety testing standards and performance requirements;
[0167] Specifically, various types of food samples refer to different kinds of food samples used in simulation tests to test the performance of food safety risk prediction models in processing diverse food data.
[0168] Specifically, various types of food samples include:
[0169] Different food categories: The model needs to handle different types of food, such as meat, vegetables, fruits, grains, etc. Each food has different risk factors and characteristics.
[0170] Different processing states: Food may be in different processing states, such as raw, cooked, processed, etc. These states affect the safety of food.
[0171] Different sources and supply chains: Food may come from different suppliers or origins, involving different supply chains. The model needs to maintain accuracy when dealing with food from different sources.
[0172] Different storage conditions: Food may be tested under different storage conditions, including factors such as temperature, humidity, etc. This can simulate actual production and storage environments.
[0173] Different batches: Food may come from different batches or time points, taking into account factors such as seasonal changes, supply chain fluctuations, etc.
[0174] S45. If the optimized food safety risk prediction model does not meet the preset safety testing standards and performance requirements, return to step S43, adjust the food safety risk prediction model parameters, and re-optimize. If the optimized food safety risk prediction model meets all preset conditions and performance requirements, it is used as the final food safety risk prediction model;
[0175] Specifically, performance requirements refer to the expected standards or indicators for the performance of food safety risk prediction models in practical applications.
[0176] Specifically, food safety risk prediction model parameters refer to adjustable parameters that affect model behavior and performance (model hyperparameters, feature selection parameters, algorithm parameters, etc.).
[0177] S46. Use the final food safety risk prediction model to conduct safety testing on actual food samples.
[0178] It should be explained that, taking milk testing as an example, a machine learning-based model is constructed to predict the risk of antibiotic residues in milk. The historical data set is used to train and test the model initially, and the performance data of the model when processing different types of milk samples, such as accuracy and recall, are collected. The optimization goal may include improving the accuracy of the model to at least 98%, while ensuring that the recall rate is not less than 95%. Constraints include limiting the training and prediction time of the model to adapt to actual operational needs, and ensuring that the model can run stably under different environmental conditions. Genetic algorithms are used to adjust the model's hyperparameters, such as learning rate, number of layers, and number of neurons in each layer, to find the optimal parameter combination under the defined objective function and constraints, and the optimized model is simulated and tested using a new milk sample data set, which covers milk from different regions, different seasons, and different processing processes. The performance of the model under various conditions is analyzed, and it is verified whether it meets the previously set food safety testing standards. If the results of the simulation test do not meet the preset safety testing standards, the model parameters or optimization strategies will be adjusted and re-optimized. This process may be iterated multiple times until the model performance meets all preset conditions. The final verified food safety risk prediction model will be applied to actual milk testing, and safety testing of milk samples on the market will be carried out to detect their safety risks in real time.
[0179] Preferably, using an optimization algorithm to find the optimal solution in the parameter space of the food safety risk prediction model, and generating an optimized food safety risk prediction model comprises the following steps:
[0180] S431, initializing the optimization algorithm and setting the initial food safety risk prediction model parameters;
[0181] S432, repeating steps S433 to S436 according to the set initial food safety risk prediction model parameters;
[0182] S433, randomly perturbing the initial food safety risk prediction model parameters to generate new food safety risk prediction model parameters;
[0183] S434, calculating the difference between the fitness value of the new food safety risk prediction model parameter and the fitness value of the initial food safety risk prediction model parameter;
[0184] S435. If the fitness value of the new food safety risk prediction model parameter is greater than the fitness value of the initial food safety risk prediction model parameter, the new food safety risk prediction model parameter is accepted as the new initial food safety risk prediction model parameter; otherwise, the acceptance probability of the new food safety risk prediction model parameter is calculated according to the acceptance criteria;
[0185] Specifically, the acceptance criterion is the Metropolis rule, which is an acceptance-rejection criterion used in Monte Carlo simulation. The basic idea of this rule is: if the new state has lower energy (or higher probability) than the current state, then accept the new state; otherwise, accept the new state with a probability that is the negative exponent of the energy difference (or probability ratio) between the new state and the current state.
[0186] S436. If the acceptance probability is greater than the random number, the new food safety risk prediction model parameters are accepted as new initial food safety risk prediction model parameters; otherwise, the initial food safety risk prediction model parameters are retained;
[0187] S437. If the set termination condition is met, the initial food safety risk prediction model parameters are output as the optimal food safety risk prediction model parameters; otherwise, the food safety risk prediction model parameters are attenuated by the attenuation function and then the process returns to step S432;
[0188] S438. Repeat steps S433 to S437 until the optimal food safety risk prediction model parameters are found, and an optimized food safety risk prediction model is generated.
[0189] It should be explained that, taking milk detection as an example, simulated annealing algorithm is used as an optimization algorithm to initialize the parameters of the milk safety detection model, including but not limited to threshold setting, sensor sensitivity, etc. Simulated annealing is a heuristic search algorithm that finds the global optimal solution of the system by imitating the annealing process in the physical process. According to the initialized parameters, the subsequent optimization steps are repeated until the termination condition is reached or the optimal parameters are found. Small random changes are applied on the basis of the current model parameters to generate new model parameter combinations to explore the parameter space and detect the performance of the new and old parameter combinations. For example, the difference in accuracy and recall between the two is calculated through simulation tests. If the fitness of the new parameters is higher, it is directly accepted; if it is lower, an acceptance probability is calculated, which is proportional to the negative exponent of the fitness difference. If the preset number of iterations or performance standards are not reached, the parameters are adjusted using the attenuation function to continue the optimization process. The attenuation function helps to gradually reduce the range of parameter changes, so that the algorithm gradually focuses on the most promising area, and repeats steps S433 to S437 until the best food safety risk prediction model parameters are found. Apply these parameters to the milk safety risk prediction model to ensure that the model achieves the best performance in actual detection.
[0190] Specifically, the optimization algorithm used is a simulated annealing algorithm, which is a heuristic optimization algorithm that gradually optimizes the objective function value by simulating the cooling process in the solid annealing process. In the present invention, the simulated annealing algorithm is used to find the best food safety risk prediction model parameters, which come from the parameter set initially set. The fitness value of each design scheme is calculated based on the performance indicators and design constraints of each parameter combination. The scheme with high performance indicators and meeting the design constraints has a larger fitness value. The simulated annealing algorithm searches for the food safety risk prediction model parameters with the largest fitness value in the design parameter space to generate an optimized food safety risk prediction model.
[0191] Preferably, the calculation formula of the fitness value is:
[0192]
[0193] Among them, S(T m ) represents the fitness value of the food safety risk prediction model parameter set;
[0194] T m Represents the parameter set of food safety risk prediction model;
[0195] H represents weight;
[0196] H 1 and H 2 Represent the weights corresponding to accuracy and difference respectively;
[0197] K mIndicates T m The precision value of
[0198] Q represents the performance test index;
[0199] Both m and n represent indexes;
[0200] Q nm Indicates T m Performance test indicators compared with other food safety risk prediction model parameter sets;
[0201] m stands for T m The index of
[0202] n represents the index of other food safety risk prediction model parameter sets.
[0203] Preferably, the attenuation formula of the attenuation function is:
[0204]
[0205] Among them, p h It is represented as the parameter of the food safety risk prediction model at the ath iteration;
[0206] P 0 It is represented as the initial food safety risk prediction model parameter;
[0207] a represents the number of iterations.
[0208] Preferably, judging whether the food safety standards are met based on the safety test results, if so, marking it as safe and allowing it to enter the market for circulation, if not, isolating the food sample, starting the traceability procedure, and taking corresponding measures, including the following steps:
[0209] S51. Determine the key safety parameters of the food samples to be tested and set the initial food safety standard range;
[0210] Specifically, key safety parameters include:
[0211] Microbial contamination indicators: These indicators involve microbial contamination in food, such as bacteria (such as Salmonella, E. coli), molds, yeasts, etc. Key safety parameters include the number, type and pathogenicity of microorganisms.
[0212] Chemical residues: These parameters involve chemical residues in food, such as pesticide residues, heavy metal content, use of additives, etc. Key safety parameters include the type, concentration and safety standard of chemical substances.
[0213] Physical properties: These parameters relate to the physical properties of the food, such as temperature, humidity, pH, etc. Critical safety parameters include the range and variation of physical properties.
[0214] Production and processing conditions: These parameters involve the production and processing conditions of food, such as production technology, sanitation measures, storage temperature, etc. Key safety parameters include compliance and control of production and processing conditions, etc.
[0215] Food origin and supply chain: These parameters involve the origin and supply chain of food, such as supplier reliability, transportation methods, quality control, etc. Key safety parameters include traceability of the supply chain and quality assurance.
[0216] S52, preset an initial value of the detection duration (usually 0 or 1), and preset the number of detections as the termination condition of the detection process;
[0217] Specifically, the preset detection duration initial value refers to the preset initial value of the time counter.
[0218] Specifically, the termination conditions include that the time recorded by the time counter reaches a preset maximum value and the number of iterations of the optimization algorithm reaches a preset maximum number.
[0219] S53, through internal circulation, continuously conduct safety tests on food samples, and adjust and optimize the testing process and parameters based on the test results;
[0220] Specifically, the inner loop: continuously conduct safety tests on food samples according to a certain strategy, calculate the objective function, and determine whether the parameters need to be updated. This cyclic process is called the inner loop.
[0221] S54. Use statistical methods to test the safety of food samples after each test;
[0222] Specifically, the statistical method is k-fold cross validation, that is, k-fold cross validation is a machine learning model detection method, which refers to dividing the collected detection process and parameter data into k subsets, one of which is used as a validation set, and the remaining k-1 subsets are used as training sets.
[0223] S55. Calculate the safety score based on the safety and food safety standards after each test;
[0224] S56, comparing the safety score calculated each time with the safety score calculated last time, and selecting the result that better meets the food safety standard as the current best result;
[0225] S57, increasing the initial value of the detection time, and if the preset maximum number of detection times has been reached, terminating the detection process;
[0226] S58. Analyze the key safety parameters of food samples after testing and compare them with food safety standards to determine whether the food samples meet all set food safety standards. If they do, they will be marked as safe and allowed to enter the market. If they do not, the food samples will be isolated, the traceability procedure will be initiated, and corresponding measures will be taken.
[0227] It should be explained that, taking milk testing as an example, for milk samples, key safety parameters include microbial contamination indicators (such as E. coli counts), chemical residues (such as antibiotic and hormone levels), and physical properties (such as pH and temperature). According to national food safety standards, safety thresholds for each parameter are set, such as E. coli not exceeding 100 units per milliliter. The initial detection time of milk safety detection is set to 0, and the preset number of detections is 5 times to ensure the reliability of data and the comprehensiveness of detection. During the safety detection process, parameters are adjusted according to the previous test results, such as increasing the detection sensitivity of specific chemicals to ensure that undetected trace residues are identified. The k-fold cross-validation method is used to detect the safety of milk samples. The stability and reliability of the detection model are tested through multiple independent tests. According to the test results, the safety score of each sample is calculated and compared with the food safety standards, such as a comprehensive score based on the indicators of chemical residues and microbial contamination. The best safety score in the continuous test results is compared with the previous score, and the result that best meets the food safety standards is selected as the final test result. If the number of tests reaches the preset maximum value or the test time exceeds the preset time, the test process is terminated and the final test results are evaluated. If all key safety parameters meet the food safety standards, the milk can be marked as safe and allowed to circulate. If there is a safety problem, the milk sample is isolated, the traceability procedure is initiated, the source of the problem is found, and corresponding measures are taken, such as recycling or destroying the problem milk.
[0228] According to another embodiment of the present invention, Figure 2 As shown, a food safety traceability detection system based on machine learning is also provided, and the food safety traceability detection system based on machine learning includes:
[0229] Data collection and processing module 1, used to collect various data in the food supply chain and perform preprocessing to obtain corresponding detection feature data;
[0230] Data analysis module 2, used to analyze the obtained detection feature data through an analysis algorithm to obtain food safety risk detection indicators;
[0231] A prediction model building module 3 is used to build a food safety risk prediction model using a machine learning algorithm based on the obtained food safety risk detection indicators;
[0232] The model optimization and detection module 4 is used to optimize the constructed food safety risk prediction model through an optimization algorithm, and to perform safety detection on food samples through the optimized food safety risk prediction model;
[0233] Result judgment and management measures module 5 is used to judge whether the food safety standards are met according to the safety test results. If so, the food is marked as safe and allowed to enter the market for circulation. If not, the food sample is isolated, the traceability procedure is initiated, and corresponding measures are taken;
[0234] Among them, the data collection and processing module 1 is connected with the prediction model construction module 3 through the data analysis module 2, and the prediction model construction module 3 is connected with the result judgment and management measures module 5 through the model optimization and detection module 4.
[0235] In summary, with the aid of the above technical solution of the present invention, the present invention analyzes the obtained detection feature data through an analysis algorithm, thereby processing abnormal detection feature data, including the application of whitening processing and correction strategies, effectively reducing the negative impact of abnormal data on food safety detection results, ensuring the objectivity and accuracy of the detection results, and optimizing the model by setting a preset threshold and using an analysis algorithm, so that while ensuring the detection quality, the detection efficiency can also be improved, and by applying the results of the model to actual food safety risk detection, the accuracy, efficiency and dynamic adaptability of food safety risk detection are improved. The present invention optimizes the constructed food safety risk prediction model through an optimization algorithm, so that through continuous testing and optimization of the food safety risk prediction model, the accuracy of the model in practical applications can be improved, ensuring that the model can more reliably predict the safety risks of food samples, and defining optimization goals and constraints, thereby helping to clarify the direction and goals of model optimization, so that the model is more suitable for actual food safety monitoring needs, and at the same time, the final food safety risk prediction model is used to perform safety detection on actual food samples, thereby improving the accuracy and adaptability of the model. The present invention determines whether food safety standards are met through safety test results, so that by continuously testing and comparing key safety parameters, it can accurately determine whether food samples meet food safety standards, thereby helping to prevent unsafe food from entering the market and protecting the health of consumers. If it is found that a food sample does not meet safety standards, the traceability procedure will be immediately initiated and corresponding measures will be taken to isolate the food sample, thereby timely controlling food safety risks and preventing the occurrence of food safety incidents.
[0236] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A food safety traceability detection method based on machine learning, characterized in that: The food safety traceability detection method based on machine learning includes the following steps: S1. Collect various data in the food supply chain and pre-process them to obtain corresponding detection feature data; S2. Analyze the obtained detection feature data through an analysis algorithm to obtain a food safety risk detection index; S3. Based on the obtained food safety risk detection indicators, a food safety risk prediction model is constructed using a machine learning algorithm; S4. Optimizing the constructed food safety risk prediction model through an optimization algorithm, and conducting safety testing on food samples through the optimized food safety risk prediction model; S5. Based on the safety test results, determine whether the food meets the food safety standards. If it does, it will be marked as safe and allowed to enter the market. If it does not, the food sample will be isolated, the traceability procedure will be initiated, and corresponding measures will be taken; Analyzing the obtained detection feature data by an analysis algorithm to obtain food safety risk detection indicators includes the following steps: S21. Obtaining and identifying abnormal detection feature data that affects food safety risk detection efficiency from the obtained detection feature data; S22. Determine the measurement method for food safety risk detection efficiency, set a preset threshold as the best acceptable detection efficiency, and set a correction strategy; S23. If it is found that the abnormal detection feature data causes the food safety risk detection efficiency to exceed the preset threshold, the data is corrected using the set correction strategy; S24, determining the objective function and constraint conditions, and establishing an optimization model; S25. Apply the analysis algorithm to the optimization model to find the best solution that satisfies the constraint conditions, and use it as a basis for determining whether the abnormal detection feature data causes the food safety risk detection efficiency to exceed a preset threshold; S26. Apply the results of the optimization model to the actual food safety risk detection process and generate food safety risk detection indicators.
2. A food safety traceability detection method based on machine learning according to claim 1, characterized in that: The collecting of various data in the food supply chain and preprocessing to obtain corresponding detection feature data includes the following steps: S11. Obtain duplicate data corresponding to various types of data in the food supply chain, and perform denoising, filtering and smoothing on the duplicate data; S12. Connect the unprocessed data rows in various data in the food supply chain to generate a new data table, associate different data tables through external key values, generate a complete data table, and obtain an accurate data set; S13. Extract features from the accurate data set and obtain corresponding detection feature data.
3. A food safety traceability detection method based on machine learning according to claim 1, characterized in that: The method of applying the analysis algorithm to the optimization model to find the best solution that satisfies the constraint conditions and serving as a basis for determining whether the abnormal detection feature data causes the food safety risk detection efficiency to exceed a preset threshold value includes the following steps: S251, whitening the anomaly detection feature data to obtain whitened anomaly detection feature data that meets preset conditions; S252, initializing the parameters of the analysis algorithm and setting the initial anomaly detection feature data correction strategy; S253. Calculate the food safety risk detection efficiency corresponding to each abnormal detection feature data correction strategy through the established objective function, and update the status; S254, optimizing, testing and adjusting each abnormal detection feature data correction strategy according to preset conditions, and updating the status; S255. If the preset number of iterations is reached or the food safety risk detection efficiency reaches the preset threshold, execute step S256; otherwise, return to step S253 to continue optimizing the abnormal detection feature data correction strategy; S256, determining a globally optimal anomaly detection feature data correction strategy as a corrected anomaly detection feature data correction strategy; S257. Apply the corrected anomaly detection feature data correction strategy to re-test the food samples for safety risks, and compare the food safety risk detection results before and after the correction to analyze the effectiveness of the optimal anomaly detection feature data correction strategy.
4. The food safety traceability detection method based on machine learning according to claim 1, characterized in that: The method of constructing a food safety risk prediction model using a machine learning algorithm based on the obtained food safety risk detection index comprises the following steps: S31, input the original data set of food safety risk detection indicators, and initialize several mapping tasks for building an isolation tree; S32, using the Hadoop distributed framework, distributes several mapping tasks to each computing node in the cluster; S33, perform random sampling through sampling techniques, and construct a sample subspace for each isolated tree; S34, Hadoop creates and runs a processing job for the original data set of food safety risk detection indicators, sends it to the job tracker, and each computing node will execute the mapping task in parallel; S35. After all mapping tasks for building isolated trees are completed, each tree is persisted in an output file, and an isolated forest is obtained as a food safety risk prediction model.
5. The food safety traceability detection method based on machine learning according to claim 1, characterized in that: The method of optimizing the constructed food safety risk prediction model by using an optimization algorithm and performing safety testing on food samples by using the optimized food safety risk prediction model comprises the following steps: S41. Testing the constructed food safety risk prediction model and collecting the test results of the food safety risk prediction model; S42. Define optimization objectives and constraints based on test results and food safety requirements; S43, using an optimization algorithm to find an optimal solution in the parameter space of the food safety risk prediction model, and generating an optimized food safety risk prediction model; S44. Conduct simulation tests on the optimized food safety risk prediction model, collect and analyze the performance data of the food safety risk prediction model when processing various types of food samples, and verify whether the optimization results meet the preset food safety testing standards and performance requirements; S45. If the optimized food safety risk prediction model does not meet the preset safety testing standards and performance requirements, return to step S43, adjust the food safety risk prediction model parameters, and re-optimize. If the optimized food safety risk prediction model meets all preset conditions and performance requirements, it is used as the final food safety risk prediction model; S46. Use the final food safety risk prediction model to conduct safety testing on actual food samples.
6. A food safety traceability detection method based on machine learning according to claim 5, characterized in that: The method of using an optimization algorithm to find an optimal solution in the parameter space of the food safety risk prediction model to generate an optimized food safety risk prediction model comprises the following steps: S431, initializing the optimization algorithm and setting the initial food safety risk prediction model parameters; S432, repeating steps S433 to S436 according to the set initial food safety risk prediction model parameters; S433, randomly perturbing the initial food safety risk prediction model parameters to generate new food safety risk prediction model parameters; S434, calculating the difference between the fitness value of the new food safety risk prediction model parameter and the fitness value of the initial food safety risk prediction model parameter; S435. If the fitness value of the new food safety risk prediction model parameter is greater than the fitness value of the initial food safety risk prediction model parameter, the new food safety risk prediction model parameter is accepted as the new initial food safety risk prediction model parameter; otherwise, the acceptance probability of the new food safety risk prediction model parameter is calculated according to the acceptance criteria; S436. If the acceptance probability is greater than the random number, the new food safety risk prediction model parameters are accepted as new initial food safety risk prediction model parameters; otherwise, the initial food safety risk prediction model parameters are retained; S437. If the set termination condition is met, the initial food safety risk prediction model parameters are output as the optimal food safety risk prediction model parameters; otherwise, the food safety risk prediction model parameters are attenuated by the attenuation function and then the process returns to step S432; S438. Repeat steps S433 to S437 until the optimal food safety risk prediction model parameters are found, and an optimized food safety risk prediction model is generated.
7. A food safety traceability detection method based on machine learning according to claim 6, characterized in that: The calculation formula of the fitness value is: Among them, S(T m ) represents the fitness value of the food safety risk prediction model parameter set; T m Represents the parameter set of food safety risk prediction model; H represents weight; H1 and H2 represent the weights corresponding to accuracy and variability, respectively; K m Indicates T m The precision value of Q represents the performance test index; Both m and n represent indexes; Q nm Indicates T m Performance test indicators compared with other food safety risk prediction model parameter sets; m stands for T m The index of n represents the index of other food safety risk prediction model parameter sets.
8. The food safety traceability detection method based on machine learning according to claim 6 is characterized in that: The attenuation formula of the attenuation function is: Among them, p h It is represented as the parameter of the food safety risk prediction model at the ath iteration; P0 represents the initial food safety risk prediction model parameter; a represents the number of iterations.
9. The food safety traceability detection method based on machine learning according to claim 1, characterized in that: The method of judging whether the food safety standards are met based on the safety test results, if so, marking it as safe and allowing it to enter the market, if not, isolating the food sample, starting the traceability procedure, and taking corresponding measures, including the following steps: S51. Determine the key safety parameters of the food samples to be tested and set the initial food safety standard range; S52, preset an initial value of the detection time, and preset the number of detections as the termination condition of the detection process; S53, through internal circulation, continuously conduct safety tests on food samples, and adjust and optimize the testing process and parameters based on the test results; S54. Use statistical methods to test the safety of food samples after each test; S55. Calculate the safety score based on the safety and food safety standards after each test; S56, comparing the safety score calculated each time with the safety score calculated last time, and selecting the result that better meets the food safety standard as the current best result; S57, increasing the initial value of the detection time, and if the preset maximum number of detection times has been reached, terminating the detection process; S58. Analyze the key safety parameters of food samples after testing and compare them with food safety standards to determine whether the food samples meet all set food safety standards. If they do, they will be marked as safe and allowed to enter the market. If they do not, the food samples will be isolated, the traceability procedure will be initiated, and corresponding measures will be taken.
10. A food safety traceability detection system based on machine learning, used to implement the food safety traceability detection method based on machine learning described in any one of claims 1 to 9, characterized in that: The food safety traceability detection system based on machine learning includes: The data collection and processing module is used to collect various data in the food supply chain and perform preprocessing to obtain corresponding detection feature data; A data analysis module is used to analyze the obtained detection feature data through an analysis algorithm to obtain food safety risk detection indicators; A prediction model building module is used to build a food safety risk prediction model using a machine learning algorithm based on the obtained food safety risk detection indicators; The model optimization and detection module is used to optimize the constructed food safety risk prediction model through the optimization algorithm, and to perform safety detection on food samples through the optimized food safety risk prediction model; The result judgment and management measures module is used to judge whether the food safety standards are met based on the safety test results. If so, it is marked as safe and allowed to enter the market. If not, the food samples are isolated, the traceability procedure is initiated, and corresponding measures are taken; Among them, the data collection and processing module is connected with the prediction model construction module through the data analysis module, and the prediction model construction module is connected with the model optimization and detection module and the result judgment and management measures module.
Citation Information
Cited By
Tracing detection system and method based on food safety supervision
CN119887247A
Material digital supply chain test method
CN120235477A
Quick-frozen abalone safety management method and system based on traceability identification
CN122022852A