Method and system for analyzing content of heavy metal elements in soil based on XRF
By applying the trained heavy metal element detection model in the XRF spectrum data of soil samples, the problem of low detection accuracy of heavy metal content in soil in the prior art is solved, and higher detection accuracy and more accurate identification of element characteristic peaks are achieved.
Patent Information
- Application Number
- CN202411672454.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-03-18
AI Technical Summary
In the prior art, when using X-ray fluorescence analysis method to detect heavy metal content in soil, there is noise interference, which leads to a decrease in the resolution of elemental characteristic X-rays and difficulty in identifying elemental characteristic peaks. Especially for heavy metal elements with lower content, the detection accuracy is low.
By collecting XRF spectrum data from soil samples, the tested heavy metal element detection model is used to determine the content of each target heavy metal element. The model is built on a preset machine learning model and is trained using data feature samples related to the content of heavy metal elements in standard soil samples.
It effectively improves the detection accuracy of the content of each target heavy metal element in the soil sample, reduces the influence of noise interference, and improves the identification accuracy of element characteristic peaks.
Smart Images

Figure CN119643611A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to a method and system for analyzing the content of heavy metal elements in soil based on XRF. Background Art
[0002] X-ray fluorescence analysis, also known as X-ray fluorescence analysis (XRF) technology, is a method of using primary X-ray photons or other microscopic particles to excite atoms in the sample to be tested, causing them to produce fluorescence (i.e., secondary X-rays) to analyze material composition and study chemical forms.
[0003] In the prior art, when using XRF technology for detection and analysis, X-rays will have certain noise interference, which can easily reduce the instrument's resolution of element characteristic X-rays and interfere with the identification of element characteristic peaks. In particular, for certain low-content heavy metal elements in soil, the noise interference of X-rays may cause the characteristic spectrum lines of the elements to be annihilated, resulting in low accuracy of the detected heavy metal content. Summary of the invention
[0004] In view of the above-mentioned deficiencies in the prior art, the purpose of the present invention is to provide a method and system for analyzing the content of heavy metal elements in soil based on XRF, aiming to solve the problem of low accuracy in detecting the content of heavy metals in soil using X-ray fluorescence analysis method in the prior art.
[0005] In order to achieve the above object, the first aspect of the present invention provides a method for analyzing the content of heavy metal elements in soil based on XRF, comprising:
[0006] Collect XRF spectrum data of the soil sample to be tested;
[0007] Based on the XRF spectrum data, determining several target heavy metal elements contained in the soil sample to be tested;
[0008] The XRF spectrum data is detected using a trained heavy metal element detection model to determine the detection results of the content of each target heavy metal element. The trained heavy metal element detection model is constructed based on a preset machine learning model and is trained using data feature samples related to the heavy metal element content in standard soil samples.
[0009] Optionally, determining several target heavy metal elements contained in the soil sample to be tested based on the XRF spectrum data includes:
[0010] Based on the XRF spectrum data, all characteristic peaks are determined;
[0011] Based on the characteristic peaks, determining the types of all heavy metal elements contained in the soil sample to be tested;
[0012] Based on the types of all the heavy metal elements, several target heavy metal elements contained in the soil sample to be tested are determined.
[0013] Optionally, the detecting the XRF spectrum data using the trained heavy metal element detection model to determine the detection result of each target heavy metal element content includes:
[0014] Extracting data features related to the heavy metal element content in the XRF spectrum data corresponding to all the target heavy metal elements to obtain a target feature vector;
[0015] The target feature vector is processed using a trained heavy metal element detection model to determine the detection result of each target heavy metal element content.
[0016] Optionally, before determining all characteristic peaks based on the XRF spectrum data, the method further comprises:
[0017] The XRF spectrum data is preprocessed to update the XRF spectrum data, wherein the preprocessing operation includes at least one of denoising and removing XRF spectrum data that is irrelevant to any of the target heavy metal elements.
[0018] Optionally, the preset machine learning algorithm is an extreme gradient boosting algorithm, and the training process of the heavy metal element detection model includes:
[0019] Collecting standard values of heavy metal element contents in standard soil samples, and data characteristic samples related to the heavy metal element contents in the standard soil samples;
[0020] Based on the extreme gradient boosting algorithm, the objective function corresponding to the decision tree is constructed;
[0021] The Boosting algorithm is used to determine the best split point of the decision tree corresponding to the objective function, and iterative training is performed with the goal of maximizing the information gain of the objective function to obtain the optimal objective function;
[0022] Based on the optimal objective function, a trained heavy metal element detection model is obtained.
[0023] Optionally, constructing an objective function corresponding to the decision tree based on the extreme gradient boosting algorithm includes:
[0024] Construct a loss function based on the predicted value of each decision tree and the corresponding standard value;
[0025] A regularization term is constructed based on the weight of the decision tree, the weight of the leaf nodes in the decision tree, and the preset depth of the decision tree;
[0026] Based on the loss function and the regularization term, an objective function corresponding to the decision tree is constructed using the extreme gradient boosting algorithm.
[0027] Optionally, the using of a Boosting algorithm to determine an optimal splitting point of a decision tree corresponding to the objective function, performing iterative training with the goal of maximizing the information gain of the objective function, and obtaining an optimal objective function includes:
[0028] Using the greedy algorithm, traverse all the partition points of the data feature samples corresponding to the decision tree, and solve the information gain of each partition point respectively;
[0029] Determine the optimal splitting point of the decision tree corresponding to the objective function according to the size of the information gain and the preset information gain threshold;
[0030] Based on the optimal splitting point, iterative training is performed with the goal of maximizing the information gain of the objective function to obtain an optimal objective function.
[0031] A second aspect of the present invention provides a system for analyzing the content of heavy metal elements in soil based on XRF, the system comprising:
[0032] An information acquisition module is used to collect XRF spectrum data of the soil sample to be tested;
[0033] A heavy metal element detection module, used to determine a number of target heavy metal elements contained in the soil sample to be tested based on the XRF spectrum data;
[0034] The heavy metal element content detection module is used to detect the XRF spectrum data using a trained heavy metal element detection model to determine the detection results of the content of each target heavy metal element. The trained heavy metal element detection model is constructed based on a preset machine learning model and is trained using data feature samples related to the heavy metal element content in standard soil samples.
[0035] A third aspect of the present invention provides an intelligent terminal, which includes a memory, a processor, and a program for analyzing the content of heavy metal elements in soil based on XRF, which is stored in the memory and can be run on the processor. When the program for analyzing the content of heavy metal elements in soil based on XRF is executed by the processor, any step of the method for analyzing the content of heavy metal elements in soil based on XRF is implemented.
[0036] A fourth aspect of the present invention provides a computer-readable storage medium, on which is stored a program for analyzing the content of heavy metal elements in soil based on XRF. When the program for analyzing the content of heavy metal elements in soil based on XRF is executed by a processor, any step of the method for analyzing the content of heavy metal elements in soil based on XRF is implemented.
[0037] Compared with the prior art, the beneficial effects of this solution are as follows:
[0038] The present invention utilizes XRF technology to collect XRF spectrum data of target soil samples, and based on the relationship between XRF spectrum data and characteristic peaks, and the standard curve relationship between element mass fractions in standard samples and their characteristic peak intensities, utilizes a machine learning model to construct and train a trained heavy metal element detection model, and utilizes the trained heavy metal element detection model to process the target feature vector, which can effectively improve the detection accuracy of each target heavy metal element content in the target soil sample. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0040] Figure 1 This is a flow chart of the method for analyzing the content of heavy metal elements in soil based on XRF of the present invention;
[0041] Figure 2 This is a comparison chart of the predicted value and the actual value of the Zn element in the standard soil sample of the present invention;
[0042] Figure 3 This is a comparison diagram of the predicted value and the actual value of the Cu element in the standard soil sample of the present invention;
[0043] Figure 4 This is a comparison diagram of the predicted value and the actual value of the Cr element in the standard soil sample of the present invention;
[0044] Figure 5 This is a schematic diagram of the system module for analyzing the content of heavy metal elements in soil based on XRF of the present invention;
[0045] Figure 6 It is a schematic diagram of the structure of the intelligent terminal of the present invention. DETAILED DESCRIPTION
[0046] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present invention. However, it should be clear to those skilled in the art that the present invention may be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present invention.
[0047] It should be understood that when used in this specification and the appended claims, the term "comprising" indicates the presence of described features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0048] It should also be understood that the terms used in the present specification are only for the purpose of describing specific embodiments and are not intended to limit the present invention. As used in the present specification and the appended claims, unless the context clearly indicates otherwise, the singular forms "a", "an" and "the" are intended to include plural forms.
[0049] It should be further understood that the term "and / or" used in the present description and the appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0050] The following is a clear and complete description of the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0051] In the following description, many specific details are set forth to facilitate a full understanding of the present invention, but the present invention may also be implemented in other ways different from those described herein, and those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0052] In view of the low accuracy of the X-ray fluorescence analysis method in the prior art for detecting the heavy metal content in soil, the present invention proposes a method for analyzing the content of heavy metal elements in soil based on XRF, which is deployed on electronic devices such as computers and servers and applied to the scene of measuring the content of heavy metals in soil, targeting the situation achieved by the X-ray fluorescence analysis method. Specifically, Figure 1 As shown, the steps of the method in this embodiment include:
[0053] Step S100: collecting XRF spectrum data of the soil sample to be tested;
[0054] Specifically, according to the research purpose and the characteristics of the soil sample to be tested, an XRF analyzer with appropriate resolution is selected to measure the XRF spectrum data of the soil sample to be tested, ensuring that the resolution of the XRF spectrum can accurately reflect the instrument's ability to resolve adjacent elements, accurately identify elements, and reduce interference between elements.
[0055] Step S200: determining a number of target heavy metal elements contained in the soil sample to be tested based on the XRF spectrum data;
[0056] Specifically, since the fluorescent X-rays of different elements have their own specific wavelengths or energy characteristics, the types of elements present in the sample can be determined by measuring the wavelength or energy of the fluorescent X-rays. In the XRF spectrum, each element corresponds to one or more characteristic spectral lines, and the position and shape of these spectral lines can be used to identify the elements. Since the intensity of the characteristic X-rays of an element is proportional to the content of the element in the sample. Therefore, by measuring the intensity of the fluorescent X-rays and performing appropriate calibration and correction, the content of the element in the sample can be calculated. In the XRF spectrum, the intensity of the characteristic spectral lines of an element reflects the content of the element in the sample, and the higher the intensity, the greater the content.
[0057] Step S300: Use a trained heavy metal element detection model to detect the XRF spectrum data to determine the detection results of the content of each target heavy metal element. The trained heavy metal element detection model is constructed based on a preset machine learning model and is trained using data feature samples related to the heavy metal element content in standard soil samples.
[0058] Specifically, a machine learning model capable of measuring the content of various heavy metal elements in soil is selected to construct a heavy metal element detection model, and the data feature samples related to the content of heavy metal elements in the standard soil sample and the true values of the content of various heavy metal elements in the standard soil sample are used to train the heavy metal element detection model to obtain a trained heavy metal element detection model. Then, the pre-processed XRF spectrum data is used as input data, and each target heavy metal element is detected respectively using the trained heavy metal element detection model, so as to determine the detection result of the content of each target heavy metal element. Among them, the data feature samples related to the content of heavy metal elements include the physicochemical properties of the sample (such as the pH value of the soil, the organic matter content, etc.), certain spectral feature parameters in the XRF measurement, etc., which can be used to reflect the corresponding element content information, and the spectral feature parameters include but are not limited to the position of the characteristic peak, the intensity of the characteristic peak (such as peak height or peak area), the half-peak width and the shape of the characteristic spectral line, etc.
[0059] In this embodiment, XRF technology is used to collect XRF spectrum data of the target soil sample, and according to the proportional relationship between the characteristics of the spectral lines in the XRF spectrum and the content of heavy metal elements in the target soil sample, the target feature vector is processed using a trained heavy metal element detection model, which can effectively improve the detection accuracy of each target heavy metal element content in the target soil sample.
[0060] In a preferred embodiment, the step S200 of determining several target heavy metal elements contained in the soil sample to be tested based on the XRF spectrum data includes:
[0061] Step S210: determining all characteristic peaks based on the XRF spectrum data;
[0062] Step S220: determining the types of all heavy metal elements contained in the soil sample to be tested based on the characteristic peaks;
[0063] Step S230: Based on the types of all the heavy metal elements, determine a number of target heavy metal elements contained in the soil sample to be tested.
[0064] Specifically, for the pre-processed XRF spectrum data, the X-ray fluorescence generated by different elements has a specific energy (or wavelength). The energy (or wavelength) distribution of various X-ray fluorescence is detected by the detector, and the peak in the energy spectrum (or wavelength spectrum) is the characteristic peak of the element in the soil sample. Due to the different atomic structures of different elements, the X-ray fluorescence energy generated by their electronic transitions is also different, so different elements will have characteristic peaks at different energy positions. Therefore, this embodiment determines the types of all heavy metal elements contained in the soil sample to be tested based on the parameters that can be used to reflect the corresponding element content information, such as the position of the characteristic peak, the intensity of the characteristic peak (such as peak height or peak area), the half-peak width and the shape of the characteristic spectrum line. Then, in combination with the research purpose, some or all of the heavy metal elements contained in the soil sample to be tested are determined as target heavy metal elements.
[0065] Furthermore, within a certain range, the higher the mass fraction of the element in the soil to be tested, the greater the intensity of the characteristic peak it produces. Therefore, by constructing a standard curve (i.e., a calibration curve) between the mass fraction of the element in the standard sample and its characteristic peak intensity, the mass fraction of the element in the soil sample can be calculated based on the characteristic peak intensity of various target heavy metal elements in the soil sample to be tested.
[0066] Further, before determining all characteristic peaks based on the XRF spectrum data, the method includes:
[0067] The XRF spectrum data is preprocessed to update the XRF spectrum data, wherein the preprocessing operation includes at least one of denoising and removing XRF spectrum data that is irrelevant to any of the target heavy metal elements.
[0068] Specifically, due to factors such as the noise of the XRF instrument itself and the scattering generated by the matrix of the sample (other components in the soil except the target heavy metal), there is often background noise in the collected XRF spectrum. In order to improve the accuracy of the analysis results of the target heavy metal element content in the soil, this embodiment performs smoothing and denoising on the collected XRF spectrum data; at the same time, since the collected XRF spectrum contains the characteristic spectral lines of all elements in the soil sample to be tested, the characteristic spectral lines corresponding to elements other than the target heavy metal element may be superimposed on the characteristic spectral lines of the target heavy metal element, which may easily lead to a higher measurement result of the content of the target heavy metal element and affect the accuracy of the measurement result. Therefore, this embodiment further removes the XRF spectrum data that is not related to any target heavy metal element in the XRF spectrum data, that is, removes other background signals in the soil sample to be tested except the fluorescent X-ray signal generated by the target element to avoid the influence of the characteristic spectral lines of other elements.
[0069] In a preferred embodiment, the step S300 of detecting the XRF spectrum data using the trained heavy metal element detection model to determine the detection result of each target heavy metal element content includes:
[0070] Step S310: extracting data features related to the heavy metal element content in the XRF spectrum data corresponding to all the target heavy metal elements to obtain a target feature vector;
[0071] Step S320: using the trained heavy metal element detection model to process the target feature vector to determine the detection result of each target heavy metal element content.
[0072] Specifically, extract the data features related to the content of heavy metal elements in the XRF spectrum data corresponding to all target heavy metal elements, including but not limited to the position of the characteristic peak, the intensity of the characteristic peak (such as peak height or peak area), the half-peak width and the shape of the characteristic spectrum line. If there is only one target heavy metal element, there is only one set of data features, so a target feature vector is constructed using the data features; if there are multiple target heavy metal elements, each target heavy metal element corresponds to a set of data features, so a target feature vector is constructed using the data features of all target heavy metal primary colors. Then, the target feature vector is used as the input data of the trained heavy metal element detection model, then based on the standard curve (i.e., calibration curve) between the mass fraction of the element and its characteristic peak intensity in the constructed standard sample, the mass fraction of the element in the target soil sample can be calculated based on the characteristic peak intensity of various target heavy metal elements in the soil sample to be tested, thereby determining the detection result of each target heavy metal element content according to the mass fraction.
[0073] For example, the relationship between the mass fraction of the target heavy metal element in the target soil sample and the X-ray fluorescence spectrum is expressed as:
[0074] w a =Q*(I a +β at *I Q )*(1+∑α at *w t )+b (1)
[0075] Among them, w a is the mass fraction of the target heavy metal element, w t is the mass fraction of the interfering element, Q is the slope of the standard curve, b is the intercept of the standard curve, I a is the X-ray fluorescence spectrum intensity of the measured target heavy metal element, β at is the overlapped line correction factor, I Q is the theoretical calculated intensity of overlapping spectral lines, α at is the influence coefficient of the interfering element on the measured target heavy metal element, the subscript a represents the index of the target heavy metal element, if there are multiple target heavy metal elements, a is used to distinguish different target heavy metal elements, and t represents the index of the interfering element. Among them, the interfering element refers to the non-target heavy metal element in the target soil sample.
[0076] In this embodiment, XRF technology is used to collect XRF spectrum data of the target soil sample, and based on the relationship between the XRF spectrum data and the characteristic peak, as well as the standard curve relationship between the mass fraction of the element in the standard sample and the intensity of its characteristic peak, a machine learning model is constructed and trained to obtain a trained heavy metal element detection model, and the trained heavy metal element detection model is used to process the target feature vector, which can effectively improve the detection accuracy of each target heavy metal element content in the target soil sample.
[0077] In a preferred embodiment, the preset machine learning algorithm is an extreme gradient boosting algorithm, and the training process of the heavy metal element detection model in step S300 includes:
[0078] Step S330: collecting standard values of heavy metal element contents in standard soil samples, and data feature samples related to the heavy metal element contents in the standard soil samples;
[0079] Specifically, the standard values of heavy metal content in standard soil samples are collected as label data; data feature samples related to the heavy metal content in standard soil samples are collected, wherein the data feature samples related to the heavy metal content include the physical and chemical properties of the samples (such as the pH value of the soil, the organic matter content, etc.), certain spectral feature parameters in XRF measurement, etc. that can be used to reflect the corresponding element content information, and the spectral feature parameters include but are not limited to the position of the characteristic peak, the intensity of the characteristic peak (such as peak height or peak area), half-peak width and the shape of the characteristic spectral line, etc. The training data set is constructed using the labeled standard values and data feature samples.
[0080] Step S340: constructing an objective function corresponding to the decision tree based on the extreme gradient boosting algorithm;
[0081] Specifically, the eXtreme GradientBoosting (XGBoost) model is an ensemble learning algorithm based on GradientBoosting DecisionTrees (GBDT), which is widely used in the field of machine learning. The core idea of XGBoost is to combine multiple weak classifiers (usually decision trees) into a strong classifier. Each decision tree is trained based on the residual of the previous tree, that is, the feature selection of the decision tree based on XGBoost is not random. The next decision tree will consider the prediction error of the data features of the previous decision tree, so that the features with larger errors and data feature samples will receive more attention in the subsequent decision tree generation, and the residuals will be gradually reduced by continuously iterating and optimizing the loss function. At the same time, the model reduces the risk of overfitting by controlling the complexity of the tree and the regularization term. XGBoost uses the second-order Taylor expansion in the optimization of the loss function, which can improve the accuracy of the algorithm when dealing with nonlinear problems.
[0082] Based on this, this embodiment constructs a loss function based on the predicted value and the corresponding standard value of each decision tree; constructs a regularization term based on the weight of the decision tree, the weight of the leaf node in the decision tree and the depth of the preset decision tree; based on the loss function and the regularization term, the objective function corresponding to the decision tree is constructed using the extreme gradient boosting algorithm. Specifically, for each decision tree, there is a predicted value (usually the output value of the leaf node) and the corresponding actual standard value. The loss function is constructed using the predicted value and the labeled standard value to measure the difference between the model predicted value and the actual standard value. The choice of the loss function depends on the specific task type (such as classification or regression). At the same time, this embodiment introduces a regularization term in the objective function to control the complexity of the model and prevent overfitting. The regularization term includes two parts: the weight of the decision tree (i.e., the complexity of each tree) and the weight of the leaf node in the decision tree. The weight of each decision tree can be determined by limiting the depth of the decision tree, the number of leaf nodes, or the number of split nodes. Then, this embodiment uses the extreme gradient boosting algorithm to construct the objective function corresponding to the decision tree based on the loss function and the regularization term to guide the training process of the model.
[0083] Step S350: using the Boosting algorithm to determine the best split point of the decision tree corresponding to the objective function, and performing iterative training with the goal of maximizing the information gain of the objective function to obtain the optimal objective function;
[0084] In the training process, the purpose is to use the extreme gradient boosting algorithm to iteratively construct a decision tree, add a new decision tree each time to minimize the loss of the objective function, and optimize the objective function by iterative optimization to obtain the optimal objective function. Specifically, this embodiment uses a greedy algorithm to traverse all the partition points of the data feature samples corresponding to the decision tree, and solve the information gain of each partition point respectively; according to the size of the information gain and the preset information gain threshold, the optimal splitting point of the decision tree corresponding to the objective function is determined; based on the optimal splitting point, iterative training is performed with the goal of maximizing the information gain of the objective function to obtain the optimal objective function. Specifically, it includes: for the current node to be split, select one from all the data features in the training data set as a candidate split feature; for the candidate split feature, use a greedy algorithm to traverse all the partition points of the data feature samples corresponding to the decision tree, and for each candidate partition point, divide the training data set into two parts (left child node and right child node), and calculate the information entropy of the two parts of the data set respectively; according to the weights of the two parts of the data set (that is, the number ratio of data points), calculate the weighted conditional entropy; and calculate the difference between the information entropy and the conditional entropy to obtain the information gain, so as to reflect the degree of improvement of the purity of the data set after splitting through the partition point. Then, the information gain of all candidate partitioning points is compared, and by setting the information gain threshold, the partitioning points with too small information gain are screened out to reduce the complexity of the model and prevent overfitting. The node with the largest information gain among the leaf nodes is selected as the partitioning point, and the partitioning point that exceeds the preset threshold is used as the best splitting point for the current node. Finally, based on the best splitting point, the current node is split into two child nodes, and the data set of the child nodes is updated. The steps of determining the best splitting point of the node and splitting are repeated, and the structure and parameters of the decision tree are continuously adjusted to obtain the optimal decision tree model, thereby maximizing the information gain of the objective function, that is, minimizing the sum of the loss of the loss function and the regularization term.
[0085] As an illustrative example, for a training data set G = {x i ,y i}, x i represents the i-th data feature sample, there are n data feature samples in total, y i Represents x i The corresponding true value.
[0086] Assume that the initial objective function of the lth decision tree is:
[0087]
[0088] in, Indicates that the first l decision trees jointly analyze the i-th data feature sample x i The predicted value, f l (x i) represents the predicted value of the lth decision tree for the i-th data feature sample; Represents the loss function of the decision tree model, which is used to reflect the difference between the predicted value obtained by each decision tree and its true value. In this example, the loss function uses the cross entropy loss function:
[0089]
[0090] Among them, Ω(f l ) is the regularization term of the lth decision tree. In this example, L2 regularization is used, μ is used to control the weight ratio of the decision tree, T is the depth of the current decision tree, λ is used to control the weight of the regularization term in the entire loss function, w is the weight parameter, which obeys the Gaussian distribution and is taken as the weight of the current leaf node. Then the regularization term Ω can be expressed as:
[0091]
[0092] According to the principle of Boosting algorithm, the lth decision tree is used for data feature sample x i The predicted value of is the sum of the predicted values of all decision trees before this tree and the predicted value of this decision tree, that is:
[0093]
[0094] According to Taylor's formula, we can expand the above formula:
[0095]
[0096] In the XGBoost model, f l (x i ) with w is the weight of the leaf node mentioned above, q(x i ) is the data feature sample x i The leaf node of the decision tree, g i and h i Respectively right The first and second derivatives of are used to obtain the weight of the leaf node. Let j = q(x i ), G j =∑ i∈j g i , H j =∑ i∈j h i , while removing the constant term, we get:
[0097]
[0098] By solving the above formula, we can calculate the weight w of the leaf nodej , structural score And information gain Gain, which is used to reflect the importance of the feature, that is, the more important the feature, the greater the information gain.
[0099] Then, using the greedy algorithm, traverse all the partitioning points of all features, calculate the information gain of all the partitioning points, and take the node with the largest information gain as the partitioning point; at the same time, set an information gain threshold, and only when the information gain of the partitioning point is greater than the information gain threshold will it continue to split, otherwise a new decision tree will be created. For the splitting of the left and right subtrees of the decision tree, in this example, the gradient (first-order derivative) and the sum of the second-order derivatives of the samples on the left and right subtrees are calculated respectively, so as to calculate the information gain Gain, that is:
[0100]
[0101] Where G represents the sum of the gradients of all data feature samples on a certain node or data feature before and after the split; H represents the sum of the second-order derivatives of all samples on the feature before and after the split; G L Represents the gradient (first-order derivative) of the sample on the left subtree; G R represents the gradient (first-order derivative) of the sample on the right subtree; H L represents the sum of the second-order derivatives of the samples on the left subtree; H R Represents the sum of the second-order derivatives of the samples on the right subtree.
[0102] In this example, the weights and information gains of each leaf node of the decision tree are obtained by calculating the objective function, and the loss is minimized by solving the maximum information gain of the objective function, thereby obtaining the optimal XRF-machine learning model. At the same time, the accuracy of the model prediction results is improved by performing a second-order Taylor formula expansion on the loss function, and the introduction of a regular term can effectively avoid overfitting.
[0103] Step S360: Based on the optimal objective function, a trained heavy metal element detection model is obtained.
[0104] Specifically, according to step S350, the objective function is calculated to obtain the weights and information gains of each leaf node of the decision tree, and the loss is minimized by solving the maximum information gain of the objective function to obtain the optimal objective function, thereby obtaining the optimal XRF-machine learning model, that is, the trained heavy metal element detection model. The XRF-machine learning model based on the gradient boosting machine constructed in this embodiment can effectively improve the accuracy of detecting heavy metal content in soil using XRF technology.
[0105] Next, field soil samples were collected, and the model established by the method of the present invention was used to analyze the content of heavy metal elements in the field soil. Inductively coupled plasma atomic emission spectroscopy (ICP-AES) was used to quantitatively analyze the corresponding elements in the soil samples, and the heavy metal content in the field soil measured by XRF was compared, which effectively verified the accuracy of the prediction of the method of the present invention in field soil samples. The details are as follows:
[0106] The standard mass fractions of various heavy metal elements contained in 20 standard soil samples were collected. Table 1 shows the content (mg / kg) of heavy metal elements Cr, Cu and Zn in each soil standard sample.
[0107] Table 1:
[0108]
[0109]
[0110] The XRF spectrum data of each standard soil sample was collected using an XRF analyzer that can analyze FU elements, constant (%) - trace (ppm); the precision (major and minor elements) RSD% is between 0.1-1.0.
[0111] Then, the XRF-machine learning model was constructed for the three heavy metal elements Zn, Cu and Cr in the standard soil samples to obtain the Gradient Boosting Machines (GBM) model. The determination coefficient, relative analysis error, mean absolute error and root mean square error were used to evaluate the model performance to compare the errors between the predicted values and the true values.
[0112] The following is based on the true value x of the mth standard soil sample m , the predicted value y predicted by the XRF-machine learning model constructed by the present invention m , the average of the predicted values The construction methods of each evaluation function are introduced respectively.
[0113] Coefficient of determination R 2 As a core evaluation index in statistics, it is also called goodness of fit or coefficient of determination. It evaluates the degree of fit of the model as a whole and provides a standard for quantifying the degree of fit of the model to the data. 2 The coefficient range is between 0 and 1, and its value reflects the degree of fit between the model prediction value and the actual observation value. 2 The closer it is to 1, the higher the degree of model fit and the better the model performance.2 The expression is:
[0114]
[0115] The root mean square error (RMSE) evaluates the degree of fit of the model from a numerical perspective by quantifying the deviation between the model's predicted value and the true value. RMSE is more sensitive to larger error values and can capture predicted values with large errors. However, this characteristic also makes RMSE more sensitive to outliers (i.e., observations that deviate significantly from the normal range). The smaller the RMSE value, the better the performance of the model. The expression of RMSE is:
[0116]
[0117] The average difference value BIAS reflects the average difference between the true value and the predicted value. When BIAS is a positive number, it means that the true value is greater than the predicted value from the overall prediction result. Conversely, when BIAS is a negative number, it means that the overall predicted value is greater than the true value. At the same time, when the BIAS value is closer to 0, it means that the difference between the true value and the predicted value is smaller. The expression of BIAS is:
[0118]
[0119] The analysis of relative analysis error RPD is based on SD and RMSE. SD stands for standard deviation, which refers to the square root of the arithmetic mean of the difference between the data value and the mean value, reflecting the degree of dispersion of a data set. The smaller the SD, the more concentrated the element content measured by XRF, that is, the closer the element content in each soil sample. When RPD < 1.4, the constructed model is considered unreliable; when 1.4 < RPD < 2.0, the constructed model is considered relatively reliable; when RPD > 2.0, the model is considered to have a high degree of accuracy and a good degree of fit, and can be used for predictive analysis. The expression of RPD is:
[0120]
[0121] The prediction results of the XRF-machine learning model constructed in the present invention for the heavy metal elements Zn, Cu, and Cr in the standard soil samples are shown in Table 2.
[0122] Table 2:
[0123]
[0124] Figure 2-4The following are the comparison diagrams of the predicted values and true values of Zn, Cu and Cr elements in standard soil samples, where the red solid line indicates the fitting degree of the predicted results of the GBM model to the true values of heavy metals in standard soil samples, the green dotted line indicates the line where the true value and the predicted value are 1:1, the gray area is the 95% confidence interval, and the black dots indicate the sample points. The horizontal axis indicates the true value, and the vertical axis indicates the predicted value, both in mg / kg.
[0125] From Table 2 and Figure 2-Figure 4 It can be seen that for the Zn element in Table 2, from the perspective of R2, the GBM model R2 value is 0.858, which has good accuracy, but is affected by the prediction error of samples in the high value area, resulting in a low R2 value for the overall model. The performance of RPD is similar to that of R2, and the RPD value of the GBM model is 2.65, which performs well. From the perspective of BIAS, the BIAS value of the GBM model is positive, indicating that its prediction results are generally smaller than its true value, and the prediction is generally small, which is shown in the figure as being biased below the standard line. From the image, the sample points with prediction errors in the GBM model all fall below the standard line. Therefore, when modeling field soil samples, a GBM model with relatively excellent prediction ability is selected for modeling.
[0126] For the Cu element in Table 2, from the perspective of R2, the R2 value of the GBM model is close to 0.9, and the prediction ability is good; from the perspective of BIAS, the BIAS value of the model is greater than 0, indicating that the average difference of the predicted values of this model is smaller than the true value. From the perspective of RPD, the RPD value is between 2 and 3. The modeling method for Cu performs very well in the low value area, but the predicted value deviates from the true value in the high value area. There is a sample with a true value exceeding 0.03, which shows obvious deviation in modeling. GBM deviates in the direction smaller than the true value. This may be because the GBM modeling method is based on a decision tree, which makes the data in the high value area underestimated during modeling, resulting in a smaller predicted value.
[0127] For the Cr element in Table 2, GBM performs well, and the degree of fit between its predicted value and the true value is very high. From the perspective of R2, the R2 of the GBM model is greater than 0.95, which shows that the GBM model predicts the data very well. For the BIAS value, the GBM model is negative, and the prediction results are on average larger. In the GBM model, the predicted value of this sample fits the true value very well, and this sample appears in the concentrated distribution area of sample values, which shows that the prediction error has a greater impact on the model evaluation.
[0128] Furthermore, the effectiveness of the method of the present invention in predicting the content of heavy metal elements in field soil samples was verified, specifically comprising: collecting 23 field soil samples, air-drying the obtained soil samples and passing them through a 100-mesh sieve, dividing the sieved soil samples into two parts, performing ICP-AES analysis on one part, and performing XRF analysis on the other part.
[0129] For the ICP-AES determination of a field soil sample, the instruments used include: ICP-AES analyzer, analytical balance, polytetrafluoroethylene crucible, hot plate, 25ml volumetric flask, polyethylene vial; reagents include: high-purity hydrogen fluoride HF, nitric acid HNO3 and perchloric acid HClO4, as well as high-purity argon. The experimental steps include: weighing 0.1g of soil sample that has passed through a 100-mesh sieve and placing it in a polytetrafluoroethylene crucible, and the experiment is carried out in a fume hood; placing the polytetrafluoroethylene containing the soil sample on the hot plate, adding 7ml HF and 1ml HNO3 along the wall of the crucible, heating to 250℃, digesting to nearly dry, stopping heating, and letting it stand to cool. Add 5ml HF, continue heating and digesting until almost dry, and let it stand to cool; add 2ml HClO4 along the crucible wall, heat and digest until no white smoke comes out; add 1ml aqua regia (1:1 HNO3), heat and digest until the solution is yellow, transparent and without residue; after cooling, transfer the digested solution to a 25ml GG-17 volumetric flask to make up the volume, filter and transfer to a polyethylene vial for standby use; prepare standard solutions of each element, the correlation coefficient of its standard curve is above 0.99, and the concentration range is similar to the element content in the soil sample. After ICP-AES determination, the contents of three heavy metals Cr, Cu, and Zn were measured, as shown in Table 3.
[0130] Table 3:
[0131]
[0132]
[0133] For the XRF determination of another field soil sample, the experimental instruments include: X-ray fluorescence spectrometer, powder tablet press, analytical balance, plastic ring; the materials include: field soil sample sieved through 100 mesh. The experimental steps include: edging the soil sample with a plastic ring and pressing it into a thin sheet with a thickness greater than 7 mm on the powder tablet press; establishing a measurement method according to the instrument operation procedure of the XRF analyzer, and measuring the above 23 soil samples in turn by the XRF analyzer to derive the analysis results. The XRF spectrum data obtained by the XRF analyzer is used to predict the Cr, Cu, and Zn contents in the spectrum data, as shown in Table 4.
[0134] Table 4:
[0135]
[0136] Comparative analysis of the results of ICP-AES and XRF measurements shows that for the Cr element, the prediction results of the GBM model fit the ICP measurement values very well, with R2 of 0.867 and RPD of 2.74, indicating that the model has excellent prediction ability and the credibility of the GBM model is high. Therefore, the prediction results of the GBM model can be accepted as the final prediction results. Analysis of the XRF-machine learning model of the Cu element shows that the prediction results of the GBM model fit the ICP measurement values very well, with R2 of 0.843 and RPD of 2.19, indicating that the model has good quantitative prediction ability. Analysis of the XRF-machine learning model of the Zn element shows that the prediction effect of the GBM model is general, with R2 of 0.798 and RPD of 1.19, indicating that quantitative prediction can be performed. In summary, the GBM model constructed by the present invention significantly improves the accuracy of XRF quantitative analysis and realizes accurate quantitative prediction of Cr, Cu, and Zn.
[0137] like Figure 5 As shown, corresponding to the above-mentioned method for analyzing the content of heavy metal elements in soil based on XRF, an embodiment of the present invention further provides a system for analyzing the content of heavy metal elements in soil based on XRF, and the above-mentioned system for analyzing the content of heavy metal elements in soil based on XRF includes:
[0138] The information acquisition module 510 is used to collect XRF spectrum data of the soil sample to be tested;
[0139] A heavy metal element detection module 520 is used to determine a number of target heavy metal elements contained in the soil sample to be tested based on the XRF spectrum data;
[0140] The heavy metal element content detection module 530 is used to detect the XRF spectrum data using a trained heavy metal element detection model to determine the detection results of the content of each target heavy metal element. The trained heavy metal element detection model is constructed based on a preset machine learning model and is trained using data feature samples related to the heavy metal element content in standard soil samples.
[0141] Specifically, in this embodiment, the specific functions of the system for analyzing the content of heavy metal elements in soil based on XRF can also refer to the corresponding description in the method for analyzing the content of heavy metal elements in soil based on XRF, which will not be repeated here.
[0142] Based on the above embodiments, the present invention further provides an intelligent terminal, whose principle block diagram can be shown as follows: Figure 6As shown. The above-mentioned intelligent terminal includes a processor, a memory, a network interface and a display screen connected through a system bus. Among them, the processor of the intelligent terminal is used to provide computing and control capabilities. The memory of the intelligent terminal includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a program for analyzing the content of heavy metal elements in soil based on XRF. The internal memory provides an environment for the operation of the operating system in the non-volatile storage medium and the program based on XRF analysis of the content of heavy metal elements in soil. The network interface of the intelligent terminal is used to communicate with an external terminal through a network connection. When the program for analyzing the content of heavy metal elements in soil based on XRF is executed by the processor, the steps of any one of the above-mentioned methods for analyzing the content of heavy metal elements in soil based on XRF are implemented. The display screen of the intelligent terminal can be a liquid crystal display screen or an electronic ink display screen.
[0143] Those skilled in the art will understand that Figure 6 The principle block diagram shown in the figure is only a block diagram of a partial structure related to the scheme of the present invention, and does not constitute a limitation on the smart terminal to which the scheme of the present invention is applied. The specific smart terminal may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0144] In one embodiment, a smart terminal is provided, which includes a memory, a processor, and a program for analyzing the content of heavy metal elements in soil based on XRF, which is stored in the memory and can be run on the processor. When the program for analyzing the content of heavy metal elements in soil based on XRF is executed by the processor, the steps of any one of the methods for analyzing the content of heavy metal elements in soil based on XRF provided in an embodiment of the present invention are implemented.
[0145] An embodiment of the present invention also provides a computer-readable storage medium, on which is stored a program for analyzing the content of heavy metal elements in soil based on XRF. When the program for analyzing the content of heavy metal elements in soil based on XRF is executed by a processor, the steps of any one of the methods for analyzing the content of heavy metal elements in soil based on XRF provided in an embodiment of the present invention are implemented.
[0146] It should be understood that the serial numbers of the steps in the above embodiments do not imply a sequence of execution, and the execution sequence of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present invention.
[0147] Those skilled in the art can clearly understand that, for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the above-mentioned device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of the present invention. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.
[0148] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0149] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.
[0150] In the embodiments provided by the present invention, it should be understood that the disclosed apparatus / terminal equipment and method can be implemented in other ways. For example, the apparatus / terminal equipment embodiments described above are only illustrative, for example, the division of the above modules or units is only a logical function division, and in actual implementation, other division methods can be used, for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed.
[0151] The embodiments described above are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, it should be understood by those skilled in the art that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features therein may be replaced by equivalents. However, these modifications or replacements do not deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.
Claims
1. A method for analyzing the content of heavy metal elements in soil based on XRF, characterized in that: The following steps are involved: Collect XRF spectrum data of the soil sample to be tested; Based on the XRF spectrum data, determining several target heavy metal elements contained in the soil sample to be tested; The XRF spectrum data is detected using a trained heavy metal element detection model to determine the detection results of the content of each target heavy metal element. The trained heavy metal element detection model is constructed based on a preset machine learning model and is trained using data feature samples related to the heavy metal element content in standard soil samples.
2. The method for analyzing the content of heavy metal elements in soil based on XRF according to claim 1, characterized in that: Determining several target heavy metal elements contained in the soil sample to be tested based on the XRF spectrum data includes: Based on the XRF spectrum data, all characteristic peaks are determined; Based on the characteristic peaks, determining the types of all heavy metal elements contained in the soil sample to be tested; Based on the types of all the heavy metal elements, several target heavy metal elements contained in the soil sample to be tested are determined.
3. The method for analyzing the content of heavy metal elements in soil based on XRF according to claim 1, characterized in that: The method of using the trained heavy metal element detection model to detect the XRF spectrum data to determine the detection result of each target heavy metal element content includes: Extracting data features related to the heavy metal element content in the XRF spectrum data corresponding to all the target heavy metal elements to obtain a target feature vector; The target feature vector is processed using a trained heavy metal element detection model to determine the detection result of each target heavy metal element content.
4. The method for analyzing the content of heavy metal elements in soil based on XRF according to claim 2, characterized in that: Before determining all characteristic peaks based on the XRF spectrum data, the method includes: The XRF spectrum data is preprocessed to update the XRF spectrum data, wherein the preprocessing operation includes at least one of denoising and removing XRF spectrum data that is irrelevant to any of the target heavy metal elements.
5. The method for analyzing the content of heavy metal elements in soil based on XRF according to claim 1, characterized in that: The preset machine learning algorithm is the extreme gradient boosting algorithm. The training process of the heavy metal element detection model includes: Collecting standard values of heavy metal element contents in standard soil samples, and data characteristic samples related to the heavy metal element contents in the standard soil samples; Based on the extreme gradient boosting algorithm, the objective function corresponding to the decision tree is constructed; The Boosting algorithm is used to determine the best split point of the decision tree corresponding to the objective function, and iterative training is performed with the goal of maximizing the information gain of the objective function to obtain the optimal objective function; Based on the optimal objective function, a trained heavy metal element detection model is obtained.
6. The method for analyzing the content of heavy metal elements in soil based on XRF according to claim 5, characterized in that: The objective function corresponding to the decision tree is constructed based on the extreme gradient boosting algorithm, including: Construct a loss function based on the predicted value of each decision tree and the corresponding standard value; A regularization term is constructed based on the weight of the decision tree, the weight of the leaf nodes in the decision tree, and the preset depth of the decision tree; Based on the loss function and the regularization term, an objective function corresponding to the decision tree is constructed using the extreme gradient boosting algorithm.
7. The method for analyzing the content of heavy metal elements in soil based on XRF according to claim 5, characterized in that: The Boosting algorithm is used to determine the best split point of the decision tree corresponding to the objective function, and iterative training is performed to maximize the information gain of the objective function to obtain the optimal objective function, including: Using the greedy algorithm, traverse all the partition points of the data feature samples corresponding to the decision tree, and solve the information gain of each partition point respectively; Determine the optimal splitting point of the decision tree corresponding to the objective function according to the size of the information gain and the preset information gain threshold; Based on the optimal splitting point, iterative training is performed with the goal of maximizing the information gain of the objective function to obtain an optimal objective function.
8. A system for analyzing the content of heavy metal elements in soil based on XRF, characterized in that: The system comprises: An information acquisition module is used to collect XRF spectrum data of the soil sample to be tested; A heavy metal element detection module, used to determine a number of target heavy metal elements contained in the soil sample to be tested based on the XRF spectrum data; The heavy metal element content detection module is used to detect the XRF spectrum data using a trained heavy metal element detection model to determine the detection results of the content of each target heavy metal element. The trained heavy metal element detection model is constructed based on a preset machine learning model and is trained using data feature samples related to the heavy metal element content in standard soil samples.
9. An intelligent terminal, characterized in that: The intelligent terminal includes a memory, a processor, and a program for analyzing the content of heavy metal elements in soil based on XRF, which is stored in the memory and can be run on the processor. When the program for analyzing the content of heavy metal elements in soil based on XRF is executed by the processor, the steps of the method for analyzing the content of heavy metal elements in soil based on XRF as described in any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a program for analyzing the content of heavy metal elements in soil based on XRF. When the program for analyzing the content of heavy metal elements in soil based on XRF is executed by a processor, the steps of the method for analyzing the content of heavy metal elements in soil based on XRF as described in any one of claims 1 to 7 are implemented.
Citation Information
Cited By
XRF metal detection and analysis method for soil heavy metal pollution
CN121167678A
An xrf metal detection analysis method for soil heavy metal pollution
CN121167678B