Water pollution detection method based on environment multi-dimensional information ensemble learning
By using XGBoost integrated learning algorithm and SPBO hyperparameter optimization algorithm in water pollutant detection, combined with multi-dimensional environmental information, the problem of insufficient detection accuracy and adaptability in the existing technology is solved, and high-precision and efficient water pollutant detection is achieved .
Patent Information
- Application Number
- CN202410974025.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-19
- Publication Date
- 2024-12-03
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
The existing water pollutant detection methods have shortcomings in detection time, detection accuracy and environmental adaptability, especially in complex water quality environments, and there are problems such as overfitting.
Using an environmental multidimensional information ensemble learning method, combined with XGBoost integrated learning algorithm and SPBO hyperparameter optimization algorithm, a SPBO-XGBoost model is established, and a variety of feature data is trained to optimize hyperparameters to improve the generalization ability and detection accuracy of the model.
It realizes high-precision detection of water pollutant concentrations in complex water quality environments, improves the cross-environmental fitness and generalization capabilities of the model, reduces the amount of calculation, and provides an efficient and accurate water quality detection solution.
Smart Images

Figure CN119066946A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of water quality detection, and in particular to a water pollution detection method based on environmental multi-dimensional information integrated learning. Background Art
[0002] Rapid, accurate and comprehensive monitoring of water pollutants is a key link in water management. How to quickly and accurately detect pollutants in water is a key issue to be studied in the field of water resources and water environment. Traditional water pollutant detection methods mainly rely on chemical analysis and biological detection methods. Although these methods can provide relatively accurate detection results, they usually require a long detection time, complex operating procedures and expensive detection equipment.
[0003] In the prior art, common water pollutant detection methods include physical methods, chemical methods and biological methods. Physical methods include membrane filtration technology and spectroscopy technology, chemical methods include titration and electrochemical analysis, and biological methods include biosensor technology. These methods all have certain limitations in practical applications. For example, physical methods have high requirements for equipment, chemical methods have a long detection cycle and are prone to secondary pollution, and biological methods are easily affected by environmental factors, resulting in unstable detection results.
[0004] With the development of big data and machine learning technology, data-driven methods are gradually applied to the field of water pollutant detection. This type of method collects water sample-related data and combines it with machine learning algorithms to detect and predict water pollutants in real time. However, traditional machine learning methods such as decision trees and support vector machines often show certain limitations when dealing with high-dimensional data and nonlinear relationships, and it is difficult to meet the requirements of high-precision detection. The current water pollutant detection methods based on deep learning are highly data-dependent and have high computing resource requirements. When faced with complex water environments, diverse water pollutants, and many features, there are problems such as low detection real-time performance and efficiency, poor accuracy, difficulty in accurately selecting the objective function, and poor cross-environment adaptability and generalization ability of water pollutant detection models, and there may be overfitting.
[0005] In short, the existing water pollutant detection methods still have some shortcomings in terms of detection time, detection accuracy and environmental adaptability. Therefore, there is an urgent need for a new high-performance and high-accuracy water pollutant detection method that can involve multiple features and process the classification and regression problem of water quality monitoring data based on multi-dimensional environmental information to meet the needs of practical applications. Summary of the invention
[0006] In order to overcome the shortcomings of the existing methods, the present invention provides a high-performance and high-accuracy water pollution detection method based on environmental multi-dimensional information integrated learning. When detecting water pollutants, environmental multi-dimensional information is involved, the cross-environment adaptability of the model is improved, the efficiency of hyperparameter optimization is improved, the model is simplified while the generalization ability is improved, and high-precision detection of pollutant concentrations can be achieved in complex water quality environments.
[0007] In order to solve the above technical problems, the present invention provides the following technical solutions:
[0008] A water pollution detection method based on environmental multi-dimensional information integrated learning, which measures multiple characteristics of water samples to obtain environmental multi-dimensional information, sets the initial hyperparameters of an XGBoost integrated learning model, and performs training to establish a basic model; sets the value space of the hyperparameters, defines an evaluation function, and uses an SPBO algorithm to iteratively update the hyperparameter population to obtain an optimal hyperparameter group; uses the optimal hyperparameter group optimized by SPBO to train an XGBoost model to obtain an SPBO-XGBoost model, obtains multiple characteristic data of water samples and inputs them into the SPBO-XGBoost model to detect the content of water pollutants.
[0009] Further, the method comprises the following steps:
[0010] Step 1: Get sample data
[0011] Measure water samples to obtain water quality data, including excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen, turbidity and other multi-dimensional environmental information, perform data preprocessing and establish water pollutant concentration labels to prepare data sets for model training and testing;
[0012] Step 2: Build the XGBoost base model
[0013] Set the initial model hyperparameters, including learning rate, tree depth, subsampling ratio, column sampling ratio, and regularization parameters, to build a basic model. Assuming that the given data set consists of n samples and m features, the XGBoost model integrates K decision trees, i.e., K iterations. For each water sample i, F i Indicates the corresponding characteristics, such as excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen and turbidity, etc., corresponding to the actual value of water pollutant concentration c i , the data set is represented by D = {F i ,c i}(|D|=n,F i ∈R m ,c i ∈R), calculate the water pollutant concentration prediction result c of the model i , expressed as:
[0014]
[0015]
[0016] in represents a tree structure space set, q is the structure of the tree, and samples can be mapped to corresponding leaf nodes. q(F) is used to determine which leaf node a piece of data falls into, and the predicted value of the leaf node of the tree is f k (F i ) represents the regression value of all samples at the node, and each tree f k Each has a corresponding independent tree structure q and weight w, T represents the total number of leaf nodes in the tree, and each leaf node j, j∈{1,2,...,T} has its corresponding value, that is, weight w j ;
[0017] The XGBoost algorithm uses an objective function to regulate the learning process. When the reduction of the objective function becomes limited, the learning process terminates. The objective function contains a loss function term and a regular term. The objective function is expressed as follows:
[0018]
[0019] Where n represents the number of samples, and the loss function term It measures the difference between the model prediction and the actual observation, describing how well the model fits the training data; is a regularization term that penalizes complexity cost and prevents overfitting, λ,γ are regularization hyperparameters, and ||w j || 2 Represents the square of the corresponding value on each leaf node. The goal of XGBoost is to minimize the objective function and obtain the optimal model by iteratively optimizing the loss function and regularization term;
[0020] Each tree is constructed by minimizing the objective function. The construction of the tree is completed in an iterative process. The newly added tree is trained from the previous tree and the residual in the predicted value is updated. The objective function is traversed over n samples and iterated k times as shown in formula (4). In each iteration step k, in order to optimize the function, the tree f that minimizes the objective function is found. k , using only the first-order derivative cannot guarantee that the global optimal solution is found, so the second-order Taylor expansion is used to estimate, and finally the constant term is eliminated, and the traversal on the sample is rewritten as the traversal on the leaf node j, and the approximate formula of the objective function is obtained (5);
[0021]
[0022]
[0023] in and are the first and second order derivatives of the loss function, I j is all the sample data in leaf node j. At this time, find the minimum value of the objective function and set its first-order derivative to zero, as shown in formula (6), and solve formula (7), that is, when w j The value is When , the objective function reaches its minimum value.
[0024]
[0025]
[0026] Substituting formula (7) into formula (5), the optimal objective function value is:
[0027]
[0028] In order to find the best split point, the decision tree is constructed using a greedy algorithm. Each time, an attempt is made to add a split to an existing leaf. By iteratively traversing all leaf nodes and calculating the gain, it is determined whether the split is the best. For a specific split scheme, the gain is calculated as follows:
[0029]
[0030] in and are the scores of the left and right subtrees respectively, is the score before splitting, γ is the complexity cost introduced by adding a new leaf node, and the larger the Gain value, the better;
[0031] The leaf nodes are segmented using the greedy algorithm, and the structure of the decision tree is measured using the optimal objective function value. After all trees are constructed, the final prediction value is the sum of all tree prediction values, as shown in formula (1), completing the establishment of the XGBoost basic model.
[0032] Step 3: SPBO Optimize Hyperparameters
[0033] Given the hyperparameters to be optimized and the value space of each hyperparameter, use SPBO to search for the most suitable hyperparameters in the given hyperparameter value space, initialize the hyperparameter population, assign an initial value to each hyperparameter, and each group of assigned hyperparameters constitutes a hyperparameter group. A hyperparameter group is regarded as an individual in the hyperparameter population; define an evaluation function, use each hyperparameter group to train the XGBoost model, and return the performance index (such as mean square error) on the validation set, and use the evaluation function to evaluate the performance of each hyperparameter group; obtain the performance index of each hyperparameter group, and use the SPBO algorithm to divide the hyperparameter groups in the population into four categories according to the performance index: optimal, suboptimal, general and random boost;
[0034] Step 4: Train the XGBoost model to detect water pollutants
[0035] The optimal hyperparameter group optimized by SPBO was used to train the XGBoost model to obtain the SPBO-XG Boost model, and cross-validation was used to evaluate the performance of the model under the optimal hyperparameters to ensure that the obtained model has good generalization ability and avoid overfitting and underfitting. The excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen and turbidity of the water samples to be tested were measured and input into the SPBO-XGBoost model. The output is the concentration of water pollutants in the water sample. By using SPBO for hyperparameter adjustment, the predictive ability of the XGBoost model has been enhanced, thereby achieving faster calculation and more accurate prediction of water pollutant concentrations.
[0036] Furthermore, in step 3, different operators are designed for different types, and the mathematical calculation process is as follows:
[0037] 3.1) Optimal hyperparameter set
[0038]
[0039] Among them, a is randomly set to 1 or 2, rand() is a random number between [0,1], and t is the current iteration number. Represents the value of the optimal hyperparameter group in the current hyperparameter population, is the value of the jth hyperparameter group randomly selected in the current iteration;
[0040] 3.2) Suboptimal hyperparameter set
[0041]
[0042]
[0043] in, is the value of the i-th hyperparameter group in the current hyperparameter population, is the value of the hyperparameter group corresponding to the average performance index, that is, the mean vector of all individuals in the population, and rand() is a random number between [0,1];
[0044] 3.3) General hyperparameter group
[0045]
[0046] in, is the value of the hyperparameter group corresponding to the average performance index, that is, the mean vector of all individuals in the population, and rand() is a random number between [0,1];
[0047] 3.4) Randomly improve the hyperparameter group
[0048]
[0049] in, and are the values corresponding to the hyperparameter groups with the highest and lowest performance indicators in the hyperparameter population, respectively. rand() is a random number between [0,1];
[0050] According to the strategy of the above SPBO algorithm, the hyperparameter population is updated, and a new candidate hyperparameter group is generated and its performance index is evaluated. The above process is repeated until the preset number of iterations is reached or the performance of the hyperparameter group is no longer significantly improved, and the optimal hyperparameter group is obtained.
[0051] The technical concept of the present invention is as follows: the present invention couples the Student Psychology Optimization (SPBO) algorithm with the Extreme Gradient Boosting (XGBoost) algorithm. XGBoost is an integrated learning algorithm that combines a group of decision trees into a strong learner. The performance of the overall model is improved by integrating multiple decision tree models. Each decision tree learns the relationship between the characteristics of the data and the labels, and makes corresponding predictions. The final prediction result is the weighted sum of the prediction results of all decision trees. In this way, multi-dimensional information of the environment is involved in model training and prediction, thereby improving the generalization ability and prediction performance of the model. The model is continuously optimized using the gradient boosting algorithm, a new decision tree is generated in each round of iteration, the prediction result of each tree is used to fit the residual of the prediction result of the previous tree, and the model is updated to reduce the residual error, thereby gradually improving the performance of the overall model.
[0052] Since the performance of the XGBoost model is highly dependent on the value of the hyperparameters, it is necessary to tune it to achieve the best performance. SPBO is a meta-heuristic intelligent optimization algorithm that simulates student psychology. The present invention optimizes the hyperparameters in the XGBoost model, such as learning rate, tree depth, subsampling ratio, regularization parameters, etc., through the SPBO algorithm to achieve the search for the most suitable hyperparameters. The SPBO algorithm identifies the optimal hyperparameters by evaluating the performance of the XGBoost model on different hyperparameters in the search space, and then uses the hyperparameters optimized by SPBO and the training data set to train the XGBoost model to establish the SPBO-XG Boost model. By using SPBO for hyperparameter tuning, the predictive ability of the XGBoost model is enhanced, thereby achieving faster calculation and more accurate prediction of water pollutant concentrations.
[0053] The beneficial technical effects of the present invention are mainly manifested in: 1. The XGBoost ensemble learning algorithm is used to establish a model. Compared with traditional methods, the present invention is more suitable for data sets with more features, and can involve multi-dimensional environmental information in water pollutant detection, thereby improving the cross-environment adaptability of the model. The model is made simpler to prevent overfitting, reduce the amount of calculation and improve the generalization ability. 2. The SPBO algorithm is coupled with the XGBoost algorithm, and the model hyperparameters are tuned using SPBO to ensure that the model of each specific data set achieves the best performance, which can not only improve the hyperparameter tuning efficiency, computational stability and prediction accuracy, but also reduce time consumption, providing an efficient and accurate water quality detection solution. The present invention has significant advantages in feature selection, model training and hyperparameter optimization, and can achieve high-precision detection of pollutant concentrations in complex water quality environments, providing important support for environmental monitoring and pollution control. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] Figure 1 Build a flowchart for the XGBoost model.
[0055] Figure 2 Flowchart for SPBO algorithm calculation.
[0056] Figure 3 This is the flow chart of the SPBO-XGBoost model. Specific implementation plan
[0057] In order to make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the present invention is further described in detail below in conjunction with specific embodiments and drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the operation process of the present invention, but are not the only operation of the present invention.
[0058] Reference Figure 1 to Figure 3A water pollution detection method based on environmental multi-dimensional information integrated learning, which measures multiple characteristics of water samples to obtain environmental multi-dimensional information, sets the initial hyperparameters of the XGBoost integrated learning model, and trains it to establish a basic model; sets the value space of the hyperparameters, defines the evaluation function, and uses the SPBO algorithm to iteratively update the hyperparameter population to obtain the optimal hyperparameter group; uses the optimal hyperparameter group optimized by SPBO to train the XGBoost model to obtain the SPBO-XGBoost model, obtains multiple characteristic data of water samples and inputs them into the SPBO-XGBoost model to detect the content of water pollutants.
[0059] Further, the method comprises the following steps:
[0060] Step 1: Get sample data
[0061] Measure water samples to obtain water quality data, including excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen, turbidity and other multi-dimensional environmental information, perform data preprocessing and establish water pollutant concentration labels to prepare data sets for model training and testing;
[0062] Step 2: Build the XGBoost base model
[0063] Set the initial model hyperparameters, including learning rate, tree depth, subsampling ratio, column sampling ratio, and regularization parameters, to build a basic model. Assuming that the given data set consists of n samples and m features, the XGBoost model integrates K decision trees, i.e., K iterations. For each water sample i, F i Indicates the corresponding characteristics, such as excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen and turbidity, etc., corresponding to the actual value of water pollutant concentration c i , the data set is represented by D = {F i ,c i}(|D|=n,F i ∈R m ,c i ∈R), calculate the water pollutant concentration prediction result c of the model i , expressed as:
[0064]
[0065]
[0066] in represents a tree structure space set, q is the structure of the tree, and samples can be mapped to corresponding leaf nodes. q(F) is used to determine which leaf node a piece of data falls into, and the predicted value of the leaf node of the tree is f k (F i) represents the regression value of all samples at the node, and each tree f k Each has a corresponding independent tree structure q and weight w, T represents the total number of leaf nodes in the tree, and each leaf node j, j∈{1,2,...,T} has its corresponding value, that is, weight w j ;
[0067] The XGBoost algorithm uses an objective function to regulate the learning process. When the reduction of the objective function becomes limited, the learning process terminates. The objective function contains a loss function term and a regular term. The objective function is expressed as follows:
[0068]
[0069] Where n represents the number of samples, and the loss function term It measures the difference between the model prediction and the actual observation, describing how well the model fits the training data; is a regularization term that penalizes complexity cost and prevents overfitting, λ,γ are regularization hyperparameters, and ||w j || 2 Represents the square of the corresponding value on each leaf node. The goal of XGBoost is to minimize the objective function and obtain the optimal model by iteratively optimizing the loss function and regularization term;
[0070] Each tree is constructed by minimizing the objective function. The construction of the tree is completed in an iterative process. The newly added tree is trained from the previous tree and the residual in the predicted value is updated. The objective function is traversed over n samples and iterated k times as shown in formula (4). In each iteration step k, in order to optimize the function, the tree f that minimizes the objective function is found. k , using only the first-order derivative cannot guarantee that the global optimal solution is found, so the second-order Taylor expansion is used to estimate, and finally the constant term is eliminated, and the traversal on the sample is rewritten as the traversal on the leaf node j, and the approximate formula of the objective function is obtained (5);
[0071]
[0072]
[0073] in and are the first and second order derivatives of the loss function, I j is all the sample data in leaf node j. At this time, find the minimum value of the objective function and set its first-order derivative to zero, as shown in formula (6), and solve formula (7), that is, when w j The value is When , the objective function reaches its minimum value.
[0074]
[0075]
[0076] Substituting formula (7) into formula (5), the optimal objective function value is:
[0077]
[0078] In order to find the best split point, the decision tree is constructed using a greedy algorithm. Each time, an attempt is made to add a split to an existing leaf. By iteratively traversing all leaf nodes and calculating the gain, it is determined whether the split is the best. For a specific split scheme, the gain is calculated as follows:
[0079]
[0080] in and are the scores of the left and right subtrees respectively, is the score before splitting, γ is the complexity cost introduced by adding a new leaf node, and the larger the Gain value, the better;
[0081] The leaf nodes are segmented using the greedy algorithm, and the structure of the decision tree is measured using the optimal objective function value. After all trees are constructed, the final prediction value is the sum of all tree prediction values, as shown in formula (1), completing the establishment of the XGBoost basic model.
[0082] Step 3: SPBO Optimize Hyperparameters
[0083] Given the hyperparameters to be optimized and the value space of each hyperparameter, use SPBO to search for the most suitable hyperparameters in the given hyperparameter value space, initialize the hyperparameter population, assign an initial value to each hyperparameter, and each group of assigned hyperparameters constitutes a hyperparameter group. A hyperparameter group is regarded as an individual in the hyperparameter population; define an evaluation function, use each hyperparameter group to train the XGBoost model, and return the performance index (such as mean square error) on the validation set, and use the evaluation function to evaluate the performance of each hyperparameter group; obtain the performance index of each hyperparameter group, and use the SPBO algorithm to divide the hyperparameter groups in the population into four categories according to the performance index: optimal, suboptimal, general and random boost;
[0084] In step 3, different operators are designed for different types, and the mathematical calculation process is as follows:
[0085] 3.1) Optimal hyperparameter set
[0086]
[0087] Among them, a is randomly set to 1 or 2, rand() is a random number between [0,1], and t is the current iteration number. Represents the value of the optimal hyperparameter group in the current hyperparameter population, is the value of the jth hyperparameter group randomly selected in the current iteration;
[0088] 3.2) Suboptimal hyperparameter set
[0089]
[0090]
[0091] in, is the value of the i-th hyperparameter group in the current hyperparameter population, is the value of the hyperparameter group corresponding to the average performance index, that is, the mean vector of all individuals in the population, and rand() is a random number between [0,1];
[0092] 3.3) General hyperparameter group
[0093]
[0094] in, is the value of the hyperparameter group corresponding to the average performance index, that is, the mean vector of all individuals in the population, and rand() is a random number between [0,1];
[0095] 3.4) Randomly improve the hyperparameter group
[0096]
[0097] in, and are the values corresponding to the hyperparameter groups with the highest and lowest performance indicators in the hyperparameter population, respectively. rand() is a random number between [0,1];
[0098] According to the strategy of the above SPBO algorithm, the hyperparameter population is updated, and a new candidate hyperparameter group is generated and its performance index is evaluated. The above process is repeated until the preset number of iterations is reached or the performance of the hyperparameter group is no longer significantly improved, and the optimal hyperparameter group is obtained.
[0099] Step 4: Train the XGBoost model to detect water pollutants
[0100] The optimal hyperparameter group optimized by SPBO was used to train the XGBoost model to obtain the SPBO-XG Boost model, and cross-validation was used to evaluate the performance of the model under the optimal hyperparameters to ensure that the obtained model has good generalization ability and avoid overfitting and underfitting. The excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen and turbidity of the water samples to be tested were measured and input into the SPBO-XGBoost model. The output is the concentration of water pollutants in the water sample. By using SPBO for hyperparameter adjustment, the predictive ability of the XGBoost model has been enhanced, thereby achieving faster calculation and more accurate prediction of water pollutant concentrations.
[0101] The performance of the XGBoost model used in the present invention depends largely on its hyperparameters, which are predefined and used to determine the learning process of the model. Correctly adjusting these hyperparameters is crucial to ensure the optimal performance of the model for each specific data set.
[0102] Based on this, in order to improve the performance of the XGBoost model used so that it can more accurately detect the pollutant content in water, the present invention introduces the SPBO algorithm, couples it with XGBoost, and identifies the optimal configuration by evaluating the performance of different configurations of the XGBoost algorithm in the hyperparameter value space. After obtaining the optimal hyperparameter group, the XGBoost model is trained using the training data set and the hyperparameters identified by the SPBO, and an SPBO-XGBoost model is established to obtain a water pollution detection method based on integrated learning of environmental multidimensional information.
[0103] Taking the detection of tryptophan content in water as an example, the specific implementation steps are:
[0104] Step 1: Prepare a set of tryptophan solutions with a concentration gradient, including 50 samples, measure the fluorescence intensity, temperature, and pH of each sample in the excitation band of 300-350nm and the emission band of 380-430nm, establish concentration labels, standardize all numerical data to the range of 0-1 to eliminate the dimension effect, and divide the obtained data into training samples (40) and test samples (10).
[0105] Step 2: Reference Figure 1 As shown in the XGBoost model construction flow chart, the initial hyperparameters of the XGBoost model are set, the tree depth δ is set to 3, the number of trees K is set to 2, the learning rate η is set to 0.1, the two regularization parameters are set to λ=1, γ=0, the subsample ratio σ is set to 1, and the loss function is selected as the logarithmic loss function logloss. The first-order derivative and second-order derivative of logloss are respectively
[0106] g i =ci -c i (29)
[0107] h i =c i *(1-c i ) (30)
[0108] Since this is the first tree, the initial value c i The value is assigned by the user, and the default value is set to 0.5. Next, refer to the above formula to calculate the first-order derivative and second-order derivative of the loss function logloss of each sample data, traverse all the values of the three features of all sample data as split points, and divide the sample into left node I at the root node L and right node I R Two sets, at this time G L , H L , G R and H R They are
[0109]
[0110]
[0111]
[0112]
[0113] Substitute the above formula (9) to calculate the corresponding gain values of all samples, and finally compare the Gain values under each splitting condition, and select the point with the largest Gain as the splitting point of the root node. At this time, the first layer of the tree is established, and because the depth of the tree is set to 3, it is necessary to continue splitting, and the two leaf nodes after the split are regarded as root nodes respectively. Repeat the above process until the depth of the tree reaches 3 and T leaf nodes are obtained. At this time, the weight w of each leaf node is calculated according to the above formula (7): j , the final leaf node value is weight w j Multiply the set learning rate by 0.1. At this point, the first tree is built.
[0114] The fitting process of the second tree is exactly the same as that of the first tree, except that c i Update, because we choose to use logloss as the loss function, the updated c i It can be expressed as
[0115]
[0116] Where f1(F i) is the value of a sample at the first leaf node. After the update is completed, the above process is repeated to complete the construction of the second tree. Since the number of trees K is set to 2, the XGBoost basic model is established.
[0117] Step 3: Set the hyperparameter ranges required for optimization as follows:
[0118]
[0119] The evaluation function is defined, and the mean square error (MSE) objective function is evaluated using K-fold cross validation. The entire data set is randomly divided into K subsets of equal size. Usually, K is 5 or 10. In this invention, K is 5, and each subset contains 10 samples. For each subset k (k ranges from 1 to 5), the kth subset is used as the validation set, and the other 4 subsets are used as training sets. The XGBoost model is trained on the training set. The trained model is used to make predictions on the validation set, and the mean square error (MSE) is calculated. The MSE of the 5 validations is averaged as the final performance indicator P of the model. i The calculation formula can be expressed as
[0120]
[0121] After each hyperparameter value space is given and the evaluation function is defined, SPBO is used to tune the hyperparameters according to step 3 above. The performance of each hyperparameter group is evaluated using the evaluation function, and the hyperparameter population is updated using the evaluation results. The iteration is completed when the maximum number of iterations is reached or the performance converges to a certain threshold. P is selected. i The hyperparameter group with the lowest value is the optimal hyperparameter group.
[0122] Step 4: After obtaining the optimal hyperparameter group after the SPBO algorithm iteration, the hyperparameters are brought into the XGBoost model described in step 2 above for training. Finally, a model consisting of multiple decision trees is obtained, and the relationship between fluorescence intensity, temperature, pH value and tryptophan concentration is established. The fluorescence intensity, pH value and temperature of the actual water sample in the excitation band of 300-350nm and the emission band of 380-430nm are subsequently measured and brought into the established SPBO-XGBoost model. The tryptophan concentration in the water sample can be calculated by formula (1).
[0123] The contents described in the embodiments of this specification are merely enumerations of implementation forms of the inventive concept and are for illustrative purposes only. The protection scope of the present invention should not be considered to be limited to the specific forms described in this embodiment, and the protection scope of the present invention also extends to equivalent technical means that can be thought of by ordinary technicians in this field based on the inventive concept.
Claims
1. A water pollution detection method based on integrated learning of environmental multi-dimensional information, It is characterized in that Measure multiple characteristics of water samples to obtain multi-dimensional environmental information, set the initial hyperparameters of the XGBoost ensemble learning model, and train it to establish a basic model; set the value space of the hyperparameters, define the evaluation function, and use the SPBO algorithm to iteratively update the hyperparameter population to obtain the optimal hyperparameter group; use the optimal hyperparameter group optimized by SPBO to train the XGBoost model to obtain the SPBO-XGBoost model, obtain the corresponding characteristic data of water samples, and input the SPBO-XGBoost model to detect the content of water pollutants.
2. The water pollution detection method based on environmental multi-dimensional information integrated learning as claimed in claim 1, It is characterized in that The method comprises the following steps: Step 1: Get sample data Measure water samples to obtain water quality data, including excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen and turbidity, perform data preprocessing and establish water pollutant concentration labels to prepare data sets for model training and testing; Step 2: Build the XGBoost base model Set the initial model hyperparameters, including learning rate, tree depth, subsampling ratio, column sampling ratio and regularization parameters, and build a basic model. Assuming that the given data set consists of n samples and m features, the XGBoost model integrates K decision trees, i.e., K iterations. For each water sample i, F i Indicates the corresponding characteristics, including excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen and turbidity, corresponding to the actual value of water pollutant concentration c i , the data set is represented by D = {F i ,c i }(|D|=n,F i ∈R m ,c i ∈R), calculate the water pollutant concentration prediction result c of the model i , expressed as: in represents a tree structure space set, q is the structure of the tree, and samples can be mapped to corresponding leaf nodes. q(F) is used to determine which leaf node a piece of data falls into, and the predicted value of the leaf node of the tree is f k (F i ) represents the regression value of all samples at the node, and each tree f k Each has a corresponding independent tree structure q and weight w, T represents the total number of leaf nodes in the tree, and each leaf node j, j∈{1,2,...,T} has its corresponding value, that is, weight w j ; The XGBoost algorithm uses an objective function to regulate the learning process. When the reduction of the objective function becomes limited, the learning process terminates. The objective function contains a loss function term and a regular term. The objective function is expressed as follows: Where n represents the number of samples, and the loss function term It measures the difference between the model prediction and the actual observation, describing how well the model fits the training data; is a regularization term that penalizes complexity cost and prevents overfitting, λ,γ are regularization hyperparameters, and ||w j || 2 Represents the square of the corresponding value on each leaf node. The goal of XGBoost is to minimize the objective function and obtain the optimal model by iteratively optimizing the loss function and regularization term; Each tree is constructed by minimizing the objective function. The construction of the tree is completed in an iterative process. The newly added tree is trained from the previous tree and the residual in the predicted value is updated. The objective function is traversed over n samples and iterated k times as shown in formula (4). In each iteration step k, in order to optimize the function, the tree f that minimizes the objective function is found. k , using only the first-order derivative cannot guarantee that the global optimal solution is found, so the second-order Taylor expansion is used to estimate, and finally the constant term is eliminated, and the traversal on the sample is rewritten as the traversal on the leaf node j, and the approximate formula of the objective function is obtained (5); in and are the first and second order derivatives of the loss function, I j is all the sample data in leaf node j. At this time, we find the minimum value of the objective function and set its first-order derivative to zero, as shown in formula (6). We can solve formula (7), that is, when w j The value is When , the objective function reaches its minimum value. Substituting formula (7) into formula (5), the optimal objective function value is: In order to find the best split point, the decision tree is constructed using a greedy algorithm. Each time, an attempt is made to add a split to an existing leaf. By iteratively traversing all leaf nodes, the gain is calculated to determine whether the split is the best. For a split scheme, the gain is calculated as follows: in and are the scores of the left and right subtrees respectively, is the score before splitting, γ is the complexity cost introduced by adding a new leaf node, and the larger the Gain value, the better; The leaf nodes are segmented using the greedy algorithm, and the structure of the decision tree is measured using the optimal objective function value. After all trees are constructed, the final prediction value is the sum of all tree prediction values, as shown in formula (1), completing the establishment of the XGBoost basic model. Step 3: SPBO Optimize Hyperparameters Given the hyperparameters to be optimized and the value space of each hyperparameter, use SPBO to search for the most suitable hyperparameters in the given hyperparameter value space; initialize the hyperparameter population, assign an initial value to each hyperparameter, and each group of assigned hyperparameters constitutes a hyperparameter group. A hyperparameter group is regarded as an individual in the hyperparameter population. Define the evaluation function, use each hyperparameter group to train the XGBoost model, and return the performance index on the validation set. Use the evaluation function to evaluate the performance of each hyperparameter group. Obtain the performance index of each hyperparameter group, and use the SPBO algorithm to divide the hyperparameter groups in the population into four categories according to the performance index: optimal, suboptimal, general, and random boost; Step 4: Train the XGBoost model to detect water pollutants The optimal hyperparameter group optimized by SPBO was used to train the XGBoost model to obtain the SPBO-XGBoost model, and cross-validation was used to evaluate the performance of the model under the optimal hyperparameters to ensure that the obtained model has good generalization ability and avoid overfitting and underfitting. The excitation wavelength, emission wavelength, fluorescence intensity, absorbance, conductivity, temperature, pH, dissolved oxygen and turbidity characteristics of the water samples to be tested were measured and input into the SPBO-XGBoost model. The output is the concentration of water pollutants in the water sample. By using SPBO for hyperparameter adjustment, the predictive ability of the XGBoost model has been enhanced, thereby achieving faster calculation and more accurate prediction of water pollutant concentrations.
3. The water pollution detection method based on environmental multi-dimensional information integrated learning as claimed in claim 2, It is characterized in that In step 2, different operators are designed for different types, and the mathematical calculation process is as follows: 3.1) Optimal hyperparameter set Among them, a is randomly set to 1 or 2, rand() is a random number between [0,1], and t is the current iteration number. Represents the value of the optimal hyperparameter group in the current hyperparameter population, is the value of the jth hyperparameter group randomly selected in the current iteration; 3.2) Suboptimal hyperparameter set in, is the value of the i-th hyperparameter group in the current hyperparameter population, is the value of the hyperparameter group corresponding to the average performance index, that is, the mean vector of all individuals in the population, and rand() is a random number between [0,1]; 3.3) General hyperparameter group in, is the value of the hyperparameter group corresponding to the average performance index, that is, the mean vector of all individuals in the population, and rand() is a random number between [0,1]; 3.4) Randomly improve the hyperparameter group in, and are the values corresponding to the hyperparameter groups with the highest and lowest performance indicators in the hyperparameter population, respectively. rand() is a random number between [0,1]; According to the strategy of the SPBO algorithm, the hyperparameter population is updated, and a new candidate hyperparameter group is generated and its performance index is evaluated. The above process is repeated until the preset number of iterations is reached or the performance of the hyperparameter group is no longer significantly improved, and the optimal hyperparameter group is obtained.
Citation Information
Cited By
Processing method and device of organic molecule maximum absorption peak prediction model
CN120183561A
