A machine learning-based heavy metal tracing and interpretation method

CN122527701APending Publication Date: 2026-08-07NANJING INST OF ENVIRONMENTAL SCI MINIST OF ECOLOGY & ENVIRONMENT OF THE PEOPLES REPUBLIC OF CHINA +1
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
NANJING INST OF ENVIRONMENTAL SCI MINIST OF ECOLOGY & ENVIRONMENT OF THE PEOPLES REPUBLIC OF CHINA
Filing Date
2026-05-18
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

然而,PCA存在线性假设局限、缺乏监督信息、对异常值敏感、难以剔除噪声特征等不足,导致降维后的特征子集未必是最优分类特征组合,可能包含与污染源分类无关或冗余的噪声特征,因此构建的特征指纹不精确

Benefits of technology

(1)通过结合Boruta与递归特征筛选构建重金属污染源特征指纹谱库,有效去除冗余特征,提高模型输入数据的代表性与鲁棒性;

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122527701A_ABST
    Figure CN122527701A_ABST
Patent Text Reader

Abstract

The present application relates to a kind of heavy metal traceability and interpretation method based on machine learning, first, obtain pollution source sample monitoring data;Identify characteristic fingerprint library;Then, build PSO-RF model, integrate voting output pollution source classification result;Finally, the marginal contribution of each feature to the prediction result is calculated using SHAP method, and the key traceability features of pollution source analysis process are identified to provide global and local explainability for the model;Combine RAG with large language model, and convert model output into natural language traceability interpretation.The present application optimizes machine learning model and machine learning pollution source identification process, and improves the accuracy of heavy metal pollution source identification in river and lake water.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a machine learning-based method for tracing and interpreting heavy metal sources, belonging to the technical field of heavy metal pollution source tracing. Background Technology

[0002] Most heavy metals are potentially hazardous pollutants, characterized by high toxicity, persistence, and bioaccumulation, which can easily cause serious damage to aquatic ecosystems. Accurately identifying the sources of heavy metal pollution is a key prerequisite for carrying out water environment governance and risk management. However, due to the complexity of pollution sources (such as industrial wastewater, agricultural non-point source pollution, atmospheric deposition, and traffic emissions), pollution fingerprint characteristics often exhibit high dimensionality and non-linearity, posing a significant challenge to accurate source tracing.

[0003] Currently, traditional methods for tracing the sources of heavy metal pollution in rivers and lakes involve isotope tracing, principal component analysis, and positive definite matrix factorization, which are limited by weak nonlinear source resolution capabilities. With the rapid development of machine learning technology, machine learning-based source tracing methods relying on data-driven models are increasingly emerging. Machine learning (such as random forests, support vector machines, XGBoost, and deep learning), with its powerful nonlinear mapping and feature extraction capabilities, can identify the characteristic fingerprints of pollution sources from complex data, providing a more flexible technical path for accurate source tracing. Although machine learning has strong predictive capabilities, it still has certain limitations, including the following issues: (1) Inaccurate fingerprinting of pollution source characteristics Existing methods typically use monitoring indicators directly as model inputs or employ unsupervised dimensionality reduction techniques such as Principal Component Analysis (PCA) to select key fingerprint features. However, PCA suffers from limitations such as linearity assumptions, lack of supervision information, sensitivity to outliers, and difficulty in removing noisy features. Consequently, the dimensionality-reduced feature subset may not be the optimal combination of classification features and may contain noisy features that are irrelevant to pollution source classification or are redundant, resulting in inaccurate feature fingerprints.

[0004] (2) Insufficient accuracy in source tracing of machine learning algorithms: The performance of a single machine learning model (such as random forest, support vector machine or XGBoost) is highly dependent on the setting of hyperparameters, and the optimal value of hyperparameters changes dynamically with the data features. In practical applications, relying on experience or grid search for parameter tuning is inefficient and prone to getting trapped in local optima, resulting in insufficient accuracy in pollution source classification.

[0005] (3) The black box model lacks interpretability Most machine learning models are "black box" models, meaning their internal decision-making mechanisms are opaque. They can only output pollution source classification results, but cannot explain the contribution of each feature to the prediction results, nor can they provide verifiable evidence for tracing the source. Summary of the Invention

[0006] To address the aforementioned problems, this invention discloses a machine learning-based method for tracing and interpreting heavy metal sources, the specific technical solution of which is as follows: A machine learning-based method for tracing and interpreting heavy metal sources includes the following steps: Step 1: Obtain monitoring data of pollution source samples; Step 2: Identify the feature fingerprint database Step 2.1: Standardization: Z-score standardization is used to eliminate differences in dimensions and magnitudes; Step 2.2: Feature selection: The Boruta method is used to remove noisy features that are irrelevant to the pollution source classification, and the first-level feature set A is obtained; Step 2.3: Recursive optimization screening: The recursive feature elimination method RF-RFE based on random forest is used to recursively screen the first-level feature set A to obtain the second-level optimal feature subset B; Step 3: Construct the PSO-RF model Step 3.1: Use the second-level optimal feature subset B obtained in Step 2.3 as the model input matrix X. B The pollution source type is used as the output label Y to divide the training set and the test set; Step 3.2: Use the Particle Swarm Optimization (PSO) algorithm to globally optimize the hyperparameters of the Random Forest (RF). Step 3.3: Construct a random forest model based on the optimal hyperparameters, train multiple decision trees through Bootstrap sampling and random feature selection, and integrate voting to output the pollution source classification results; Step 4: Enhance model interpretability Step 4.1: Use the SHAP method to calculate the marginal contribution of each feature to the prediction results, identify the key source-tracing features in the pollution source apportionment process, and provide global and local interpretability for the model; Step 4.2: Combine RAG with the large language model to transform the model output into a natural language etymological explanation.

[0007] Furthermore, step 1 specifically involves: acquiring monitoring data of potential pollution source samples within the study area, determining the content of heavy metal elements in the pollution sources using inductively coupled plasma mass spectrometry (ICP-MS), determining the stable isotope ratios using multi-receiver inductively coupled plasma mass spectrometry (MC-ICP-MS), removing outliers from the data, and constructing a pollutant fingerprint spectral library.

[0008] Furthermore, the specific process of step 2.1 is as follows: The heavy metal element content and isotope ratio data show significant differences in dimensions and numerical ranges. By performing Z-score standardization on the heavy metal element content and isotope ratio data, all features are transformed to a unified scale with a mean of 0 and a standard deviation of 1. The Z-score standardization calculation formula is as follows: , In the formula: i is the row, j is the column, and Z is the column. ij It is the standardized expression value, X ij It is the original value, μ j σ is the mean of the data in the j-th column. j It is the standard deviation of the data in column j; Mean: ,

[0009] Standard deviation: ,

[0010] In the formula: q is the number of pollution source samples.

[0011] Furthermore, the specific process in section 2.2 is as follows: First, an initial random forest model is constructed. The input is the original feature matrix Z and the label Y. The original feature matrix Z has a dimension of q×p, where q is the number of pollution source samples and p is the number of variables, including the content of heavy metal elements and the ratio of stable isotopes. The label Y is the type of pollution source. A set of shadow features with no real relationship to the label vector is generated by randomly shuffling the original features. Then, the importance of the original features and the shadow features is compared. If the importance of the original features is significantly higher than the maximum importance of all shadow features, it is marked as "important". If it is lower, it is marked as "irrelevant". Otherwise, it is marked as "pending". Then, in each iteration, "irrelevant" features are removed, and the random forest model is reconstructed based on the remaining features and evaluated repeatedly until all features are clearly classified or the maximum number of iterations is reached; finally, the first-level feature set A is output.

[0012] Furthermore, the specific process of step 2.3 is as follows: First, using the first-level feature set A as input, a random forest model is trained using all features. The contribution of each feature to the classification performance is evaluated through the feature weights output by the model, and the feature with the smallest contribution is identified. Then, based on the importance of the features, remove the feature with the lowest importance in the current feature set each time, or remove features in batches by rounding down to 10% of the current number of features. In each iteration, the remaining feature set is used to repeat the above training, evaluation and removal steps until the feature set is reduced to the preset minimum size or the specified number of iterations is reached. Finally, the feature subset obtained from the last iteration is determined as the second-level optimal feature subset B.

[0013] Furthermore, the specific process of step 3.2 is as follows: Step 3.21 Initialize the particle swarm Randomly generate a particle swarm, with each particle containing hyperparameters of the RF model; Set the particle swarm size N and the maximum number of iterations G. max Inertia weight w, learning factors c1 and c2; Within the defined hyperparameter search space, initialize the particle's position and velocity; Calculate the initial fitness value for each particle: For each combination of hyperparameters of the random forest represented by a particle, the fitness value is calculated using the K-fold cross-validation method. The dataset is divided into K mutually exclusive subsets. One subset is selected as the validation set, and the remaining subsets are used as the training set. A random forest model is built based on the training set, and predictions are made on the validation set. The precision and recall of each class are calculated based on the prediction results. The F1-score is then calculated, and the average of the F1-scores obtained from the K cross-validations is taken as the fitness function value of the particle. Accuracy: , Recall rate: , F1 score: , , The particle's fitness function value: , In the formula: TP is a correct prediction and is predicted to be of this class; FP is a prediction of this class but actually belongs to another class; FN is a prediction of this class but is actually a different class; C is the number of pollution source categories; C is the number of pollution source categories; F1 C It is the F1-score for Category C pollution sources; F1 k It is the F1-score of the k-th cross-validation; Initialize the individual optimal position and the global optimal position; Step 3.22 Update the particle's velocity and position according to the update formula of the PSO algorithm: Speed ​​updates: , Location update: , in, and Let represent the velocity and position of the nth particle in the g-th iteration, respectively, and w be the inertial weight. and It is a learning factor. It represents the optimal position of an individual particle from the nth particle to the gth iteration. It represents the globally optimal position of the entire particle swarm up to the g-th iteration. and It is a random number between [0,1]. Step 3.23 Fitness Assessment The fitness value of each particle is calculated based on the fitness function; Step 3.24 Update the optimal value If the current particle's fitness value is better than its historical best value, then update the individual's best position; If the current particle's fitness value is better than the global optimum, then update the global optimum position; Step 3.25 Iterative Optimization Repeat steps 3.22 to 3.24 until the preset maximum number of iterations is reached or the minimum difference in fitness values ​​between two iterations is reached. Output the position of the globally optimal particle, which is the optimal combination of hyperparameters for the random forest.

[0014] Furthermore, the specific process of step 3.3 is as follows: Step 3.31 Parameter Setting: Random forests consist of multiple decision trees, each trained on a subset of the dataset sampled by Bootstrap. During node splitting, a subset of features is randomly selected for optimal splitting, and the final result is output through majority voting classification or average regression. Its hyperparameters include: n_estimators: Number of decision trees; max_depth: The maximum depth of the tree; min_samples_split: controls the minimum number of samples when splitting a node in the tree; min_samples_leaf: Minimum number of samples in a leaf node; max_features: The maximum number of features to consider during each split; Step 3.32 Bootstrap Sampling to Construct Training Subset From the original training set, multiple training subsets are constructed using the Bootstrap sampling method, which serve as the training data for each decision tree; Random sampling with replacement is performed on the original training set to extract M samples, forming a new training subset containing M samples. Due to sampling with replacement, some samples are not drawn. The samples that are not drawn are called out-of-bag samples; Out-of-bag samples are used for internal validation of the model; Step 3.33 Random Feature Selection When training a single decision tree for each training subset obtained by Bootstrap sampling, instead of using all features, y features are randomly selected from x features, where y < x. For classification tasks and then features are selected for splitting among these y features; Step 3.34 Construct Decision Tree Based on the above random "sample subset + feature subset", a single decision tree is constructed. The construction of each tree follows the following principles: Construct an unpruned decision tree. The single tree is deliberately overfitted, and the subsequent ensemble will offset the overfitting; The splitting criterion uses the Gini index. The sample set of the current node is the data set D. The data set D has a total of R categories, and the proportion of samples in the r-th category is P r then the Gini index is: , Under the condition of a certain feature E in the feature subset B, the data set D is divided into two parts D1 and D2, then the Gini gain of this feature is: , Repeat steps 3.32 - 3.34 until the stopping condition is met; The stopping conditions include: reaching the maximum tree depth, the number of samples in the node is less than the minimum splitting sample number, the number of samples in the leaf node is less than the minimum sample number of the leaf node, the samples in the current node belong to the same category or the node cannot be effectively divided continuously; Step 3.35 Ensemble Prediction Suppose T decision trees are constructed. Collect the prediction results of all T trees and use the majority voting method. The final prediction result is the category with the most votes: , In the formula: H(α) is the predicted category of the final ensemble model for the input α, is the indicator function, h t (α) is the prediction result of the t-th decision tree for the input α, T is the number of decision trees, and Y is the label of the pollution source type.

[0015] Furthermore, the specific process of step 4.1 is as follows: Feature combination traversal: Consider all possible combinations of feature subsets; Marginal contribution calculation: For each feature, calculate the marginal contribution it brings when added to any feature subset to measure the marginal impact of this feature on the model prediction result; Contribution-weighted average: The SHAP value for each feature is calculated using the following formula: , In the formula: B is the optimal feature subset. It is a subset of features that does not contain feature u. In the feature subset The predicted value below, It is the probability that feature u appears in the subset S among all possible permutations of features; The key features that have the greatest impact on pollution source identification are identified by calculating SHAP values, which serve as the basis for the source tracing conclusions.

[0016] Furthermore, the specific process of step 4.2 is as follows: First, based on the LangChain framework and the Chroma vector database, a literature library for tracing the source of heavy metal pollution is pre-constructed, containing journal articles, research reports, and standard specifications, and Llama 3.1 is selected as the generation model; after the PSO-RF model identifies the pollution source type, the system automatically extracts key features as search terms, performs semantic retrieval in the literature library, and provides the 3-5 most relevant literature evidences; finally, the output results of the PSO-RF model, the key feature SHAP value, and the retrieved literature are constructed into structured prompt words, and the large language model generates a natural language form of source tracing explanation.

[0017] The beneficial effects of this invention are: (1) By combining Boruta and recursive feature screening, a fingerprint spectrum library of heavy metal pollution sources is constructed, which effectively removes redundant features and improves the representativeness and robustness of the model input data; (2) Particle swarm optimization algorithm is introduced to optimize the hyperparameters of the random forest model, thereby improving the model’s accuracy and generalization ability in classifying heavy metal pollution sources. (3) Introduce the SHAP method to enhance the interpretability of the model and make the pollution source identification results have clear characteristic basis; (4) Combining RAG and LLM to generate natural language interpretations, providing literature data support to address the shortcomings of LLM-generated interpretations, such as generalization, lack of specificity, and susceptibility to hallucination. Attached Figure Description

[0018] Figure 1 This is the optimization process for the fingerprint database.

[0019] Figure 2 This is a flowchart of the particle swarm optimization algorithm.

[0020] Figure 3 This is a flowchart of a machine learning-based heavy metal tracing process. Detailed Implementation

[0021] The present invention will be further illustrated below with reference to the accompanying drawings and specific embodiments. It should be understood that the following specific embodiments are for illustrative purposes only and are not intended to limit the scope of the invention.

[0022] Combined with appendix Figure 1-3 The specific execution process of this invention is given below: Step 1: Obtain monitoring data of pollution source samples Acquire monitoring data of potential pollution sources within the study area. Determine the content of heavy metal elements in the pollution sources using inductively coupled plasma mass spectrometry (ICP-MS), and determine the stable isotope ratios using multi-receiver inductively coupled plasma mass spectrometry (MC-ICP-MS). Remove outliers from the data and construct a pollutant fingerprint spectral library.

[0023] Step 2: Identify the feature fingerprint database Step 2.1: Standardization Processing The heavy metal element content and isotope ratio data show significant differences in dimensions and numerical range. By performing Z-score standardization on these data, all features are transformed to a uniform scale with a mean of 0 and a standard deviation of 1. This not only eliminates the bias caused by differences in dimensions and magnitudes but also effectively improves the convergence speed and generalization performance of the subsequent Particle Swarm Optimization Random Forest (PSO-RF) model. The Z-score standardization formula is as follows: , In the formula: Z ij It is the standardized expression value, X ij It is the original value, μ i It is the mean, σ i That is the standard deviation.

[0024] Step 2.2: Feature Selection: The Boruta method is used to perform statistical significance testing on the fingerprint features, eliminating noisy features that are not significantly related to the pollution source classification, and obtaining the first-level feature set A. The specific process of the Boruta algorithm is as follows: (1) Constructing a random forest model: Input the feature matrix X and the target variable Y, and set the random forest parameters.

[0025] (2) Creating shadow features: To evaluate the importance of the original features, the Boruta algorithm shuffles the data and generates a set of shadow features corresponding to the original features. These shadow features are generated by randomly arranging the data of the original features and have no real relationship with the target variable.

[0026] (3) Comparing feature importance: The algorithm compares the importance of the original features with the importance of the shadow features. If the importance of a certain original feature is significantly higher than the maximum importance of all shadow features, it is marked as "important". If its importance is lower than the maximum importance of the shadow features, it is marked as "irrelevant". For those whose importance cannot be clearly judged, they are marked as "to be determined".

[0027] (4) Gradually eliminate irrelevant features: The algorithm iteratively removes features marked as "irrelevant" in each round and reconstructs the random forest model based on the remaining features, repeating the feature importance evaluation and comparison process described above. Iteration continues until all features are clearly classified as "important" or "irrelevant," or the preset maximum number of iterations is reached. (5) Output results: Finally, the Boruta algorithm outputs three types of features: important, irrelevant and undetermined. Important features can be retained for model building, while irrelevant features can be discarded. Undetermined features need to be further analyzed or selectively retained, and finally the first feature set A is obtained.

[0028] Step 2.3: Recursive optimization screening: The recursive feature elimination (RF-RFE) method based on random forest is used to recursively screen the first-level feature set A, with classification accuracy as the optimization objective, to obtain the second-level optimal feature subset B.

[0029] Dynamic Feature Extraction (RFE) is a dynamic feature selection method: each iteration trains the model based on the current feature set, recalculates feature importance, and removes the weakest features, achieving dynamic ranking. This mechanism allows for precise evaluation of changes in feature importance, gradually finding the optimal feature subset. The specific process is as follows: (1) Training the model: Using the first-level feature set A as input, train the random forest model using all features.

[0030] (2) Assess feature importance: Identify features that contribute little to model performance by using the feature weights or coefficients of the model.

[0031] (3) Remove the weakest feature: Based on the calculated feature importance ranking, identify one or more features with the lowest importance in the current feature set and remove them from the feature set. Removing one feature in each iteration can obtain the most refined feature selection result, but to improve computational efficiency, a certain percentage of the current total number of features can also be removed each time (e.g., 10% of the current number of features is removed each time, rounded down).

[0032] (4) Iterative repetition: In each iteration, the above steps are repeated using the remaining feature set from the previous round. This process continues until the feature set is reduced to the preset minimum size or the specified number of iterations is reached.

[0033] (5) Determine the final feature subset: the second-level feature set B used by the model obtained in the last iteration.

[0034] Step 3: Improvement of Machine Learning Algorithms Step 3.1: Model Input and Output The pollution source feature fingerprint data obtained after feature filtering is used as the model input matrix X, and the pollution source type is used as the output label vector y to construct the training set. To verify the model's generalization ability, a stratified sampling method is used to divide the dataset into a training set and a test set in a 7:3 ratio to ensure that the distribution ratio of various pollution sources is consistent between the training set and the test set.

[0035] Step 3.2: Particle Swarm Optimization Algorithm (1) Initialize the particle swarm Randomly generate a particle swarm, where each particle contains hyperparameters of the RF model; Set the particle swarm size N and the maximum number of iterations G. max Inertia weight w, learning factors c1 and c2; Within the defined hyperparameter search space, initialize the particle's position x. i and velocity v i ; Calculate the initial fitness value for each particle, and initialize the individual optimal position and the global optimal position.

[0036] (2) Update the particle's velocity and position according to the update formula of the PSO algorithm: Speed ​​updates: , Location update: , in, and Let their values ​​represent the velocity and position of the i-th particle in the t-th iteration, respectively. It is inertial weight. and As a learning factor, It represents the optimal position of the individual particle from the i-th particle to the t-th iteration. It represents the globally optimal position of the entire particle swarm up to the t-th iteration. and It is a random number between [0, 1].

[0037] (3) Fitness assessment The fitness value of each particle is calculated based on the fitness function.

[0038] (4) Update the optimal value If the fitness value of the current particle is better than its historical best value, update the individual best position; If the fitness value of the current particle is better than the global best value, update the global best position.

[0039] (5)Iterative optimization Repeat steps (2) to (4) until the preset maximum number of iterations or the minimum difference in fitness values between two iterations is reached, and output the position of the global best particle, which is the optimal hyperparameter combination of the random forest.

[0040] Step 3.3: Construction of the random forest model (1)Parameter setting The random forest consists of multiple decision trees. Each tree is trained on a sub-dataset sampled by Bootstrap and randomly selects a part of the features for optimal splitting when splitting nodes. Finally, the result is output through majority voting (classification) or averaging (regression). Its main hyperparameters include: n_estimators: The number of decision trees; max_depth: The maximum depth of the tree; min_samples_split: Controls the minimum number of samples when splitting nodes of the tree; min_samples_leaf: The minimum number of samples in the leaf node; max_features: The maximum number of features considered for each split.

[0041] (2)Construct training subsets by Bootstrap sampling From the original training set, use the Bootstrap sampling method to construct multiple training subsets as the training data for each decision tree.

[0042] Randomly sample with replacement from the original training set to draw N samples to form a new training subset containing N samples; Due to sampling with replacement, some samples are not drawn. The samples not drawn account for about 37% of the original training set, and these samples are called out-of-bag samples; The out-of-bag samples can be used for internal validation of the model, and the generalization ability of the model can be evaluated without separately dividing the test set, improving the sample utilization rate.

[0043] (3)Random feature selection For each training subset obtained by Bootstrap sampling, when training a single decision tree, not all features are used. Instead, m features are randomly selected from n features (m < n, usually taken for classification tasks ), and then features are selected for splitting among these m features.

[0044] (4) Constructing a decision tree Based on the above random "sample subset + feature subset", a single decision tree is constructed, and the construction of each tree follows the following principles: Build an unpruned decision tree, intentionally allowing each individual tree to overfit, and the subsequent ensemble will offset the overfitting; The splitting criterion uses the Gini index. The dataset D has K classes, and the probability of the k-th class is P. k Then the Gini index is: , Given feature A, the dataset D is divided into two parts, D1 and D2. The Gini gain of this feature is:

[0045] Repeat the above process until the stopping condition is met (such as reaching the maximum depth, the number of node samples being less than the threshold, etc.).

[0046] (5) Integrated prediction Suppose we construct T decision trees {h1(x), h2(x), h3(x), ..., h T Given T trees (x), collect the prediction results from all T trees, use majority voting, and the final prediction result is the class with the most votes:

[0047] Where I(·) is the indicator function.

[0048] Step 4: Enhance interpretability Step 4.1: SHAP The interpreter calculates the SHAP value of the sample, and the specific process is as follows: Feature combination traversal: Consider all possible combinations of feature subsets; Marginal contribution calculation: For each feature, calculate its marginal contribution when added to any subset of features, in order to measure the marginal impact of the feature on the model's prediction results.

[0049] Contribution-weighted average: The SHAP value for each feature is calculated using the following formula:

[0050] In the formula: For the set of all features, For features not included Feature subset, For the feature subset The predicted value below, Among all possible permutations of features, the feature The probability of appearing in the order of this subset.

[0051] The key features that have the greatest impact on pollution source identification are identified by calculating SHAP values, which serve as the basis for the source tracing conclusions.

[0052] Step 4.2: RAG+LLM Retrieval Enhancement Generation (RAG), as a knowledge enhancement module, retrieves scientific evidence related to the characteristics of heavy metal pollution sources from the literature database; Large Language Model (LLM), as a generative model, transforms the features identified by SHAP and the retrieved literature into readable explanations.

[0053] (1) RAG preparation Before conducting a literature search, the technical components of RAG must be configured to lay the groundwork for subsequent feature retrieval and interpretation generation. The core is to determine the search tools, generation model, and literature data sources: Search tools: LangChain is used as the search framework, combined with the Chroma vector database as the search tool.

[0054] Literature data: A literature database in the field of heavy metal pollution source tracing was pre-constructed, including published journal articles, research reports, standards and specifications.

[0055] Generative model: Llama 3.1 was selected as the LLM generative model.

[0056] (2) RAG search Once the model identifies a pollution source, the system automatically extracts key features (such as heavy metal elements, isotope ratios, and pollution source types) as search terms, performs semantic retrieval in the literature database, and uses vector similarity matching to return 3-5 documents most relevant to the current source tracing results.

[0057] (3) LLM generation interpretation The output of the PSO-RF model, the key feature SHAP value, the retrieved literature abstracts, and the background knowledge of pollution sources are used to construct structured prompt words. These are then input into the large language model Llama 3.1, which performs integrated natural language generation, including feature interpretation, literature verification, and hypothesis generation, to produce an explanation about the source of heavy metal pollution in rivers and lakes.

[0058] Those skilled in the art will understand that, unless otherwise defined, all terms used herein (including technical and scientific terms) have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains. It should also be understood that terms such as those defined in general dictionaries should be understood to have the same meaning as in the context of the prior art, and should not be interpreted in an idealized or overly formal sense unless defined as herein.

[0059] Based on the above-described preferred embodiments of the present invention, and through the foregoing description, those skilled in the art can make various changes and modifications without departing from the inventive concept. The technical scope of this invention is not limited to the contents of the specification, but must be determined according to the scope of the claims.

Claims

1. A method for tracing and interpreting heavy metal sources based on machine learning, characterized in that, Includes the following steps: Step 1: Obtain monitoring data of pollution source samples; Step 2: Identify the feature fingerprint database Step 2.1: Standardization: Z-score standardization is used to eliminate differences in dimensions and magnitudes; Step 2.2: Feature selection: The Boruta method is used to remove noisy features that are irrelevant to the pollution source classification, and the first-level feature set A is obtained; Step 2.3: Recursive optimization screening: The recursive feature elimination method RF-RFE based on random forest is used to recursively screen the first-level feature set A to obtain the second-level optimal feature subset B; Step 3: Construct the PSO-RF model Step 3.1: Use the second-level optimal feature subset B obtained in Step 2.3 as the model input matrix X. B The pollution source type is used as the output label Y to divide the training set and the test set; Step 3.2: Use the Particle Swarm Optimization (PSO) algorithm to globally optimize the hyperparameters of the Random Forest (RF). Step 3.3: Construct a random forest model based on the optimal hyperparameters, train multiple decision trees through Bootstrap sampling and random feature selection, and integrate voting to output the pollution source classification results; Step 4: Enhance model interpretability Step 4.1: Use the SHAP method to calculate the marginal contribution of each feature to the prediction results, identify the key source-tracing features in the pollution source apportionment process, and provide global and local interpretability for the model; Step 4.2: Combine RAG with the large language model to transform the model output into a natural language etymological explanation.

2. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, Step 1 specifically involves: acquiring monitoring data of potential pollution source samples within the study area, determining the content of heavy metal elements in the pollution sources using inductively coupled plasma mass spectrometry (ICP-MS), determining the stable isotope ratios using multi-receiver inductively coupled plasma mass spectrometry (MC-ICP-MS), removing outliers from the data, and constructing a pollutant fingerprint spectral library.

3. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, The specific process of step 2.1 is as follows: The heavy metal element content and isotope ratio data show significant differences in dimensions and numerical ranges. By performing Z-score standardization on the heavy metal element content and isotope ratio data, all features are transformed to a unified scale with a mean of 0 and a standard deviation of 1. The Z-score standardization calculation formula is as follows: , In the formula: i is the row, j is the column, and Z is the column. ij It is the standardized expression value, X ij It is the original value, μ j σ is the mean of the data in the j-th column. j It is the standard deviation of the data in column j; Mean: , Standard deviation: , In the formula: q is the number of pollution source samples.

4. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, The specific process described in section 2.2 is as follows: First, an initial random forest model is constructed. The input is the original feature matrix Z and the label Y. The original feature matrix Z has a dimension of q×p, where q is the number of pollution source samples and p is the number of variables, including the content of heavy metal elements and the ratio of stable isotopes. The label Y is the type of pollution source. A set of shadow features with no real relationship to the label vector is generated by randomly shuffling the original features. Then, the importance of the original features and the shadow features is compared. If the importance of the original features is significantly higher than the maximum importance of all shadow features, it is marked as "important". If it is lower, it is marked as "irrelevant". Otherwise, it is marked as "pending". Then, in each iteration, "irrelevant" features are removed, and the random forest model is reconstructed based on the remaining features and evaluated repeatedly until all features are clearly classified or the maximum number of iterations is reached; finally, the first-level feature set A is output.

5. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, The specific process of step 2.3 is as follows: First, using the first-level feature set A as input, a random forest model is trained using all features. The contribution of each feature to the classification performance is evaluated through the feature weights output by the model, and the feature with the smallest contribution is identified. Then, based on the importance of the features, remove the feature with the lowest importance in the current feature set each time, or remove features in batches by rounding down to 10% of the current number of features. In each iteration, the remaining feature set is used to repeat the above training, evaluation and removal steps until the feature set is reduced to the preset minimum size or the specified number of iterations is reached. Finally, the feature subset obtained from the last iteration is determined as the second-level optimal feature subset B.

6. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, The specific process of step 3.2 is as follows: Step 3.21 Initialize the particle swarm Randomly generate a particle swarm, with each particle containing hyperparameters of the RF model; Set the particle swarm size N and the maximum number of iterations G. max Inertia weight w, learning factors c1 and c2; Within the defined hyperparameter search space, initialize the particle's position and velocity; Calculate the initial fitness value for each particle: For each combination of hyperparameters of the random forest represented by a particle, the fitness value is calculated using the K-fold cross-validation method. The dataset is divided into K mutually exclusive subsets. One subset is selected as the validation set, and the remaining subsets are used as the training set. A random forest model is built based on the training set, and predictions are made on the validation set. The precision and recall of each class are calculated based on the prediction results. The F1-score is then calculated, and the average of the F1-scores obtained from the K cross-validations is taken as the fitness function value of the particle. Accuracy: , Recall rate: , F1 score: , , The particle's fitness function value: , In the formula: TP represents a correct prediction and is predicted to be of that category; FP represents a prediction of that category but an actual category other than that; FN represents an actual category but is predicted to be of another category; C represents the number of pollution source categories; F1 C It is the F1-score for Category C pollution sources; F1 k It is the F1-score of the k-th cross-validation; Initialize the individual optimal position and the global optimal position; Step 3.22 Update the particle's velocity and position according to the update formula of the PSO algorithm: Speed ​​updates: , Location update: , in, and Let represent the velocity and position of the nth particle in the g-th iteration, respectively, and w be the inertial weight. and It is a learning factor. It represents the optimal position of an individual particle from the nth particle to the gth iteration. It represents the globally optimal position of the entire particle swarm up to the g-th iteration. and It is a random number between [0,1]. Step 3.23 Fitness Assessment The fitness value of each particle is calculated based on the fitness function; Step 3.24 Update the optimal value If the current particle's fitness value is better than its historical best value, then update the individual's best position; If the current particle's fitness value is better than the global optimum, then update the global optimum position; Step 3.25 Iterative Optimization Repeat steps 3.22 to 3.24 until the preset maximum number of iterations is reached or the minimum difference in fitness values ​​between two iterations is reached. Output the position of the globally optimal particle, which is the optimal combination of hyperparameters for the random forest.

7. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, The specific process of step 3.3 is as follows: Step 3.31 Parameter Setting Random forests consist of multiple decision trees, each trained on a subset of the dataset sampled by Bootstrap. When splitting nodes, they randomly select some features for optimal splitting and finally output the results through majority voting or average regression. Its hyperparameters include: n_estimators: Number of decision trees; max_depth: The maximum depth of the tree; min_samples_split: controls the minimum number of samples when splitting a node in the tree; min_samples_leaf: Minimum number of samples in a leaf node; max_features: The maximum number of features to consider during each split; Step 3.32 Bootstrap Sampling to Construct Training Subset From the original training set, multiple training subsets are constructed using the Bootstrap sampling method, which serve as the training data for each decision tree; Random sampling with replacement is performed on the original training set to extract M samples, forming a new training subset containing M samples. Because sampling with replacement is used, some samples are not selected. These unselected samples are called out-of-bag samples. Outside-bag samples are used for internal validation of the model; Step 3.33 Random Feature Selection When training a single decision tree for each training subset obtained by Bootstrap sampling, instead of using all features, randomly select y features from x features, where y < x. For classification tasks, take , and then select features for splitting among these y features; Step 3.34 Constructing the decision tree Based on the above random "sample subset + feature subset", a single decision tree is constructed, and the construction of each tree follows the following principles: Build an unpruned decision tree, where individual trees are intentionally overfitted, and subsequent ensemble will offset the overfitting. The splitting criterion uses the Gini index. The sample set of the current node is dataset D, which has R classes. The proportion of samples in class r is P. r Then the Gini index is: , Given a feature E in feature subset B, if dataset D is divided into two parts D1 and D2, then the Gini gain of that feature is: , Repeat steps 3.32-3.34 until the stopping conditions are met; the stopping conditions include: reaching the maximum tree depth, the number of node samples being less than the minimum number of split samples, the number of leaf node samples being less than the minimum number of leaf node samples, the current node samples belonging to the same category, or the node being unable to continue to be effectively split. Step 3.35 Integrated Prediction Suppose we construct T decision trees, collect the prediction results from all T trees, and use majority voting to determine the final prediction result as the class with the most votes: , In the formula: H(α) is the predicted category of the final ensemble model for input α. It is an indicator function, h t (α) is the prediction result of the t-th decision tree for the input α, T is the number of decision trees, and Y is the label of the pollution source type.

8. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, The specific process of step 4.1 is as follows: Feature combination traversal: Consider all possible combinations of feature subsets; Marginal contribution calculation: For each feature, calculate its marginal contribution when added to any subset of features, in order to measure the marginal impact of the feature on the model's prediction results; Contribution-weighted average: The SHAP value for each feature is calculated using the following formula: , In the formula: B is the optimal feature subset. It is a subset of features that does not contain feature u. In the feature subset The predicted value below, It is the probability that feature u appears in the subset S among all possible permutations of features; The key features that have the greatest impact on pollution source identification are identified by calculating SHAP values, which serve as the basis for the source tracing conclusions.

9. The method for tracing and interpreting heavy metal sources based on machine learning according to claim 1, characterized in that, The specific process of step 4.2 is as follows: First, based on the LangChain framework and the Chroma vector database, a literature library for tracing the source of heavy metal pollution is pre-constructed, containing journal articles, research reports, and standard specifications, and Llama 3.1 is selected as the generative model; after the PSO-RF model identifies the pollution source type, the system automatically extracts key features as search terms, performs semantic retrieval in the literature library, and provides the 3-5 most relevant literature evidences; finally, the output results of the PSO-RF model, the key feature SHAP value, and the retrieved literature are constructed into structured prompt words, and the large language model generates a natural language form of source tracing explanation.