Food risk prediction visual analysis method and device based on meta-path selection

By constructing a heterogeneous network embedding model and combining visual interaction methods, the problem of the lack of interpretability of deep learning models in food risk prediction is solved, and the interpretability of food risk prediction and decision support capabilities are improved.

CN120387679APending Publication Date: 2025-07-29ZHEJIANG UNIV OF TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510562883.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-30
Publication Date
2025-07-29

AI Technical Summary

Technical Problem

Existing food risk prediction methods rely on deep learning models, but lack interpretability and are difficult to meet the food field experts' understanding and decision-making support needs for risk level prediction.

Method used

The visual analysis method of food risk prediction based on metapathic path selection is adopted. By constructing a heterogeneous network embedding model, combined with visual interaction means, users are allowed to adjust the metapath weight and observe the embedding results in real time to show the impact of attributes on risk levels.

Benefits of technology

Enhance the interpretability and decision support capabilities of the model, enable users to intuitively understand the impact of various attributes on risk levels, and improve the transparency and credibility of the prediction process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120387679A_ABST
    Figure CN120387679A_ABST
Patent Text Reader

Abstract

The invention discloses a food risk prediction visual analysis method and device based on meta-path selection, and the method comprises the steps: carrying out the cleaning and preprocessing of food detection data, and distributing a risk level label for each sample based on a detection value of a pollutant and a legal threshold value; food attribute features are preprocessed, a heterogeneous graph is constructed for different types of nodes and relationships thereof, a suitable meta-path is designed in combination with domain knowledge, and food table data preprocessed in the previous step are converted into a data format suitable for an HAN heterogeneous model; the method comprises the following steps: interactively adjusting the weight of a meta-path in a visualization system, calculating the embedding result of a food sample in real time, carrying out dimensionality reduction display on the embedding result of the food sample through an embedding result distribution view, providing a meta-path composition view, and designing an embedding comparison view; the combined influence of the display attributes on the food risk level is visually provided and serves as the basis of meta-path weight distribution; through model calculation, food risk grade prediction is generated based on the current meta-path composition, and a prediction result is displayed in a prediction probability form; meanwhile, attribute distribution in a prediction result self-defined interval is analyzed to serve as support for the prediction result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention proposes a food risk prediction visual analysis method and device based on meta-path selection, aiming to solve the problem of risk level prediction in the food field. This method combines a heterogeneous network embedding model with meta-paths to construct an embedded representation of food samples, and by assigning adjustable weights to the meta-paths, uses visual interaction means to help users understand the influence of meta-paths on the embedding results and their role in risk level prediction, thereby improving the interpretability of the model and the decision-making support ability. Background Art

[0002] Food safety is closely related to people's health and has long been a key concern of the country and the public. With the continuous strengthening of food inspection management, a large amount of food data has also provided rich resources for food safety research. These data usually contain high-dimensional attributes, such as food production areas, sales areas, pollutant types, food categories, etc. Since there is a strong correlation between various attributes, the influence degrees of these attributes on the food risk level are different. How to understand and evaluate the influence of different attributes on the food risk level has become a major issue faced by food field experts.

[0003] Traditional food data analysis methods mostly rely on statistical models, and experts draw conclusions through manual analysis. However, with the explosion of food data volume, this process has become extremely cumbersome and time-consuming, making it difficult to meet the actual needs. In recent years, deep learning technology has gradually been applied to food risk prediction, which can directly predict the risk level of food, avoiding the inefficiency of manual analysis. However, deep learning models are often regarded as "black box" models. Food field experts can only access the input data and prediction results, but cannot understand how the model obtains these results. Although the prediction results may have a certain degree of accuracy, the lack of sufficient interpretability makes it difficult for experts to make persuasive decisions based on the model output.

[0004] Therefore, how to enable experts to more intuitively observe food data through visualization technology and understand how various attributes affect the food risk level has become a key issue in current research. By introducing an interactive visualization method and combining the prediction results of a deep learning model, the interpretability of the model can be enhanced, helping users understand the prediction logic, and providing a more decision-making support basis for food safety monitoring based on this. Summary of the Invention

[0005] In order to overcome the above deficiencies of the prior art, the present invention proposes a food risk prediction visual analysis method and device based on meta-path selection.

[0006] The food risk prediction visual analysis method based on meta-path selection of the present invention includes the following steps:

[0007] Step 1: Clean and preprocess the food test data to ensure the scientificity and effectiveness of the data. Assign risk level labels to each sample based on the test values of pollutants and legal thresholds.

[0008] Step 2: Through the preprocessing of food attribute features, construct a heterogeneous graph for different types of nodes and their relationships, design suitable meta-paths in combination with domain knowledge, and convert the preprocessed food table data in the previous step into a data format suitable for the HAN heterogeneous model.

[0009] Step 3: Interactively adjust the meta-path weights in the visualization system and calculate the embedding results of food samples in real time. Design multiple visualization views, perform dimensionality reduction display on the embedding results of food samples through the embedding result distribution view, and at the same time provide the meta-path composition view and design the embedding comparison view to help users deeply understand the impact of meta-paths on the embedding calculation results.

[0010] Step 4: The visualization provides the joint impact of attributes on the food risk level as the basis for meta-path weight assignment. Through model calculation, generate food risk level predictions based on the current meta-path composition and display the prediction results in the form of prediction probabilities. At the same time, analyze the attribute distribution within the custom interval of the prediction results as support for the prediction results.

[0011] Furthermore, Step 1 specifically includes:

[0012] 1.1 Obtain the original data. The data is sourced from the Food Safety Inspection Dataset compiled by the International Data Analysis and Management Research Center of Zhejiang University, and focuses on extracting the data of unqualified food samples, which cover detailed information such as food categories, pollutant categories, food production locations, and food sales locations.

[0013] 1.2 Clean and screen the original dataset. To ensure the accuracy and integrity of the data and prevent the occurrence of invalid data, filter out the data containing complete information such as food categories, pollutant categories, food production locations, and food sales locations. Further, ensure that there are at least 200 samples in each food category, and the number of samples detecting the same pollutant in each category must be greater than 1 to avoid biases caused by insufficient sample size or abnormal data.

[0014] 1.3 Mark the food sample labels. Based on the processed food safety data, food domain experts label the risk levels of food samples according to the test values of pollutants and the corresponding legal thresholds in each food sample. The risk level labels are divided into four levels, namely Level 0, 1, 2, and 3, to represent different degrees of food safety risks of the samples.

[0015] Even further, Step 2 specifically includes:

[0016] 2.1 Construct a heterogeneous graph. To utilize the heterogeneous network model for embedding calculation and risk prediction, it is necessary to convert tabular data into a heterogeneous graph structure. Based on food safety detection data, the constructed heterogeneous graph contains food sample nodes, food production location nodes, food sales location nodes, food category nodes, pollutant category nodes, and food risk level nodes. Different types of nodes are connected by edges according to their attribute relationships, specifically including the edges between food sample nodes and corresponding food production location nodes, food sample nodes and corresponding food sales location nodes, food sample nodes and corresponding pollutant category nodes, food sample nodes and corresponding food category nodes, and food sample nodes and corresponding food risk level nodes.

[0017] 2.2 Construct the feature matrix and adjacency matrix. According to the attribute information in the food sample data, construct the feature matrix X of food samples, which is expressed as:

[0018]

[0019] Among them, there are m rows in X, and m represents the number of food samples. Each row vector X i =(x i1 ,x i2 ,...,x ij ,...x in ), where i ∈ {1, 2,..., m}, representing the attribute feature vector of the i-th food sample. For the attribute values, one-hot encoding is used for encoding, and the encoding results of each attribute are concatenated into an overall feature vector, where j ∈ {1, 2,..., n} represents the feature dimension.

[0020] Next, construct the adjacency matrix according to the relationship between food sample nodes and attribute nodes. For each type of node relationship, generate the corresponding adjacency matrix, where the connected node pairs are encoded as 1 and the unconnected node pairs are encoded as 0.

[0021] 2.3 Design meta-paths and input them into the heterogeneous network model for training. After constructing the heterogeneous graph, further design meta-paths with semantic expression ability to explore the association relationships of food sample nodes under different context semantics. According to different semantics, multiple optional meta-paths are preset, including "food sample - production location - food sample", "food sample - sales location - food sample", "food sample - food type - food sample", "food sample - pollutant type - food sample", "food sample - food risk level - food sample". Initially, equal weights are assigned to the first four types of meta-paths, and the fifth type of meta-path is assigned a value of 0.

[0022] Next, select a suitable heterogeneous neural network model for calculation. Here, the HAN (Heterogeneous Graph Attention Network) model is used for calculation. The feature matrix and adjacency matrix obtained in the previous step are used as the input to the model for embedding result generation and risk level prediction.

[0023] Furthermore, step 3 specifically includes:

[0024] 3.1 Construct a meta-path weight adjustment and exploration interaction framework. To explore the impact of the meta-path composition on the embedding results generated by the model, a flexible exploration framework needs to be constructed to support the dynamic adjustment of meta-path weights and timely feedback of the embedding results. This framework uses the control panel as the core component of the visual interaction system. Users can adjust the meta-path composition of the system in real time through this panel, thereby affecting the embedding results.

[0025] 3.2 Visualization display of the embedding results and meta-path composition. The two-dimensional distribution of the embedding results of food samples generated under the current meta-path composition is obtained through dimensionality reduction techniques and displayed using a scatter plot. Options for coloring food nodes according to different attributes are provided to facilitate observing the distribution of different attribute values. At the same time, the current meta-path composition is displayed through a node-link view. The colors and shapes of the nodes encode different types of nodes, and the edges of the corresponding colors encode the meta-paths related to the attributes. The size of the food nodes encodes the number of food samples, the size of the attribute nodes encodes the sum of the number of food samples contained in all connected food nodes, and the thickness of the edges encodes the weight size of the corresponding meta-path. To avoid visual chaos caused by too many nodes, options are provided to expand food nodes into more detailed points according to the meta-path type, and users are allowed to select some adjacent nodes in the scatter plot through brushing and clicking to display local meta-paths.

[0026] 3.3 Design of the embedding result difference comparison and analysis. To deeply understand the impact of meta-paths on the embedding results, the system provides records of the meta-path compositions before and after, and compares the generated embedding results. Users can view the scatter plots obtained from the two calculations simultaneously and explore the changes in the positions of the same food sample nodes in the two scatter plots through brushing and clicking operations. The shared neighborhood view shows the distribution of neighborhood nodes in the two embedding results. The view is an incompletely aligned heat matrix, where the abscissa represents the neighborhood range, the ordinate represents the number of identical neighbor nodes of a certain node in the neighborhood in the two embedding results, and the color depth of each grid encodes the number of food sample nodes with n identical neighbor nodes in the m-node neighborhood represented by the grid. By clicking on the grid, the relevant node positions can be located in the scatter plot.

[0027] Furthermore, step 4 specifically includes:

[0028] 4.1 Influence of Visualization Attributes on Food Risk Levels. To visually demonstrate the influence of different attributes on food risk levels, a matrix heat map was designed to show the average risk levels of food samples with different attribute values. The view consists of 4×4 small heat matrices. The horizontal and vertical coordinates of each small heat matrix represent the attribute values of two different or identical attributes. The color shade of each square encodes the average risk level of food samples with the same combination of attribute values, and combinations of attribute values with higher risks are further emphasized in blue, orange, and red.

[0029] 4.2 Visualization of Food Risk Level Prediction Results and Analysis of Distribution Characteristics. According to the exploration method provided by the view in the above steps, users can fully understand the data and further adjust the meta-path weights based on their understanding to optimize the food risk prediction model. The system makes predictions in real time and displays the results in the prediction view. The prediction view shows the prediction results based on the prediction probabilities of several risk levels. The top, left, right, and bottom of the view correspond to risk levels 0, 1, 2, and 3 respectively. The greater the probability of predicting a certain risk level, the more the corresponding food sample node shifts in the direction of the corresponding risk level. This view also supports simultaneously displaying the prediction results under the composition of two meta-paths and differentiating them by node transparency. In addition, users can brush and select nodes within a certain range in the prediction view, and a histogram is provided to show the distribution of node attribute values to further judge the reliability of the prediction results. Figure 1 nodes within a certain range and provides a histogram to show the distribution of node attribute values to further judge the reliability of the prediction results.

[0030] The second aspect of the present invention relates to a visual analysis device for food risk prediction based on meta-path selection, including a memory and one or more processors. Executable code is stored in the memory. When the one or more processors execute the executable code, it is used to implement the visual analysis method for food risk prediction based on meta-path selection of the present invention.

[0031] The present invention mainly solves the following three problems: ① The present invention constructs a visual interactive meta-path control framework, which supports users to flexibly select whether to enable specific meta-paths to participate in model calculations and can adjust the weights of each meta-path in real time. This mechanism not only enhances the operability and flexibility of the system but also provides technical support for users to deeply participate in model configuration and optimization; ② The present invention visually displays the composition structure of meta-paths and combines it with the embedded result comparison view, enabling users to intuitively observe the impact of changes in the composition of meta-paths on the embedded results of food samples. Through visual comparison and interactive exploration, it helps users understand the embedding mechanism and feature aggregation method of the model and improves the interpretability of the model; ③ The present invention displays food risk prediction results in a probability-based manner, supports users to explore the attribute distribution of prediction results, helps evaluate the rationality and credibility of prediction results, thereby enhancing the transparency and interpretability of the prediction process.

[0032] Summary of the advantages of the present invention: (1) Simple operation and strong intuitiveness. Users can adjust the weights of meta-paths through simple interactive operations. The system will display the embedding results and prediction results in real time, and show the influence of each attribute on the prediction results through visual charts, enhancing users' understanding and trust in the prediction process. (2) High innovation and provision of diversified analysis perspectives. There is currently no similar food risk prediction method based on meta-path selection and visual analysis. The present invention can flexibly adjust the weights of meta-paths and display the results through an interactive visualization system, helping developers and domain experts deeply analyze the influence of meta-paths on risk level prediction, especially with significant innovation in the feature aggregation mechanism and prediction reliability of the model. (3) Practical significance. Through intuitive display of prediction results and interactive analysis, non-expert users can also quickly understand the background and basis of food risk prediction, especially suitable for food safety monitoring and decision support, greatly enhancing the interpretability and credibility of the system. Brief Description of the Drawings

[0033] Figure 1 is the overall flow chart of the method of the present invention.

[0034] Figure 2 is the actual interface of the system of the method of the present invention.

[0035] Figure 3 is the schematic diagram of the device of the present invention. Detailed Embodiments

[0036] The technical solutions of the present invention will be further described below with reference to the drawings.

[0037] Embodiment 1

[0038] Refer to Figure 1 The present invention generally includes four stages, namely data cleaning and preprocessing, heterogeneous graph construction and meta-path design, meta-path adjustment and visualization analysis design of embedding results, and food risk prediction display and interactive analysis design.

[0039] This embodiment relates to a visual analysis method for food risk prediction based on meta-path selection, and the specific steps are as follows:

[0040] Step 1: Clean and preprocess the data; clean and preprocess the food safety data according to certain rules to ensure the effectiveness of the data, and label the risk level of the food according to the food pollutant detection value;

[0041] 1.1 Obtain the original data. The data is sourced from the Food Safety Inspection Dataset compiled by the International Data Analysis and Management Research Center of Zhejiang University, which contains 2.6 million food sample data from the website of the China Food and Drug Administration. I focused on extracting 89,202 unqualified food sample data from 2010 to 2020. The data covers detailed information such as food categories, pollutant categories, food production locations, and food sales locations.

[0042] 1.2 Clean and filter the original dataset. To remove invalid data, filter out data with incomplete information such as food categories, pollutant categories, food production locations, and food sales locations. At the same time, filter out food types with less than 200 samples. Eventually, 20 food categories were retained. Additionally, to avoid biases caused by insufficient sample sizes or abnormal data, for each food category, retain food sample data where the number of samples detecting the same pollutant is greater than 1. Finally, 9,270 food sample data were retained.

[0043] 1.3 Label the food sample tags. After the food safety detection data has been cleaned and filtered, extract the actual detection values of all pollutants in each food sample. Food domain experts annotate the risk levels of all food samples based on the legal thresholds of the corresponding pollutants. According to the degree of pollutant exceeding the standard and its impact on food safety risks, from light to heavy, label the food samples as risk levels 0, 1, 2, and 3 respectively.

[0044] Step 2: Construct a heterogeneous graph and design meta-paths; construct a heterogeneous graph based on the attribute characteristics of the food detection dataset and design meta-paths for the heterogeneous network model calculation.

[0045] 2.1 Construct a heterogeneous graph. Based on the preprocessed food sample dataset, extract the following six types of information from the data as the node types of the heterogeneous graph: food sample nodes, with each detection record corresponding to a food node; food production location nodes, such as Jiangsu Province, Sichuan Province, Anhui Province, etc.; food sales location nodes, such as Zhejiang Province, Guangdong Province, Shandong Province, etc.; pollutant category nodes, such as microbial contamination, pesticide and veterinary drug residues, toxin contamination, etc.; food category nodes, such as vegetable foods, meat foods, pastry foods, etc.; food risk level nodes, such as risk levels 0, 1, 2, and 3. Map each unique attribute value to a graph node and assign an independent number range to each type of node to ensure the uniqueness and distinguishability of the heterogeneous graph nodes. According to the attribute fields in the food sample records, construct the following edge types and establish edge pairs using key-value mapping: food sample node - food production location node, food sample node - food sales location node, food sample node - pollutant category node, food sample node - food category node, food sample node - food risk level node. Each edge type constructs an edge table separately, and the edge table is saved in the form of source node ID and target node ID.

[0046] 2.2 Construct the feature matrix and adjacency matrix. Construct the feature matrix X of food samples according to the attribute information in the food sample data. Among them, each row of the matrix X corresponds to a food sample, and the columns represent the feature encodings of different attributes. The attribute features are processed using one-hot encoding, and the feature content includes fields such as the food production place, food sales place, pollutant category, food category, etc. At the same time, according to the various edge tables constructed in step 2.1, the corresponding adjacency matrices are generated respectively. Each node connection relationship corresponds to an adjacency matrix. For node pairs with edge connections, the matrix elements are marked as 1, and node pairs without connections are marked as 0.

[0047] 2.3 Design meta-paths and input them into the heterogeneous network model for training. After completing the construction of the heterogeneous graph structure and the generation of the adjacency matrix, in order to enhance the model's ability to model semantic relationships in the graph, the design of meta-paths is introduced to further guide the heterogeneous graph neural network to perform semantic aggregation and embedding learning on nodes. Based on the semantic relationships between various nodes and edges in the graph structure, the following meta-paths are preset to capture the indirect associations of food sample nodes in different contexts: P1 "food sample - production place - food sample" represents the association between food samples under the background of the same production place; P2 "food sample - sales place - food sample" represents the relationship between samples under the background of the same circulation and sales; P3 "food sample - pollutant category - food sample" represents the potential risk chain that may exist between foods detected with the same pollutant; P4 "food sample - food category - food sample" represents the connection between foods of the same category; P5 "food sample - food risk level - food sample" represents strengthening the semantic association according to the existing risk level information. In the initial stage, four meta-paths, P1–P4, are adopted and given equal weights, that is, [0.25, 0.25, 0.25, 0.25, 0], for modeling.

[0048] The present invention uses the HAN model as the embedding learning model, which is implemented based on the PyTorch framework. The input includes the feature matrix of food samples, the adjacency matrix corresponding to the heterogeneous graph, and the meta-paths with the above initial weight settings, which can be manually adjusted during the subsequent training process. The model output is a 64-dimensional embedding vector for each food sample node. In the food risk level prediction stage, the Adam optimizer is used, the initial learning rate is set to 0.001, and the number of training epochs is set to 200 to ensure that the model can fully converge. To ensure the real-time performance of the visual system interaction, 5000 pieces of data are randomly selected from the filtered food safety dataset for embedding calculation, and 1500 pieces of data are used for the training and testing of risk prediction. Among them, considering the imbalance in the distribution of risk level labels, to reduce the impact of data bias, the following sampling strategy is adopted: 850 samples are randomly selected from the samples with a risk level of 0; 250 samples are randomly selected from the samples with a risk level of 1; 100 samples are randomly selected from the samples with a risk level of 2; 300 samples are randomly selected from the samples with a risk level of 3.

[0049] Step 3: Design of meta-path adjustment and visualization analysis of embedding results; Based on the heterogeneous graph features and structural data obtained from the above steps, the present invention will design multiple visualization views to support users' interactive exploration of the impact of meta-paths and embedding effects.

[0050] 3.1 Construct a meta-path weight adjustment and exploration interaction framework. To support users in flexibly adjusting the composition of meta-paths based on different analysis requirements and observing the impact on the embedding results in real time, the system designs and implements a meta-path interactive control framework. This framework uses a visual control panel as the interaction entry point, and allows users to enable or disable a certain meta-path, adjust the weight coefficient corresponding to each meta-path, and synchronously transfer the adjusted meta-path configuration to the backend model to trigger the recalculation of the embedding.

[0051] 3.2 Visualization display of embedding results and meta-path composition. After obtaining the embedding vectors generated after each round of adjustment, the system maps the high-dimensional embedding results to a two-dimensional space through the UMAP dimensionality reduction technique and displays them through a scatter plot view. Each point in the scatter plot represents a food sample node, and the nodes can be color-coded according to different attribute fields to observe the clustering distribution of the samples under different semantic attributes. At the same time, the system constructs a meta-path composition view to show the structural composition of the currently used meta-paths in the form of a node-link graph. Different types of nodes are encoded with different colors and shapes, the size of the nodes represents the number of associated samples, the color of the edges represents the meta-path association attributes, and the thickness encodes the current meta-path weight value. In the initial state, all selected food samples are aggregated into one food node, and it supports classifying and aggregating food nodes according to the specified meta-path association attributes to further explore node information.

[0052] 3.3 Embedding result difference comparison and analysis design. To further support users in analyzing the impact of different meta-path combinations on the embedding effect, a comparison view of the embedding results before and after is designed, including a juxtaposed embedding scatter plot view and a shared neighborhood view. The juxtaposed embedding scatter plot view respectively shows the dimensionality reduction results of the food node embeddings generated before and after the meta-path adjustment, supports click-and-brush operations, and highlights the positions of the selected nodes in both views to observe the changes in their spatial positions. The shared neighborhood view is used to analyze the degree of neighborhood consistency of a certain node in the two embedding spaces. The view is in matrix form, where the abscissa represents the neighborhood range, the ordinate represents the number of the same neighbors within the neighborhood in the two embedding views, and the color coding of the squares represents the number of samples with n common neighbor nodes within the neighborhood of m nodes.

[0053] Step 4: Food risk prediction display and interactive analysis design; through the previous steps, the present invention helps users understand the impact of meta-paths on model embedding, and on this basis, further guides users to understand the association between attributes and risk levels, so as to support them in optimizing the meta-path configuration, obtaining more interpretable food risk prediction results, and enhancing the transparency and credibility of prediction decisions.

[0054] 4.1 Visualizing the impact of attributes on food risk levels. To help users understand the formation mechanism of food risk levels from the attribute level, the system designs and implements a heat map view of the attribute cross-influence matrix, statistically calculates the average risk levels corresponding to food samples under different combination conditions, and sets colors to highlight high-risk combinations.

[0055] 4.2 Visual display of food risk level prediction results and distribution feature analysis. After users fully understand the role of meta-paths and the attribute information of food data, they can adjust the meta-path weights according to their own understanding, thereby affecting the risk prediction results of the model. The system generates the risk level prediction results of food samples in real time based on the output of the adjusted model and displays them in the prediction result visualization view. The prediction results are displayed based on the predicted probabilities. The four edge regions of the view, namely the top, left, right, and bottom, respectively correspond to risk levels 0, 1, 2, and 3. The offset direction of the node in the graph is proportional to the probability of predicting it as a certain level. The node transparency is used to distinguish the prediction results under different meta-path weight configurations to support prediction comparison analysis, and a histogram view is provided to statistically analyze the value distribution of nodes within the selected range for each attribute. This module can effectively support users in deeply analyzing and making reasonable judgments on the model results during the prediction stage, enhancing the interpretability, transparency, and user trust of the model results.

[0056] Example 2

[0057] Refer to Figure 3, This embodiment relates to the second aspect of the present invention, which is a visual analysis device for food risk prediction based on meta-path selection, including a memory and one or more processors. An executable code is stored in the memory. When the one or more processors execute the executable code, it is used to implement the visual analysis method for food risk prediction based on meta-path selection in Embodiment 1.

[0058] The content described in the embodiments of this specification is only an enumeration of the implementation forms of the inventive concept. The protection scope of the present invention should not be regarded as limited to the specific forms stated in the embodiments. The protection scope of the present invention also extends to equivalent technical means that those skilled in the art can think of according to the inventive concept of the present invention.

Claims

1. A visual analysis method for food risk prediction based on metapath selection, comprising the following steps: Step 1: Clean and preprocess the food detection data to ensure the scientificity and effectiveness of the data; assign risk level labels to each sample based on the detected values of pollutants and legal thresholds. Step 2: Through preprocessing of food attribute features, construct a heterogeneous graph for different types of nodes and their relationships, design suitable metapaths in combination with domain knowledge, and convert the preprocessed food tabular data in the previous step into a data format suitable for the HAN heterogeneous model. Step 3: Interactively adjust the metapath weights in the visualization system and calculate the embedding results of food samples in real time. Design multiple visualization views, perform dimensionality reduction display on the embedding results of food samples through the embedding result distribution view, and at the same time provide a metapath composition view and design an embedding comparison view to help users deeply understand the impact of metapaths on the embedding calculation results. Step 4: Visually provide the joint impact of display attributes on the food risk level as the basis for metapath weight assignment; through model calculation, generate food risk level predictions based on the current metapath composition and display the prediction results in the form of prediction probabilities; at the same time, analyze the attribute distribution within the custom interval of the prediction results as support for the prediction results.

2. A food risk prediction visual analysis method based on meta-path selection, characterized in that Step 1 specifically includes: 1.1 Obtain the original data; the data is sourced from the Food Safety Inspection Dataset compiled by the International Data Analysis and Management Research Center of Zhejiang University, and focuses on extracting the data of unqualified food samples, which cover detailed information such as food categories, pollutant categories, food production locations, and food sales locations. 1.2 Clean and screen the original dataset; to ensure the accuracy and integrity of the data and prevent the occurrence of invalid data, filter out the data containing complete information such as food categories, pollutant categories, food production locations, and food sales locations; further, ensure that there are at least 200 samples in each food category, and the number of samples detecting the same pollutant in each category must be greater than 1 to avoid biases caused by insufficient sample size or abnormal data. 1.3 Mark the food sample labels; based on the processed food safety data, food domain experts label the food samples with risk levels according to the detected values of pollutants and the corresponding legal thresholds in each food sample; the risk level labels are divided into four levels, namely level 0, 1, 2, and 3, to represent different degrees of food safety risks of the samples.

3. A visual analysis method for food risk prediction based on meta-path selection, characterized in that, Step 2 specifically includes: 2.1 Construct a heterogeneous graph; To utilize the heterogeneous network model for embedding calculation and risk prediction, it is necessary to convert tabular data into a heterogeneous graph structure; Based on food safety detection data, the constructed heterogeneous graph includes food sample nodes, food production location nodes, food sales location nodes, food category nodes, pollutant category nodes, and food risk level nodes; Different types of nodes are connected by edges according to their attribute relationships, specifically including the edges between food sample nodes and corresponding food production location nodes, food sample nodes and corresponding food sales location nodes, food sample nodes and corresponding pollutant category nodes, food sample nodes and corresponding food category nodes, and food sample nodes and corresponding food risk level nodes. 2.2 Construct a feature matrix and an adjacency matrix; According to the attribute information in the food sample data, construct a feature matrix X of food samples, expressed as: Among them, there are m rows in X, and m represents the number of food samples; each row vector X i =(x i1 , x i2 ,..., x ij ,... x in ), where i ∈ {1, 2,..., m}, representing the attribute feature vector of the i-th food sample; for the attribute values, one-hot encoding is used for encoding, and the encoding results of each attribute are concatenated into an overall feature vector, where j ∈ {1, 2,..., n} represents the feature dimension; Next, construct an adjacency matrix based on the relationship between food sample nodes and attribute nodes; For each type of node relationship, generate a corresponding adjacency matrix, where connected node pairs are encoded as 1 and unconnected node pairs are encoded as 0; 2.3 Design meta-paths and input them into the heterogeneous network model for training; After constructing the heterogeneous graph, further design meta-paths with semantic expression capabilities to explore the association relationships of food sample nodes under different context semantics; According to different semantics, multiple selectable meta-paths are preset, including "food sample - production location - food sample", "food sample - sales location - food sample", "food sample - food type - food sample", "food sample - pollutant type - food sample", "food sample - food risk level - food sample"; Initially, equal weights are assigned to the first four types of meta-paths, and the fifth type of meta-path is assigned a value of 0; Select the HAN heterogeneous neural network model for calculation, and use the feature matrix and adjacency matrix obtained in the previous step as input to the model for generating embedding results and predicting risk levels.

4. A visual analysis method for food risk prediction based on meta-path selection, characterized in that, Step 3 specifically includes: 3.1 Construct a meta-path weight adjustment and exploration interaction framework; To explore the impact of the meta-path composition on the embedding results generated by the model, it is necessary to construct a flexible exploration framework that supports dynamic adjustment of meta-path weights and timely feedback of embedding results; This framework uses a control panel as the core component of the visual interaction system, and users can use this panel to adjust the meta-path composition of the system in real time, thereby affecting the embedding results; 3.2 Visualization display composed of embedding results and meta-paths; Obtain the two-dimensional distribution of the embedding results of food samples generated under the current meta-path composition through dimensionality reduction technology and display it using a scatter plot; Provide the option to color food nodes according to different attributes to facilitate observing the distribution of different attribute values; At the same time, display the current meta-path composition through a node-link view. The colors and shapes of the nodes encode different types of nodes, and the edges of the corresponding colors encode the meta-paths related to the attributes; The size of the food nodes encodes the number of food samples, the size of the attribute nodes encodes the sum of the number of food samples included in all connected food nodes, and the thickness of the edges encodes the weight size of the corresponding meta-path; To avoid visual chaos caused by too many nodes, provide the option to expand food nodes into more detailed nodes according to the meta-path type, and allow users to select some adjacent nodes in the scatter plot through brushing and clicking to display local meta-paths; 3.3 Design of comparative analysis of embedding result differences; To deeply understand the impact of meta-paths on embedding results, the system provides records of the meta-path compositions before and after, and compares the generated embedding results; Users can view the scatter plots obtained from the two calculations at the same time and explore the changes in the positions of the same food sample nodes in the two scatter plots through brushing and clicking operations; The shared neighborhood view shows the distribution of neighborhood nodes in the two embedding results. The view is an incompletely aligned heat matrix, where the abscissa represents the neighborhood range, the ordinate represents the number of identical neighbor nodes of a certain node in the neighborhood in the two embedding results, and the color depth of each square encodes the number of food sample nodes with n identical neighbor nodes in the m-node neighborhood represented by the square; By clicking on the square, the relevant node position can be located in the scatter plot.

5. A visual analysis method for food risk prediction based on meta-path selection, characterized in that, Step 4 specifically includes: 4.1 Visualize the impact of attributes on food risk levels; To intuitively display the impact of different attributes on food risk levels, a matrix heat view is designed to show the average risk levels of food samples with different attribute values; The view consists of 4×4 small heat matrices. The abscissa and ordinate of each small heat matrix represent the attribute values of two different or the same attributes. The color depth of each square encodes the average risk level of food samples with the same attribute value combination, and the attribute value combinations with higher risks are further emphasized in blue, orange, and red; 4.2 Visual display of food risk level prediction results and analysis of distribution characteristics; according to the exploration method provided by the views in the above steps, users can fully understand the data, and can further adjust the meta-path weights according to their understanding to optimize the food risk prediction model; the system makes predictions in real time and displays the results in the prediction view; the prediction view displays the prediction results based on the prediction probabilities of several risk levels. The top, left, right, and bottom of the view correspond to risk levels 0, 1, 2, and 3 respectively. The greater the probability of predicting a certain risk level, the more the node of the corresponding food sample deviates in the direction of the corresponding risk level; this view also supports simultaneously displaying the prediction results under the composition of two meta-paths and differentiating them by node transparency; in addition, users can brush and select nodes within a certain range of the prediction view and provide a histogram to display the distribution of node attribute values for further judgment on the reliability of the prediction results.

6. A visual analysis device for food risk prediction based on meta-path selection, characterized in that, Comprising a memory and one or more processors, wherein executable code is stored in the memory, and when the one or more processors execute the executable code, it is used to implement the visual analysis method for food risk prediction based on meta-path selection according to any one of claims 1-5.