A method for measuring seawater nitrate concentration based on improved least squares method
Through the improved least squares method, the problem of spectral overlap interference and noise in seawater is solved, the accuracy and stability of seawater nitrate concentration measurement are improved, and fast and accurate measurement of seawater nitrate concentration is achieved.
Patent Information
- Application Number
- CN202410976960.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-22
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2044-07-22
AI Technical Summary
Existing spectroscopic methods face spectral overlap interference, non-Gaussian noise and multicollinearity problems when measuring nitrate concentration in seawater, resulting in unstable least squares estimation results and difficulty in accurately measuring nitrate concentration in seawater.
An improved least squares method was used to preprocess the absorbance difference data through a filtering algorithm, extract the characteristic wavelength with the highest weight, add a nitrate spectrum adjustment factor, train the model using the ten-fold cross-validation method, and optimize the cost function to improve the fitting of the model. and predictive ability.
The fitting ability and prediction accuracy of the model are significantly improved, the risk of over-fitting is reduced, the generalization ability of the model is enhanced, and seawater nitrate concentration can be measured more accurately.
Smart Images

Figure CN118549367B_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of rapid analysis of seawater quality by spectroscopy, and in particular to a method for measuring seawater nitrate concentration based on an improved least squares method. Background Art
[0002] Nitrate is a common pollutant derived from agricultural discharge, industrial wastewater, and other human activities, posing potential risks to ecosystems and public health. Therefore, the development of efficient and sensitive nitrate sensors is crucial for environmental monitoring and management.
[0003] The principle of UV spectroscopy for measuring nitrate is based on the characteristic absorption of nitrate ions (NO3-) in the UV band (200-240 nm). By using a UV light source and a spectral detector to measure the UV absorption spectrum of water samples in this band, the concentration of nitrate can be inferred through a series of calculations and modeling. Due to the advantages of UV spectroscopy being fast, sensitive and non-destructive, it is currently a commonly used method for detecting nitrate in seawater.
[0004] Since seawater contains high concentrations of chloride ions, bromide ions, organic matter and other substances, their absorption spectra overlap with the nitrate spectrum in the ultraviolet band, which increases the difficulty of establishing a seawater nitrate spectrum model. The key to solving the measurement of seawater nitrate is how to effectively separate the nitrate spectrum data from the interference spectrum and derive the nitrate concentration.
[0005] In the detection of nitrate in the spectrum, the least squares method is a very common fitting method. The least squares method assumes that the error is Gaussian and independent and identically distributed, but the actual spectral data may be affected by noise, baseline drift and other interferences, making the least squares method unable to effectively handle these non-Gaussian noise and systematic errors. In multivariate spectral data, the absorption values of different wavelengths may be highly correlated, which will lead to multicollinearity problems, making the estimation results of the least squares method unstable and increasing the variance of the regression coefficient.
[0006] In summary, it is necessary to design a seawater nitrate measurement method based on improved least squares estimation to solve the above problems. Summary of the invention
[0007] In view of the problems existing in the prior art, the purpose of the present invention is to provide a method for measuring the nitrate concentration in seawater by using an improved least squares method, which can effectively solve the problems of spectral overlap interference, non-Gaussian noise and systematic error, multicollinearity, etc. existing in the prior art, improve the fitting and prediction capabilities of the model, and provide a new solution for the rapid and accurate measurement of the nitrate concentration in seawater.
[0008] To achieve the above object, the technical solution adopted by the present invention is: a method for measuring seawater nitrate concentration based on improved least squares method, comprising the following steps:
[0009] Step 1: Prepare n groups of artificial seawater and nitrate-artificial seawater solution samples with different concentrations, measure the absorption spectrum data of each sample, calculate the absorbance data of each sample using the absorption spectrum data, and obtain the absorbance difference series of n groups of nitrate-artificial seawater samples;
[0010] Step 2: Use a filtering algorithm to preprocess the absorbance difference series and construct the processed data into an absorbance difference matrix ;
[0011] Step 3: Extract the absorbance difference matrix The sample composition corresponding to the characteristic wavelength with the highest weight Matrix, separating feature variables and target variables;
[0012] Step 4: Add the nitrate spectrum adjustment factor to the least squares model to obtain an improved cost function, substitute the characteristic variable and the target variable into the cost function, use the ten-fold cross-validation method to train multiple times, and select the value of the trained nitrate spectrum adjustment factor as the optimal adjustment factor ;
[0013] Step 5: Divide the absorption spectrum data into training set and test set, and use the optimal adjustment factor obtained in step 4 Substitute the cost function into the machine learning model training, evaluate the training results, save the trained model, and import the spectral data when using it to obtain the predicted seawater nitrate concentration.
[0014] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, step 1 comprises:
[0015] Step 1-1: preparing artificial seawater solution and different nitrate-artificial seawater solutions;
[0016] Step 1-2: Measure the spectral data of the artificial seawater solution and the different nitrate-artificial seawater solutions, calculate the absorbance at each wavelength, and record the absorbance as S0 and S n , , ,in, is the wavelength of sample 0 The absorbance data at The superscript indicates the sample number, and the subscript indicates the wavelength number;
[0017] Step 1-3: Calculate the absorbance difference between the different nitrate-artificial seawater solutions and the artificial seawater solution at each corresponding wavelength , and obtain the absorbance difference series of n groups of different nitrate-artificial seawater solutions. ,in, is the wavelength of sample n The absorbance difference data at .
[0018] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, step 2 comprises:
[0019] Step 2-1: Use a filtering algorithm to filter the absorbance difference Perform data smoothing to improve the signal-to-noise ratio and suppress or eliminate random noise and high-frequency noise of the signal;
[0020] Step 2-2: Arrange the absorbance difference values of n groups of different nitrate-artificial seawater solutions into a matrix:
[0021] .
[0022] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, step 3 comprises:
[0023] Step 3-1: Use Train a linear regression model on all wavelength column vectors in : , where x represents the feature variable and y represents the target variable. Representative wavelength The corresponding wavelength vector, b is the bias;
[0024] Step 3-2: Repeat the calculation in the regression model using different wavelengths to obtain the wavelengths corresponding to the feature vectors of the three wavelengths with the highest absolute weight values ;
[0025] Step 3-3: Extract samples corresponding to three wavelengths: , with the corresponding nitrate concentration The sample data format is converted, where 1...n represents the serial numbers of different nitrate-artificial seawater solutions;
[0026] Step 3-4: Separate the feature scalar x and the target variable y, and the n groups of feature variables x are expressed as: , where a, b, c represent the wavelength serial numbers; the target variable y of the n group is expressed as: .
[0027] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, in step 4, the cost function is: ,in, , , are the coefficients of the three characteristic variables, It contains the characteristic variable coefficient , , , represents the optimal adjustment factor, T represents matrix transpose, Represents an index used to traverse all elements in the range 1-n.
[0028] The above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method obtains the coefficient formula by taking the derivative of β on the cost function to find the extreme value: , where I is the identity matrix.
[0029] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, step 4 comprises:
[0030] Step 4-1: Standardize the training set and test set, and use the standardization method to process the data so that its mean is 0 and the standard deviation is 1;
[0031] Step 4-2: Add the nitrate spectrum adjustment factor to the least squares model to obtain an improved cost function;
[0032] Step 4-3: Substitute the feature variables and target variables into the cost function, train all samples using the ten-fold cross-validation method, and calculate the coefficient of determination of the regression model. Determining the Optimal Adjustment Factor in a Regression Model .
[0033] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, step 4-3 comprises:
[0034] Step a: Generate 50 parameters as the optimal adjustment factors by logarithmic division from 10 to the power of -5 to 10 to the power of 2 Alternative parameters for
[0035] Step b: Use a ten-fold cross-validation in the training set, that is, use nine folds for training and one fold for validation, then perform ten validations and calculate the coefficient of determination of the ten validations. As the model’s performance on the training set;
[0036] Step c: Perform the verification in step b on all 50 candidate parameters and select the coefficient of determination The alternative parameter corresponding to the highest value is taken as the optimal adjustment factor .
[0037] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, in step b, the coefficient of determination is ,in is the actual value, is the predicted value, is the mean of the actual values.
[0038] In the above-mentioned method for measuring seawater nitrate concentration based on the improved least squares method, step 5 comprises:
[0039] Step 5-1: Use the SPXY algorithm to divide the absorption spectrum data of n samples into training set and test set;
[0040] Step 5-2: Calculate the distance between samples using spectral data and nitrate concentration to obtain the distribution of characterized samples;
[0041] Step 5-3: Divide the training set and test set into proportions, use the training set to optimize the cost function, and obtain the regression coefficient;
[0042] Step 5-4: Use the test set to evaluate the performance of the trained cost function.
[0043] The beneficial effect of the method for measuring the nitrate concentration in seawater based on the improved least squares method of the present invention is as follows: the improved least squares method proposed in the present invention is used for measuring the nitrate concentration in seawater, which effectively copes with the challenges of spectral overlap interference, non-Gaussian noise, high-dimensional data and multicollinearity. Compared with the traditional method, this method significantly improves the fitting ability and prediction accuracy of the model, and improves the generalization ability of the model. A new solution is provided for the rapid and accurate measurement of the nitrate concentration in seawater. By using a cost function and adding a hyperparameter of the optimal adjustment factor obtained by the nitrate spectrum adjustment factor, the problem of excessive feature weights is avoided, the influence of outliers on model training is reduced, the model is optimized more effectively, the risk of overfitting is reduced, and its performance on the training set and the test set is improved. Thereby, the model can better cope with the overfitting problem to ensure that the model fits the training data well and can generalize on unseen data. BRIEF DESCRIPTION OF THE DRAWINGS
[0044] Figure 1 This is a flow chart for selecting the optimal nitrate spectrum adjustment factor of the present invention;
[0045] Figure 2 It is a training flow chart of the present invention;
[0046] Figure 3 The relationship between the actual and predicted values of the training set of the present invention;
[0047] Figure 4 This is the relationship between the actual and predicted values of the test set of the present invention. DETAILED DESCRIPTION
[0048] In order to enable those skilled in the art to better understand the technical solution of the present invention, the technical solution in the embodiment of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiment of the present invention. Obviously, the described examples are only part of the examples of the present invention, not all the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0049] Example 1
[0050] like Figure 1-Figure 2 As shown, a method for measuring seawater nitrate concentration based on an improved least squares method comprises the following steps:
[0051] Step 1: Prepare n groups of artificial seawater and nitrate-artificial seawater solution samples with different concentrations, measure the absorption spectrum data of each sample, and use the absorption spectrum data to calculate the absorbance data of each sample. The absorbance data S0 to S n There are n+1 sets of data in total, and the absorbance difference series of n sets of nitrate-artificial seawater samples are obtained.
[0052] Step 1-1: preparing artificial seawater solution and different nitrate-artificial seawater solutions.
[0053] Step 1-2: Measure the spectral data of the artificial seawater solution and the different nitrate-artificial seawater solutions, calculate the absorbance at each wavelength, and record the absorbance as S0 and S n , , ,in, is the wavelength of sample 0 The absorbance data at The superscript indicates the sample number, and the subscript indicates the wavelength sequence number.
[0054] Step 1-3: Calculate the absorbance difference between the different nitrate-artificial seawater solutions and the artificial seawater solution at each corresponding wavelength , and obtain the absorbance difference series of n groups of different nitrate-artificial seawater solutions. ,in, is the wavelength of sample n The absorbance difference data at .
[0055] Step 2: Use a filtering algorithm to preprocess the absorbance difference series and construct the processed data into an absorbance difference matrix .
[0056] Step 2-1: Use Savitzky-Golay filtering algorithm to filter NOS1, NOS2, NOS3, ... NOS n Data smoothing is performed by Perform data smoothing to improve the signal-to-noise ratio and suppress or eliminate random noise and high-frequency noise in the signal.
[0057] Step 2-2: Arrange the absorbance difference values of n groups of pre-treated nitrate-artificial seawater solutions into a matrix:
[0058] .
[0059] Step 3: Extract the absorbance difference matrix The sample composition corresponding to the characteristic wavelength with the highest weight Matrix, separating feature variables and target variables.
[0060] This step is the preparation before training. Because the previous matrix dimension is very high and the wavelength range is wide, by using this step to find the three wavelengths with the highest weight, it is to extract the characteristic wavelengths. With these three characteristic wavelengths, the absorbance data of all samples at these three wavelengths are extracted. If each sample has three wavelength spectral data, it is a The matrix of .
[0061] Step 3-1: Use Train a linear regression model on all wavelength column vectors in : , where x represents the feature variable and y represents the target variable. Representative wavelength The corresponding wavelength vector, b is the bias.
[0062] Step 3-2: Repeat the calculation in the regression model using different wavelengths to obtain the wavelengths corresponding to the feature vectors of the three wavelengths with the highest absolute weight values .
[0063] Step 3-3: Extract samples corresponding to three wavelengths: , with the corresponding nitrate concentration The sample data format is converted into DataFrame format, where 1...n represents the number of different nitrate-artificial seawater solutions. The reason for converting to DataFrame format is that it is easier to import in Python.
[0064] Step 3-4: Separate the feature scalar x and the target variable y, and the n groups of feature variables x are expressed as: , where a, b, c represent the wavelength serial numbers; the target variable y of the n group is expressed as: .
[0065] Step 4: Add the nitrate spectrum adjustment factor to the least squares model to obtain an improved cost function, which is: ,in, , , are the coefficients of the three characteristic variables, corresponding to The coefficient of It contains the characteristic variable coefficient , , , represents the optimal adjustment factor, T represents matrix transpose, Represents the index, which is used to traverse all elements in the range 1-n. By taking the derivative of β on the cost function to find the extreme value, the coefficient formula is obtained: , where I is the unit matrix. The parameter value of β can be obtained through the above coefficient formula.
[0066] Substitute the characteristic variables and target variables into the cost function, use the ten-fold cross-validation method to train multiple times, and select the value of the best nitrate spectrum adjustment factor as the optimal adjustment factor .
[0067] Step 4-1: Standardize the training set and test set, and use the standardization method to process the data so that its mean is 0 and the standard deviation is 1.
[0068] Step 4-2: Add the nitrate spectrum adjustment factor to the least squares model to obtain an improved cost function.
[0069] Step 4-3: Substitute the feature variables and target variables into the cost function, train all samples using the ten-fold cross-validation method, and calculate the coefficient of determination of the regression model. Determining the Optimal Adjustment Factor in a Regression Model .
[0070] During the training process, in order to obtain the optimal adjustment factor , a ten-fold cross-validation method was used for all samples, first based on the coefficient of determination of the regression model Determine the hyperparameters in the regression model. Specifically:
[0071] Step a: Generate 50 parameters as the optimal adjustment factors by logarithmic division from 10 to the power of -5 to 10 to the power of 2 Here the parameter is the nitrate spectrum adjustment factor, and the hyperparameter is the optimal adjustment factor.
[0072] Step b: Use a ten-fold cross-validation in the training set, that is, use nine folds for training and one fold for validation, then perform ten trainings and calculate the coefficient of determination of the regression model obtained after ten trainings. As the performance of the model on the training set, different nitrate spectrum adjustment factors were introduced using the ten-fold cross-validation method, and the one with the best effect was selected, which is the determination coefficient of the regression model. The highest nitrate spectrum adjustment factor value is used as the optimal adjustment factor for the final formal training. Numeric value.
[0073] Step c: Perform the verification in step b on all 50 candidate parameters and select the coefficient of determination of the regression model The alternative parameter corresponding to the highest value is taken as the optimal adjustment factor .
[0074] Step 5: Divide the absorption spectrum data into a training set and a test set, substitute the hyperparameter γ obtained in step 4 into the cost function to perform machine learning model training, and evaluate the training results. Save the trained model, and import the spectrum data to obtain the concentration of seawater nitrate when using it.
[0075] Step 5-1: Use the SPXY algorithm to divide the absorption spectrum data of n samples into training set and test set;
[0076] Step 5-2: Calculate the distance between samples using spectral data and nitrate concentration to obtain the distribution of characterized samples;
[0077] Step 5-3: Divide the training set and the test set according to the ratio, use the training set to train the cost function, and obtain the regression coefficient;
[0078] Step 5-4: Use the test set to evaluate the performance of the trained cost function.
[0079] Use the SPXY algorithm to divide the previous samples into training sets and test sets for easy training. Use the optimal adjustment factor determined before the cost function , substitute the optimal adjustment factor obtained in step 4 as the final parameter for the final training.
[0080] Finally, the regression coefficient β is obtained through training, and the regression model can be constructed. , the nitrate concentration in seawater can be predicted by importing the absorbance difference.
[0081] Example 2
[0082] like Figure 1 , Figure 2 , Figure 3 , Figure 4As shown, a method for measuring seawater nitrate concentration based on an improved least squares method comprises the following steps:
[0083] Step 1: Prepare n groups of artificial seawater and nitrate-artificial seawater solution samples with different concentrations, measure the absorption spectrum data of each sample, and use the absorption spectrum data to calculate the absorbance data of each sample. n There are n+1 sets of data in total, and the absorbance difference series of n sets of nitrate-artificial seawater samples are obtained.
[0084] Step 1: prepare an artificial seawater solution, wherein each liter of the artificial seawater solution contains 35 g of sodium chloride and 86 g of sodium bromide.
[0085] Step 2: Take a portion of the artificial seawater solution and add potassium nitrate to prepare a nitrate-artificial seawater standard solution, wherein each liter of the nitrate-artificial seawater standard solution contains 1 g of potassium nitrate.
[0086] Step 3: In order to prepare the nitrate sample solution in the training set more accurately, take out Vml of nitrate-artificial seawater standard solution and transfer it to a volumetric flask, and dilute it to 100mL with artificial seawater. , where V is the volume (mL) of the nitrate-artificial seawater standard solution to be taken; n is the number of the nth solution, i.e. the solution, and represents the concentration of the nitrate solution, 0.3nmg / L, and the maximum value of n is 200; V0 is the volume (mL) of the solution with the current number.
[0087] Step 4: Repeat the above step 3 to prepare nitrate-artificial seawater solutions of different concentrations; the nitrate content in the solution is set to a minimum concentration of 0.3 mg / L and a maximum concentration of 60 mg / L, with a step length of 0.3 mg / L, for a total of 200 samples.
[0088] Step 5: Calculate the absorbance at each wavelength according to the absorption spectrum of the artificial seawater solution:
[0089] The ultraviolet absorption spectrum of pure water was measured using a deuterium halogen lamp light source and a fiber optic spectrometer. The spectrometer has 2048 pixels and can record the light intensity data of 136 pixels in the wavelength range of 200nm to 240nm. The wavelength values corresponding to each pixel in the fiber optic spectrometer are recorded as a series in ascending order of wavelength: .
[0090] The intensity of pure water transmission is recorded pixel by pixel as a series: .
[0091] The ultraviolet absorption spectrum of artificial seawater solution records the transmitted light intensity as a series in the order of wavelength from small to large: .
[0092] Take pure water sample as reference, according to Lambert-Beer law absorbance formula: .
[0093] Calculate the absorbance at each wavelength one by one, and record the absorbance data of the artificial seawater solution as a series in the order of wavelength from small to large. : .
[0094] Step 6: Repeat step 5 to measure the UV absorption spectra of 200 portions of nitrate-artificial seawater solutions, and record the spectral intensity as a series: ,in, Indicates that sample n has a wavelength The spectral intensity at , the superscript n is the number of the nitrate-artificial seawater solution, and the subscript is the serial number of the wavelength.
[0095] And calculate the absorbance data of nitrate-artificial seawater solution: , where the superscript n of A is the number of the nitrate-artificial seawater solution.
[0096] Step 2: Preprocess the data and construct the data matrix.
[0097] Step 7: Calculate the absorbance difference between the nitrate-artificial seawater solution and the artificial seawater solution at each corresponding wavelength:
[0098] in, Sample n at wavelength The absorbance difference data at .
[0099] Step 8: Use Savitzky-Golay filtering algorithm to Perform data smoothing to improve the signal-to-noise ratio and suppress or eliminate random noise and high-frequency noise in the signal.
[0100] Step 9: The absorbance difference values of the n groups of nitrate-artificial seawater solutions after pretreatment are arranged into a matrix: , where each row represents a sample and each column represents the absorbance difference data of 200 samples at the same wavelength.
[0101] Step 3: Separate feature variables and target variables.
[0102] Step 10: Using the Matrix Train a linear regression model on all wavelength column vectors in : ,in, Representative wavelength The corresponding wavelength vector, b is the bias.
[0103] For a linear regression model, the importance of a feature can be measured by the absolute value of its weight: ,in, Representative wavelength The corresponding wavelength vector.
[0104] Step 11: Repeat step 10 to find the wavelengths corresponding to the three eigenvectors with the highest absolute values of weights in the set. .
[0105] Step 12: Extract samples corresponding to three wavelengths, , with the corresponding nitrate concentration Convert the data into DataFrame format.
[0106] Step 13: Separate feature variables and target variables The feature variable is x.
[0107] ,in The superscript n is the number of the nitrate-artificial seawater solution, and the subscript is the wavelength sequence.
[0108] The target variable is y.
[0109] ,in, is the nitrate concentration of the sample solution, in mg / L.
[0110] Step 14: Standardize the training set and test set, and use the standardization method to process the data so that its mean is 0 and the standard deviation is 1.
[0111] Step 4: Construct the cost function.
[0112] Step 15: Calculate the cost function of the improved least squares regression model using the following formula:
[0113] ,in, The subscripts are the numbers of the nitrate-artificial seawater solutions. are the coefficients of the three characteristic variables, corresponding to The coefficient of It contains the characteristic variable coefficient , is the optimal adjustment factor, The feature vector representing the nitrate-artificial seawater solution sample numbered n The transpose of It represents the actual solution concentration of the nitrate-artificial seawater solution sample numbered n.
[0114] Step 16: By taking the derivative of β on the cost function to find the extreme value, we get the coefficient formula: , where I is the unit matrix. The parameter value of β can be obtained through the above coefficient formula.
[0115] Step 17: The mean square error (MSE) and the coefficient of determination are used to evaluate this model. . Mean Squared Error (MSE): ,in, is the actual value, is the predicted value and n is the number of samples.
[0116] score (coefficient of determination of the regression model), ,in is the mean of the actual values.
[0117] Step 18: During the training process, in order to obtain the optimal adjustment factor , a ten-fold cross-validation method is used for all samples. First, according to the coefficient of determination of the regression model Determining the optimal adjustment factor in a regression model Specifically, we first generate 50 parameters from 10 to the power of -5 to 10 to the power of 2 in logarithmic division as the optimal adjustment factors. , and then use a ten-fold cross-validation in the training set, that is, use nine folds for training and one fold for validation, then perform ten validations, and use the coefficient of determination of the regression model of the ten validations As the performance of the model on the training set, all 50 candidate parameters are verified in this way, and then the parameter corresponding to the highest coefficient of determination of the regression model is selected as the optimal adjustment factor .
[0118] Step 5: Evaluate the training results.
[0119] Step 19: Determine the optimal adjustment factor After that, the absorption spectrum data of 200 samples were divided into training set and test set using SPXY algorithm. When calculating the distance between samples, the X variable (spectral data) and Y variable (nitrate concentration) were taken into account at the same time. The distance between samples was calculated using two variables to ensure the maximum characterization of sample distribution, so that the training set samples are different and representative, and the stability of the model is improved. The training set (160 samples) and the test set (40 samples) were divided in a ratio of 8:2. The regression model was trained using the entire training set to obtain the regression coefficient β, which includes the characteristic variable coefficient The prediction results are shown in the figure. According to the regression coefficient β obtained by training, the regression model can be constructed. , the nitrate concentration in seawater can be predicted by importing the absorbance difference. Finally, the performance of the model is evaluated using the test set.
[0120] Example 3
[0121] The similarities between this embodiment and the above embodiment will not be described in detail, and the difference between the present embodiment and the above embodiment is as follows:
[0122] Coefficient of determination The mean square error (MSE) is used as the model evaluation criterion. The mean square error (MSE) is an evaluation indicator that measures the difference between the model prediction value and the actual observation value. It calculates the average of the squares of the difference between the predicted value and the actual value, and is usually used to evaluate the prediction performance of the regression model. The smaller the MSE, the more accurate the model's prediction. (Coefficient of Determination) is an indicator to measure the degree of fit of the regression model to the observed data. It reflects the proportion of the variation of the dependent variable (target variable) that can be explained by the independent variable (characteristic variable), and its value range is between 0 and 1. Specifically, when =1, the model can perfectly explain all the variation of the dependent variable; when =0, the model cannot explain any variation in the dependent variable, and the prediction effect is equivalent to random guessing. In actual situations, The closer it is to 1, the better the model fits the data; the closer it is to 0, the worse the model fits the data. After training the model using the data of the entire training set, the evaluation results obtained based on the test set are shown in Table 1.
[0123] Table 1: Evaluation results
[0124] Mean Squared Error (MSE) <![CDATA[Coefficient of determination (R 2 )]]> Training set 2.8776992859 0.980878803 Test Set 4.4262397690 0.966265766
[0125] According to Table 1, the coefficient of determination of the regression model is 0.96. This indicates that the model can explain 96% of the variation in the dependent variable. In other words, the model fits the data very well. The smaller the MSE, the smaller the prediction error of the model. An MSE of 4.4 indicates that the square of the average prediction error is 4.4. Overall, The mean square error (MSE) of 0.96 and the mean square error (MSE) of 4.4 indicate that this regression model is able to fit and predict the target variable, i.e., nitrate concentration, through the characteristic variable, i.e., spectrum, at a high level.
[0126] The present invention proposes a method for measuring seawater nitrate concentration using an improved least squares method; the modeling method adopted in the present technical solution can effectively improve the fitness of the model, can provide a new solution for the detection of nitrate nitrogen in water bodies, and can provide a certain reference for rapid and pollution-free online water quality monitoring scenarios.
[0127] The above embodiments are only for illustrating the inventive concept and features of the present invention, and their purpose is to enable those skilled in the art to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent changes or modifications made based on the essence of the content of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for measuring seawater nitrate concentration based on improved least squares method, characterized in that: The following steps are involved: Step 1: Prepare n groups of artificial seawater and nitrate-artificial seawater solution samples with different concentrations, measure the absorption spectrum data of each sample, calculate the absorbance data of each sample using the absorption spectrum data, and obtain the absorbance difference series of n groups of nitrate-artificial seawater samples; Step 2: Use a filtering algorithm to preprocess the absorbance difference series and construct the processed data into an absorbance difference matrix ; Step 3: Extract the absorbance difference matrix The sample composition corresponding to the characteristic wavelength with the highest weight Matrix, separating feature variables and target variables; Step 4: Add the nitrate spectrum adjustment factor to the least squares model to obtain an improved cost function, substitute the characteristic variable and the target variable into the improved cost function, use the ten-fold cross-validation method to train multiple times, and select the value of the trained nitrate spectrum adjustment factor as the optimal adjustment factor , the improved cost function is: ,in, , , are the coefficients of the three characteristic variables, It contains the characteristic variable coefficient , , , represents the optimal adjustment factor, T represents matrix transpose, Represents an index, which is used to traverse all elements in the range 1-n, including: Step 4-1: Standardize the training set and test set, and use the standardization method to process the data so that its mean is 0 and the standard deviation is 1; Step 4-2: Add the nitrate spectrum adjustment factor to the least squares model to obtain an improved cost function; Step 4-3: Substitute the feature variables and target variables into the improved cost function, train all samples using the ten-fold cross-validation method, and calculate the determination coefficient of the improved cost function. Determine the optimal adjustment factor in the improved cost function ; Step 5: Divide the absorption spectrum data into training set and test set, and use the optimal adjustment factor obtained in step 4 Substitute the improved cost function into the machine learning model training, evaluate the training results, save the trained model, and import the spectral data when using it to obtain the predicted seawater nitrate concentration.
2. The method for measuring seawater nitrate concentration based on improved least squares method according to claim 1, characterized in that: The step 1 comprises: Step 1-1: preparing artificial seawater solution and different nitrate-artificial seawater solutions; Step 1-2: Measure the spectral data of the artificial seawater solution and the different nitrate-artificial seawater solutions, calculate the absorbance at each wavelength, and record the absorbance as S0 and S n , , ,in, is the wavelength of sample 0 The absorbance data at The superscript indicates the sample number, and the subscript indicates the wavelength number; Step 1-3: Calculate the absorbance difference between the different nitrate-artificial seawater solutions and the artificial seawater solution at each corresponding wavelength , and obtain the absorbance difference series of n groups of different nitrate-artificial seawater solutions. ,in, is the wavelength of sample n The absorbance difference data at .
3. The method for measuring seawater nitrate concentration based on improved least squares method according to claim 2, characterized in that: The step 2 comprises: Step 2-1: Use a filtering algorithm to filter the absorbance difference Perform data smoothing to improve the signal-to-noise ratio and suppress or eliminate random noise and high-frequency noise of the signal; Step 2-2: Arrange the absorbance difference values of n groups of different nitrate-artificial seawater solutions into a matrix: 。 4. The method for measuring seawater nitrate concentration based on improved least squares method according to claim 3, characterized in that: The step 3 comprises: Step 3-1: Use Train a linear regression model on all wavelength column vectors in : , where x represents the feature variable and y represents the target variable. Representative wavelength The corresponding wavelength vector, b is the bias; Step 3-2: Repeat the calculation in the regression model using different wavelengths to obtain the wavelengths corresponding to the feature vectors of the three wavelengths with the highest absolute weight values ; Step 3-3: Extract samples corresponding to three wavelengths: , with the corresponding nitrate concentration The sample data format is converted, where 1...n represents the serial numbers of different nitrate-artificial seawater solutions; Step 3-4: Separate the feature scalar x and the target variable y, and the n groups of feature variables x are expressed as: , where a, b, c represent the wavelength serial numbers; the target variable y of the n group is expressed as: .
5. The method for measuring seawater nitrate concentration based on improved least squares method according to claim 1, characterized in that: By taking the derivative of β on the cost function to find the extreme value, we get the coefficient formula: , where I is the identity matrix.
6. The method for measuring seawater nitrate concentration based on improved least squares method according to claim 5, characterized in that: The step 4-3 comprises: Step a: Generate 50 parameters as the optimal adjustment factors by logarithmic division from 10 to the power of -5 to 10 to the power of 2 Alternative parameters for Step b: Use a ten-fold cross-validation in the training set, that is, use nine folds for training and one fold for validation, then perform ten training runs and calculate the coefficient of determination of the ten training runs. As the model’s performance on the training set; Step c: Perform the verification in step b on all 50 candidate parameters and select the coefficient of determination The alternative parameter corresponding to the highest value is taken as the optimal adjustment factor .
7. The method for measuring seawater nitrate concentration based on improved least squares method according to claim 6, characterized in that: In step b, the coefficient of determination ,in is the actual value, is the predicted value, is the mean of the actual values.
8. The method for measuring seawater nitrate concentration based on improved least squares method according to claim 1, characterized in that: The step 5 comprises: Step 5-1: Use the SPXY algorithm to divide the absorption spectrum data of n samples into training set and test set; Step 5-2: Calculate the distance between samples using spectral data and nitrate concentration to obtain the distribution of characterized samples; Step 5-3: Divide the training set and the test set into proportions, use the training set to optimize the cost function, and obtain the regression coefficient; Step 5-4: Use the test set to evaluate the performance of the trained cost function.
Citation Information
Patent Citations
Food nitrite and nitrate quantitative detection method
CN101059429A
Concentration measurement method for nitrate ion and nitrite ion in seawater, measurement system, measurement program, and its recording medium
JP2008145297A
