Machine learning method for predicting stable isotope abundance of nitrate nitrogen in water body
Patent Information
- Application Number
- CN202611523368.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-29
- Publication Date
- 2026-11-20
AI Technical Summary
Existing methods for detecting the abundance of stable isotopes of nitrate nitrogen in water bodies are costly and have long analysis cycles, making it difficult to meet the needs of high-frequency online monitoring of watershed water quality. Furthermore, existing machine learning models ignore the seasonal cyclical rhythms of environmental factor evolution, resulting in inaccurate predictions and weak interpretability.
By constructing monthly cycle coding features, combining hierarchical quartile random dataset partitioning and extreme gradient boosting models, introducing biogeochemical mapping relationships, screening key environmental factors and adding low-confidence warnings, the prediction results output by the model are ensured to have high accuracy and reliability.
This method enables low-cost and efficient acquisition of stable isotope abundances of nitrate nitrogen in water bodies, improves the structural stability and interpretability of prediction models, and enhances the reliability and safety of online monitoring.
Smart Images

Figure CN123138931A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of water environment monitoring technology, specifically to a machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water bodies. Background Technology
[0002] Currently, the determination of stable isotope abundance of nitrate nitrogen in water bodies mainly relies on isotope mass spectrometry. This detection method is costly and has a long analysis cycle, making it difficult to meet the operational needs of high-frequency online monitoring of watershed water quality. To reduce detection costs and increase monitoring frequency, researchers have introduced machine learning techniques to predict isotope abundance. However, in existing data processing workflows, discrete sampling times are directly input into the model, ignoring the seasonal cyclical rhythms of environmental factor evolution. This leads to misalignment of features in the time dimension, causing an imbalance in the spatial distribution of samples and failing to establish a reliable data foundation for model development.
[0003] In constructing predictive models, purely data-driven algorithms lack the underlying constraints of biogeochemical mechanisms. Existing predictive models do not incorporate prior rules from environmental science when splitting algorithm nodes, making them prone to predictive biases that violate objective natural laws within specific characteristic ranges. This lack of such constraints leads to unstable model structures and difficulty in adapting to complex and ever-changing water quality data.
[0004] Meanwhile, existing prediction methods lack interpretability, failing to match the decision weights calculated by the algorithms with actual biochemical reaction patterns, making it difficult to translate them into specific pollution source analysis conclusions. In actual engineering operations, when faced with unknown water sample characteristics exceeding the range of the training set, the lack of data boundary warning and prevention mechanisms leads to erroneous outputs from forced extrapolation by the model, reducing the safety of the online monitoring system and its practical engineering application value. Summary of the Invention
[0005] The technical problem solved by this invention is that conventional water body isotope mass spectrometry detection is costly and has a long analysis cycle, making it difficult to meet the operational needs of high-frequency online monitoring of watershed water quality. When existing methods directly apply machine learning models to predict isotope abundance, conventional data processing methods often ignore the seasonal cyclical rhythm characteristics of environmental factor evolution. Furthermore, purely data-driven models lack the underlying constraints of biogeochemical mechanisms, which can easily lead to prediction biases that violate the laws of natural science in small sample training or extreme feature intervals. This results in weak interpretability of prediction results and insufficient reliability for practical engineering applications.
[0006] To address the above problems, the present invention provides the following technical solution: This invention provides a machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water bodies, comprising: Obtain routine water quality monitoring data, sampling month, and measured values of nitrate nitrogen stable isotope abundance from water samples; construct monthly periodic coding features and form an input feature vector; wherein, the routine water quality monitoring data includes nitrate nitrogen features, ammonium nitrogen features, and dissolved oxygen features; Based on the measured abundance values of stable nitrate nitrogen isotopes, a hierarchical quartile random dataset was divided to construct training and test sets. Based on the training set and the Optuna framework, combined with the tree-structured Parzen estimator algorithm, an extreme gradient boosting model was determined. Based on the test set, the SHAP contribution value is calculated, key environmental factors are screened, and biogeochemical mapping relationships are established to determine the final prediction model. Obtain routine water quality monitoring data and sampling month for unknown water body samples, construct input feature vectors for unknown water body samples, input them into the final prediction model, and output predicted values of nitrate nitrogen stable isotope abundance.
[0007] By adopting the above technical solutions, an environmental input space is constructed by integrating multi-source water quality observation data and temporal rhythm characteristics. The consistency of the probability distribution of the data sample set is ensured by using the hierarchical division rule of the target variable. An extreme gradient boosting model with domain prior constraints is constructed and the hyperparameter optimization of the algorithm is completed. Subsequently, an interpretation mechanism is introduced to map the decision weights of the underlying algorithm with macroscopic geochemical processes, realizing a verification closed loop from data acquisition to model shaping and then to mechanism interpretation. This results in the output prediction results having high numerical calculation accuracy and reliable mechanism support logic.
[0008] Preferably, the acquisition of routine water quality monitoring data, sampling month, and measured values of nitrate nitrogen stable isotope abundance from water samples, constructing monthly periodic coding features, and forming an input feature vector includes: The water temperature, dissolved oxygen, conductivity, turbidity, chlorophyll a, total nitrogen, nitrate nitrogen, nitrite nitrogen, ammonium nitrogen, and total organic carbon of the water sample are obtained as the routine water quality monitoring data. After multiplying the ratio of the sampled month to 12 by 2π, the sine and cosine values are calculated respectively to obtain the sine periodic code value and the cosine periodic code value of the month as the periodic code feature of the month; The input feature vector is formed by horizontally concatenating the sine cycle encoding value and the cosine cycle encoding value of the month with the conventional water quality monitoring data.
[0009] By adopting the above technical solution, the discrete sampling time sequence is mapped and reconstructed using the trigonometric function transformation mechanism, eliminating the numerical fault and spatial feature distance misalignment caused by the linear encoding of calendar numbers, reflecting the physical properties of seasonal periodic changes in a two-dimensional feature space, and achieving an objective numerical characterization of the environmental background state by combining multidimensional water quality physicochemical indicators.
[0010] Preferably, the step of dividing the dataset into hierarchical quartile random datasets based on the measured abundance values of nitrate nitrogen stable isotopes to construct training and testing sets includes: The water samples were sorted in ascending order based on the measured values of nitrate nitrogen stable isotope abundance. The sorted water samples are divided into six quartile intervals with equal frequency. Random sampling without replacement is performed independently within each quartile interval, and the samples are split into training and test subsets in a ratio of 80%:20%. The training set is formed by merging all the training subsets of the aforementioned quartile intervals, and the test set is formed by merging all the test subsets of the aforementioned quartile intervals.
[0011] By adopting the above technical solution, fine-grained interval division and independent proportional sampling are performed based on the measured target values, avoiding the imbalance of sample space distribution caused by global random sampling, ensuring the consistency of the training set and test set in the target probability density distribution shape and value boundaries, and establishing a reliable data foundation for subsequent model evaluation and mechanism verification.
[0012] Preferably, the extreme gradient boosting model based on the training set and the Optuna framework combined with the tree-structured Parzen estimator algorithm includes: The extreme gradient boosting model includes a classification regression tree. During the node splitting process of the classification regression tree, a positive monotonic constraint is set for the nitrate nitrogen feature, a negative monotonic constraint is set for the ammonium nitrogen feature, and no monotonicity constraint is imposed on other features in the input feature vector, which serves as a preset monotonicity constraint. The search space boundary of the Optuna framework combined with the tree structure Parzen estimator algorithm is defined, and the minimum root mean square error of five-fold cross-validation is taken as the objective function. The hyperparameters are automatically optimized by iteratively using the Optuna framework combined with the tree structure Parzen estimator algorithm. The optimal hyperparameter combination is output and applied to the extreme gradient boosting model to complete the modeling.
[0013] By adopting the above technical solution, the principles of biogeochemistry are transformed into numerical monotonicity constraint parameters of the algorithm, which directly control the weight output of the decision tree when the node splits, suppress the abnormal numerical fluctuations that violate the laws of the objective environment in the sample sparse interval, and optimize the model settings by combining the automated hyperparameter optimization framework to improve the structural stability and generalization ability of the model fitting.
[0014] Preferably, the step of using the Optuna framework combined with the tree-structured Parzen estimator algorithm to perform hyperparameter iterative automatic optimization includes: Based on the root mean square error performance obtained from historical evaluations during the automatic optimization process of hyperparameter iteration, a preset proportion of quantile thresholds is set. A probability density function with good performance is constructed based on hyperparameter combinations below the quantile threshold, and a probability density function with poor performance is constructed based on hyperparameter combinations above the quantile threshold. Calculate the ratio of the well-performing probability density function to the poorly performing probability density function, and determine the hyperparameter values for the next iteration based on the ratio.
[0015] By adopting the above technical solution, a group probability density mathematical model is established based on the root mean square error index generated in the historical iteration trajectory. The search direction with improvement potential is derived by using the expectation maximization principle, which accelerates the calculation convergence process of the multidimensional hyperparameter space. Thus, the optimal parameter combination that minimizes the cross-validation error is located under the premise of controlling the computational cost.
[0016] Preferably, the step of calculating the SHAP contribution value based on the test set and screening key environmental factors includes: The test set is input into the finalized extreme gradient boosting model, and the SHAP algorithm is used to calculate the SHAP contribution value of each feature in the input feature vector to the prediction result of each water sample in the test set. The absolute values of the SHAP contribution values of each of the aforementioned features in each of the aforementioned water samples in the test set are taken as absolute values and averaged to obtain the mean absolute SHAP value of each of the aforementioned features. The features in the input feature vector are sorted from largest to smallest according to the mean absolute SHAP value, and the top preset number of features are selected as key environmental factors.
[0017] By adopting the above technical solution, a mechanism is introduced to explain the implicit inference process inside the ensemble tree model. The ensemble prediction value is decomposed into the sum of the basic expectation and the weights of each independent input feature. The influence of each environmental factor index on the prediction result output is quantitatively measured. The dimensionality reduction extraction of the feature space is achieved by using the mean absolute value sorting mechanism, which provides an objective mathematical measurement basis for subsequent correlation derivation.
[0018] Preferably, the step of screening key environmental factors and establishing biogeochemical mapping relationships to determine the final prediction model includes: The average or median of each of the key environmental factors in the test set is used as a benchmark. The relative magnitude of the values of each of the key environmental factors in each of the water samples in the test set with the benchmark is analyzed, as well as the positive and negative directional relationship of the SHAP contribution values of each of the key environmental factors. When the key environmental factors selected, the relative magnitudes of the key environmental factors and the benchmark, and the positive and negative directions of the SHAP contribution values of the key environmental factors all satisfy the preset biogeochemical mapping relationship, the finalized extreme gradient boosting model is determined as the final prediction model. If the preset biogeochemical mapping relationship is not met, the search space boundary of the Optuna framework combined with the tree structure Parzen estimator algorithm or the preset monotonicity constraint is adjusted, and the extreme gradient boosting model is redefined.
[0019] By adopting the above technical solutions, we can combine data verification with environmental mechanism verification, examine whether the feature contribution weights within the statistical scope conform to the laws of biochemical reactions, and avoid false associations introduced by dataset fitting through condition-triggered search space optimization and reset mechanisms, thus ensuring that the model prediction logic conforms to objective physical science mechanisms.
[0020] Preferably, the biogeochemical mapping relationship includes at least one of the following mapping rules: When key environmental factors include ammonium nitrogen characteristics, and the values of ammonium nitrogen characteristics are higher than the baseline and the SHAP contribution value corresponding to the ammonium nitrogen characteristics is negative, it is mapped to the kinetic isotope fractionation effect in the nitrification process. When the key environmental factor includes nitrate nitrogen features, and the value of the nitrate nitrogen features is higher than the baseline and the SHAP contribution value corresponding to the nitrate nitrogen features is positive, it is mapped to a mixed nitrate source scenario dominated by anthropogenic input. When key environmental factors include dissolved oxygen characteristics, and the value of the dissolved oxygen characteristic is lower than the baseline and the SHAP contribution value corresponding to the dissolved oxygen characteristic is positive, it is mapped to a denitrification isotope enrichment process.
[0021] By adopting the above technical solutions, data judgment rules in the field of water environment pollution analysis are established, and the positive and negative contribution indicators output by the algorithm are substantially transformed into specific source apportionment qualitative conclusions of nitrification fractionation, end-member mixing and denitrification reactions, thereby realizing an effective combination of machine learning numerical calculation and environmental science mechanisms.
[0022] Preferably, the step of obtaining routine water quality monitoring data and sampling month of unknown water body samples, constructing input feature vectors for unknown water body samples, inputting them into the final prediction model, and outputting predicted values of nitrate nitrogen stable isotope abundance includes: Obtain routine water quality monitoring data for the unknown water body sample and the sampling month of the unknown water body sample; Based on the sampling month of the unknown water body sample, a monthly periodic coding feature of the unknown water body sample is constructed. The regular water quality monitoring data of the unknown water body sample is concatenated with the monthly periodic coding feature of the unknown water body sample to form an unknown water body sample input feature vector with the same dimension as the input feature vector. This input feature vector is then input into the final prediction model. The final prediction model is used to make predictions and output the predicted value of the nitrate nitrogen stable isotope abundance.
[0023] By adopting the above technical solution, the data processing methods of online monitoring and offline inference are unified. The monitoring data is processed using feature construction rules consistent with the training phase, and prediction is performed using a model that has been validated by the mechanism, thereby achieving low-cost and efficient acquisition of nitrogen isotope abundance in water bodies.
[0024] Preferably, after outputting the predicted abundance values of stable nitrate nitrogen isotopes, the method further includes: Determine whether the value of any feature in the input feature vector of the unknown water sample exceeds the value range of the same feature in the training set. If so, generate and attach a low confidence warning label while outputting the predicted abundance value of nitrate nitrogen stable isotopes.
[0025] By adopting the above technical solutions, a data boundary monitoring mechanism is established to identify input features that exceed the distribution range of the training set, thereby avoiding prediction bias caused by excessive extrapolation of the model in unknown data areas and improving the reliability of online monitoring results and the security of practical applications.
[0026] This invention provides a machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water bodies. It has the following beneficial effects: 1. This invention acquires routine water quality monitoring data and sampling months and constructs monthly periodic coding features. It combines a stratified hexameric random dataset partitioning method to construct training and testing sets, transforming discrete sampling times into numerical features that reflect the seasonal cycle in nature. At the same time, it ensures the consistency of the sampling data in the target probability density distribution, avoids feature misalignment and sample imbalance caused by directly inputting raw time data, and establishes a reliable data foundation for subsequent model development.
[0027] 2. This invention introduces preset positive or negative monotonicity constraints on core water quality characteristics during the node splitting process of the classification and regression tree in the extreme gradient boosting model. It also uses the Optuna framework combined with the tree structure Parzen estimator algorithm to perform automatic hyperparameter optimization with the goal of minimizing cross-validation error. This directly transforms environmental science prior rules into numerical constraints for the underlying algorithm, suppresses abnormal prediction biases that violate objective environmental laws in specific data intervals, and improves the structural stability and generalization ability of the prediction model.
[0028] 3. This invention screens key environmental factors by calculating SHAP contribution values and matches and verifies the characteristic performance with the biogeochemical mapping relationship. After confirming that the model's inference logic conforms to the laws of real biochemical reactions, it is determined as the final prediction model. The algorithm's decision weights are clearly transformed into specific qualitative conclusions of pollution source analysis. Combined with the prevention mechanism of adding a low confidence warning label when unknown samples exceed the characteristic value range, the interpretability of the prediction results and the safety of actual online monitoring engineering applications are improved. Attached Figure Description
[0029] Figure 1 This is a block diagram of a machine learning prediction system for the abundance of stable isotopes of nitrate nitrogen in water, according to an embodiment of the present invention. Figure 2 This is a flowchart of a machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water according to an embodiment of the present invention. Figure 3 This is a flowchart illustrating the data acquisition and monthly cycle encoding process according to an embodiment of the present invention; Figure 4 This is a flowchart of the hexabyte hierarchical random dataset partitioning process according to an embodiment of the present invention; Figure 5 This is a flowchart illustrating the construction and Bayesian parameter tuning of an extreme gradient boosting model according to an embodiment of the present invention. Figure 6 A flowchart of SHAP feature contribution analysis and biogeochemical mapping according to an embodiment of the present invention; Figure 7 This is a flowchart illustrating the prediction and application of unknown water body samples according to an embodiment of the present invention; Figure 8 This is a line graph comparing predicted and measured values under different model architectures according to an embodiment of the present invention. Figure 9 A bar chart showing the distribution of mean absolute SHAP values of key environmental factors in an embodiment of the present invention; Figure 10 This is a bar chart comparing the root mean square error under different dataset partitioning methods according to an embodiment of the present invention. Detailed Implementation
[0030] The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0031] To better understand the technical solution of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. (Refer to...) Figure 1 This invention provides a machine learning prediction system for the abundance of stable isotopes of nitrate nitrogen in water, comprising: The data acquisition module is used to acquire routine water quality monitoring data and sampling month of water samples, and to construct periodic coding features; The dataset partitioning module is used to perform hierarchical quartile random dataset partitioning based on the target variable, and to construct training and test sets. The model building and hyperparameter tuning module is used to build an extreme gradient boosting model. In a preferred embodiment, monotonicity constraints are set on some input features, and hyperparameter optimization is performed based on the Bayesian optimization algorithm. The model interpretation module is used to calculate the SHAP contribution value, screen key environmental factors, and establish biogeochemical mapping relationships. The model prediction module is used to acquire data from unknown water samples and use the final prediction model to predict the abundance of stable nitrate nitrogen isotopes.
[0032] Based on the aforementioned machine learning prediction system for the abundance of stable isotopes of nitrate nitrogen in water bodies, referring to Figure 2 This invention provides a machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water, comprising the following steps: S10: Obtain routine water quality monitoring data and sampling month for water samples, and construct periodic coding features; S20: Based on the target variable, a hierarchical quartile random dataset is partitioned to construct training and test sets; S30, Construct an extreme gradient boosting model, set monotonic constraints on some input features in a preferred embodiment, and perform hyperparameter optimization based on the Optuna framework combined with the tree structure Parzen estimator algorithm; S40, calculate the SHAP contribution value, screen key environmental factors and establish biogeochemical mapping relationships; S50: Obtain data from unknown water samples and use the final prediction model to predict the abundance of stable nitrate nitrogen isotopes.
[0033] This invention is primarily applied to the identification of nitrate pollution sources in water bodies and routine water quality monitoring. It employs soft sensing technology to output predicted values of nitrate nitrogen stable isotope abundance. At the system interaction level, the input end of the data acquisition module connects to a multi-parameter water quality probe and a conventional water quality analysis instrument, receiving water quality physicochemical index data measured by the equipment. The output end of the model prediction module directly generates predicted values of nitrate nitrogen stable isotope abundance for the target water body.
[0034] In step S10, the system collects routine physicochemical data. Based on the temporal evolution attributes of environmental factors, it extracts specific monthly information from water samples. Through trigonometric function transformation, linear calendar numbers are reconstructed into sine and cosine feature components, generating continuous periodic codes to reflect the seasonal rhythm of the water body's physicochemical state. The periodic code features are concatenated with routine water quality monitoring data to form the input feature vector.
[0035] In step S20, the measured abundance of stable isotopes of nitrate nitrogen determined by stable isotope mass spectrometry is used as the measured value of the target variable. All samples are sorted according to the magnitude of the target variable, and equal-frequency quartile intervals are defined. Random sampling is performed within each interval at a fixed ratio. The sampled samples are merged to generate corresponding training and test sets, ensuring consistency in the distribution of the target spatial data before and after sample segmentation.
[0036] In step S30, an extreme gradient boosting model is constructed. In a preferred embodiment, monotonicity constraints are set for some input features, and hyperparameter optimization is performed based on the Optuna framework combined with the tree-structured Parzen estimator algorithm. The model construction and hyperparameter tuning module uses the 12-dimensional input feature vector from the training set as the model input and the measured values of stable isotope abundance of nitrate nitrogen as the supervision label to establish the extreme gradient boosting model. In a preferred embodiment, based on the contribution directions between nitrate nitrogen, ammonium nitrogen, and the target variable in the training data, and combined with the biogeochemical priors of nitrate source mixing and nitration fractionation processes, positive monotonic constraints are set for nitrate nitrogen features, negative monotonic constraints are set for ammonium nitrogen features, and no monotonicity constraints are imposed on other input features. Subsequently, the Optuna framework combined with the tree-structured Parzen estimator algorithm is used to automatically optimize the hyperparameters of the extreme gradient boosting model with the minimum root mean square error of five-fold cross-validation as the objective function, and the optimal hyperparameter combination is output to complete the model finalization.
[0037] In step S40, the SHAP contribution value is calculated, key environmental factors are screened, and a biogeochemical mapping relationship is established. The test set is input into the finalized extreme gradient boosting model, and the SHAP algorithm is used to calculate the SHAP contribution value of 12 input features to the prediction results of each sample. The absolute value of the SHAP contribution value of the same input feature in each test sample is taken and averaged to obtain the mean absolute SHAP value of that input feature. The input features are sorted from largest to smallest according to the mean absolute SHAP value, and key environmental factors are screened. Based on the positive and negative directions of the SHAP contribution values of the key environmental factors, a biogeochemical mapping relationship is established between them and nitrification, denitrification, and nitrate source mixing.
[0038] In step S50, data from the unknown water body sample is acquired, and the abundance of nitrate nitrogen stable isotopes is predicted using the final prediction model. The model prediction module acquires 10 routine water quality monitoring data points and the sampling month for the unknown water body sample. Based on the monthly periodic coding rules of step S10, it generates monthly sine and cosine periodic coding values, which, together with the 10 routine water quality monitoring data points, form a 12-dimensional input feature vector. Subsequently, this 12-dimensional input feature vector is input into the final prediction model, which has been finalized in step S30 and interpreted and verified in step S40, and outputs the predicted abundance value of nitrate nitrogen stable isotopes for the unknown water body sample.
[0039] The following provides a detailed explanation of the internal implementation principles and technical details of each step and core module of this invention. The predicted values in this paper refer to the predicted abundance values of stable isotopes of nitrate nitrogen output by the extreme gradient boosting model, and the mean absolute SHAP value is the average of the absolute values of the SHAP contribution values of the same input feature in each test sample. The measured values of the target variable are the measured abundance values of stable isotopes of nitrate nitrogen determined by stable isotope mass spectrometry.
[0040] Reference Figure 3 In the flow of this prediction method, step S10 is executed by the system's data acquisition module to acquire multidimensional basic data of the water sample and reconstruct its time-series characteristics. Step S10 includes the following sub-steps: S11: Obtain routine water quality monitoring data from water samples in the study area, and simultaneously extract the corresponding measured values of the target variable and sampling time. The data acquisition module connects to the on-site multi-parameter water quality monitoring equipment and the laboratory analysis terminal, collecting routine water quality monitoring data including 10 environmental physicochemical indicators. The 10 routine water quality parameters are water temperature, dissolved oxygen, conductivity, turbidity, chlorophyll a, total nitrogen, nitrate nitrogen, nitrite nitrogen, ammonium nitrogen, and total organic carbon. The actual sampling date record for each sample is also extracted. To provide supervision signals for subsequent model training, the measured values of stable isotope abundance of nitrate nitrogen for each water sample, determined by stable isotope mass spectrometry, are obtained and used as the measured value of the target variable.
[0041] S12 extracts calendar month information based on the sampling date of water samples and constructs monthly periodic coding features through trigonometric function transformation. The biochemical reaction mechanisms of natural aquatic environments often exhibit significant seasonal periodicity. Conventional machine learning data preprocessing methods typically use the numbers 1 to 12 to represent calendar months, but this linear coding suffers from jumps in numerical calculations. For example, December and January of the following year are adjacent in time cycle, but the absolute distance between their feature values spans 11 seconds. This spatial misalignment may cause the model to learn time distance features that do not conform to the monthly periodic relationship. To solve this problem, the data acquisition module introduces sine and cosine mathematical transformations to map linear calendar months into continuous periodic feature components. The specific calculation formula is as follows: ; ; In the formula, The sine cycle code value for the month; The calendar month of the sampling time, with a value ranging from 1 to 12; This is the cosine period encoding value for the month; Pi is a constant. In principle, by substituting the integer months from 1 to 12 into the sine and cosine formulas, a set of corresponding numerical coordinate points can be obtained in a two-dimensional feature space. In this feature space, the coordinate distance between December and January of the following year is effectively shortened, eliminating numerical discontinuities in linear encoding, thus allowing the data to truly reflect the physical process of the natural cycle of months.
[0042] S13, concatenate the periodic coding features with routine water quality monitoring data to construct the input feature vector. After calculating the time periodic coding value, the data acquisition module horizontally concatenates it with the 10 routine water quality monitoring data obtained in step S11 to generate a 12-dimensional input feature vector for a single water body sample. Subsequent steps in this scheme employ a tree-structured extreme gradient boosting algorithm framework to construct the model. The node splitting gain calculation of the tree model mainly relies on the relative size order of feature values and is generally insensitive to the absolute dimensions and numerical span of the input features. When constructing this 12-dimensional input feature vector, the system may not require standardization or normalization as a necessary step, directly using the original physical measurement values and monthly periodic coding values to construct the feature matrix to meet the input requirements of the extreme gradient boosting model. In an optional implementation, for missing values in the training samples, the system uses the historical mean or linear interpolation method from the same monitoring section to fill in the missing values; for outliers that significantly exceed the physical norms or sensor range, the system removes or smooths them according to preset range limits. The preprocessing rules remain consistent during the model training phase and the unknown water body sample prediction phase. The specific operational procedures for collecting multiple water quality parameters and measuring isotopes are well-known technologies in this field and will not be elaborated here.
[0043] After acquiring data and constructing feature vectors, the dataset needs to be appropriately partitioned for model training. (Refer to...) Figure 4 In the flow of this prediction method, step S20 is executed by the system's dataset partitioning module, which performs hierarchical quartile random dataset partitioning based on the target variable to construct the training and test sets. Step S20 includes the following sub-steps: S21: Based on the measured target variable, all samples are numerically sorted, and the sorted data is equally divided into six quartile intervals. When performing machine learning modeling on small sample datasets such as water isotopes, the global random partitioning method often results in differences in the probability distribution of the target variable between the training and test sets due to uneven sampling, thus affecting the stability of the model evaluation results. To improve this problem, the dataset partitioning module introduces a target spatial distribution constraint mechanism. The system reads the measured values of the target variable from all water samples and sorts all sample records in ascending order according to the magnitude of the target variable. After sequence recombination, the system equally divides all samples sorted by the target variable values into six quartile intervals. When the total number of samples is not divisible by 6, the system allocates the remaining samples to the corresponding quartile intervals according to a preset order to ensure that all original samples are included in the partitioning process. Dividing into six intervals is an engineering balance achieved between refining the granularity of the target variable distribution and ensuring the sample size of each interval, avoiding the problem of too many intervals leading to sparse sub-interval samples that cannot support subsequent sampling operations.
[0044] S22, within each quartile interval, perform random sampling without replacement at a predetermined ratio, merging the samples to generate training and test sets. After establishing six independent data subspaces, the dataset partitioning module performs stratified sampling within each quartile interval. The system independently performs random sampling without replacement within each quartile interval, splitting the samples within the interval into training and test subsets at a ratio of 80%:20%. After sampling across all six intervals, the training subsets are merged to form the global training set, and the test subsets are merged to form the global test set. This combination of target variable sorting and stratified sampling within intervals ensures that the partitioned training and test sets maintain a consistent probability density distribution and data boundaries for the target variable, avoiding extreme values existing only in a single set, and providing an objective validation basis for subsequent model development. In a preferred embodiment, the dataset partitioning module sets a fixed random seed during random sampling to ensure the reproducibility of the training and test set partitioning results.
[0045] After successfully building the training and test sets, the core prediction model building phase begins. (Refer to...) Figure 5 In the flow of this prediction method, step S30 is executed by the system's model building and parameter tuning module. Step S30 includes the following sub-steps: S31. Establish the extreme gradient boosting model architecture and set the initial training flow. Since environmental water quality data typically exhibits nonlinear characteristics and complex interactions between various detection indicators, the model construction and parameter tuning module uses the extreme gradient boosting model as the prediction model. Regarding data flow and connectivity, the 12-dimensional input feature vector from the training set is input into the extreme gradient boosting model. The model uses multiple classification and regression trees to split and judge sample features, outputting the corresponding prediction results. In the training and update step, the model adopts an additive training strategy, meaning that each subsequently generated decision tree is fitted with the error between the prediction results from the previous model integration and the actual measured isotope abundance values as the training objective. The system uses the acquired training set features as input data and the corresponding measured values as supervision labels, calculating the mean squared error loss function. After training a set number of tree models, the system sums the weight values output by all decision trees, and the result is the predicted value of nitrate nitrogen stable isotope abundance for the target water sample.
[0046] S32, in a preferred embodiment, feature monotonicity constraints are introduced based on biogeochemical principles. To reduce local fluctuations in the model that do not conform to empirical biogeochemical rules in sparse sample regions, the model building and parameter tuning module transforms domain prior knowledge into an algorithm parameter constraint mechanism. In a preferred embodiment, based on the variation relationship between nitrate nitrogen, ammonium nitrogen, and the abundance of stable isotopes of nitrate nitrogen in the training data, and combined with the biogeochemical priors of nitrate source mixing and nitration fractionation processes, the direction of monotonicity constraints for nitrate nitrogen and ammonium nitrogen features is determined. At the algorithm's underlying level, the model building and parameter tuning module sets nitrate nitrogen features as positive monotonic constraints and ammonium nitrogen features as negative monotonic constraints. For input features other than nitrate nitrogen and ammonium nitrogen in the 12-dimensional input feature vector, the monotonicity constraint parameter is set to 0, indicating that no monotonicity restriction is applied. In the specific code implementation, this constraint condition directly intervenes in the node splitting process of the underlying classification and regression tree. When the algorithm calculates the feature splitting gain and generates left and right child nodes, if the current splitting feature is subject to a positive monotonic constraint, the algorithm restricts the model weight value output by the right child node with the larger feature value to be no less than the output weight value of the left child node; if it is subject to a negative monotonic constraint, the opposite numerical restriction is applied. This control logic restricts the output direction of the leaf nodes corresponding to the constrained features, reducing prediction fluctuations in the local feature space that do not conform to empirical biogeochemical laws.
[0047] S33, using a surrogate model and Bayesian optimization algorithm to perform hyperparameter iterative shaping. After completing the basic structural constraints, the macroscopic hyperparameters in the model need to be optimized. The model building and hyperparameter tuning module, in conjunction with the Optuna optimization framework and the tree-structured Parzen estimator algorithm, performs automatic parameter search. The system presets the search space boundaries for hyperparameters, for example, setting the number of decision trees to range from 100 to 1000, the learning rate to range from 0.01 to 0.3, and the maximum tree depth to range from 3 to 10. In a preferred embodiment, the hyperparameter search space also includes the subsample sampling ratio, column sampling ratio, L1 regularization coefficient, L2 regularization coefficient, minimum child node weight, and minimum loss decrease value for node splitting. The subsample ratio and column sample ratio range from 0.6 to 1.0, the L1 regularization coefficient ranges from 0 to 10, the L2 regularization coefficient ranges from 0.1 to 10, the minimum child node weight ranges from 1 to 10, and the minimum loss reduction value for node splitting ranges from 0 to 0.5. The system evaluates the hyperparameter combination of the extreme gradient boosting model with the objective function of minimizing the root mean square error of five-fold cross-validation.
[0048] Based on the principle of iterative optimization, the tree-structured Parzen estimator algorithm uses a probabilistic model for guided sampling of the parameter space. The system sets a preset quantile threshold based on the root mean square error (RMSE) performance obtained from historical evaluations, for example, the top 20% of best-performing parameters in history. Parameter sets below this error threshold are used to construct probabilistic density functions that perform well, while parameter sets above the threshold are used to construct probabilistic density functions that perform poorly. By calculating the ratio of these two probability density functions and maximizing the expected improvement, the system calculates the hyperparameter values that are more likely to reduce the RMSE in the next iteration. In a preferred embodiment, the preset number of iterations is 50 to 200, more preferably 100. After the preset number of iterations, the model building and parameter tuning module outputs the hyperparameter combination that minimizes the RMSE and sets this hyperparameter combination into the extreme gradient boosting model, completing the prediction model finalization; in a preferred embodiment, this hyperparameter combination is set into an extreme gradient boosting model with monotonicity constraints. The underlying computational mechanism of the extreme gradient boosting model, based on second-order Taylor expansion, is well-known in the art and will not be elaborated here.
[0049] After the extreme gradient boosting model is initially finalized, feature contribution analysis is needed to reveal the model's internal decision-making logic and verify its conformity to geochemical laws. (Refer to...) Figure 6 In the flow of this prediction method, step S40 is executed by the system's model interpretation module. Step S40 includes the following sub-steps: S41 introduces the SHAP algorithm to calculate SHAP contribution values and statistically analyzes the mean absolute SHAP values to screen key environmental factors. After model finalization, the inference logic of the extreme gradient boosting model is hidden due to its ensemble structure of numerous decision trees. To extract the influence weights of each environmental factor on the prediction results, the model interpretation module uses the SHAP mechanism to perform feature decoupling calculations. The basic principle of this mechanism is to treat all input features as independent contributors to the prediction process. By calculating the expected change in the model's predicted output before and after adding a feature to the feature combination, the independent contribution of that feature is evaluated. Specifically, the final predicted output value of the model is decomposed into the linear sum of the model's basic predicted expected value on all training samples and the SHAP contribution values of all 12 input features, thereby obtaining the direction and magnitude of each input feature's contribution to the prediction result of a single sample.
[0050] After calculating the SHAP contribution values of all test set samples, the model interpretation module takes the absolute value of the SHAP contribution values of the same input feature in each test sample and averages them to obtain the mean absolute SHAP value of that input feature. The system sorts the 12 input features from largest to smallest mean absolute SHAP value and filters key environmental factors based on the sorting results. In a preferred embodiment, the system extracts the features with the highest mean absolute SHAP values as key environmental factors. Further, when the model learning results meet the preset feature contribution constraints, at least some of the features among conductivity, ammonium nitrogen, nitrate nitrogen, total nitrogen, and nitrite nitrogen are identified by the system as key environmental factors. More preferably, the system verifies that the mean absolute SHAP values of conductivity, ammonium nitrogen, nitrate nitrogen, total nitrogen, and nitrite nitrogen are among the top five of the 12 input features.
[0051] S42, establish a biogeochemical mapping correspondence based on the directional sign of the SHAP contribution value. Integrated tree models typically only output predicted values. To support practical applications of environmental pollution source apportionment, the model interpretation module, after extracting key environmental factors and their corresponding SHAP contribution values, establishes a mapping relationship between data attribution and biogeochemical processes based on the positive and negative directions of the SHAP contribution values. The system uses the mean or median of each key environmental factor in the entire test set as a benchmark to analyze the relative magnitude of characteristic physical observations and the directional relationship between their SHAP contribution values, establishing mapping rules for the following three typical mechanisms: In water bodies where nitrification occurs, a mapping is established between ammonium nitrogen characteristics and nitrification kinetic fractionation. When the ammonium nitrogen concentration characteristic value is higher than the set benchmark and its corresponding SHAP contribution value shows a negative sign, the system maps this negative SHAP contribution value to the kinetic isotopic fractionation in the nitrification process, i.e., a biogeochemical process that may reduce the predicted value of stable isotopic abundance of nitrate nitrogen during the conversion of ammonium nitrogen to nitrate.
[0052] In water body scenarios with external pollution input, a mapping is established between nitrate nitrogen characteristics and anthropogenic end-member mixing processes. When the nitrate nitrogen concentration characteristic value is higher than the set benchmark and its corresponding SHAP contribution value is positive, the system maps this positive SHAP contribution value to a nitrate source mixing scenario dominated by anthropogenic input of high nitrogen 15 isotopes, such as a situation where end-member inputs like domestic sewage or livestock manure lead to an increase in nitrate nitrogen concentration accompanied by an increase in the predicted abundance of stable nitrate nitrogen isotopes.
[0053] In water bodies where denitrification occurs, a mapping is established between dissolved oxygen characteristics and the denitrification isotope enrichment process. When the dissolved oxygen characteristic value is lower than a set baseline, it indicates that the water body is in a relatively anoxic state. If the SHAP contribution value corresponding to the low dissolved oxygen state is positive, it means that this characteristic state contributes to increasing the predicted value of nitrate nitrogen stable isotope abundance. The system maps this correspondence to the denitrification isotope enrichment process, that is, a biogeochemical process that may contribute to increasing the predicted value of nitrate nitrogen stable isotope abundance under relatively anoxic conditions. By executing judgment rules, the model interpretation module transforms the mathematical SHAP contribution value into a biogeochemical mechanism interpretation with practical business significance.
[0054] In a preferred embodiment, when the selected key environmental factors and their SHAP contribution directions satisfy the preset biogeochemical mapping relationship of nitrification, denitrification, and nitrate source mixing, the finalized extreme gradient boosting model is determined as the final prediction model and used for prediction of unknown water samples. If the selected key environmental factors and their SHAP contribution directions do not satisfy the preset biogeochemical mapping relationship, the process returns to step S30, and the extreme gradient boosting model is retrained after adjusting the hyperparameter search range or monotonicity constraint settings.
[0055] After completing the interpretation, verification, and mechanism confirmation of the finalized prediction model, it can be deployed for practical online monitoring and inference. (Refer to...) Figure 7 In the flow of this prediction method, step S50 is executed by the system's model prediction module. Step S50 includes the following sub-steps: S51, Preprocessing and forward inference calculations are performed on the characteristics of the unknown water body samples. During the actual operational deployment phase, the model prediction module receives basic physicochemical data of the unknown water body samples from the monitoring terminal. To ensure that the input format of the unknown water body samples remains consistent with that of the model training phase, the system calls the same feature transformation rules as in the training phase to clean and transform the newly received sample data. For missing values caused during sensor transmission, the system uses the historical mean of the monitoring section or linear interpolation to fill in the missing values; for outliers that significantly exceed physical norms, such as negative concentrations, the system removes or smooths them according to preset sensor range limits. After cleaning, the system synchronously calculates the corresponding derived feature variables, thereby constructing a 12-dimensional input feature vector consistent with the dimensions of the training phase. Subsequently, the system imports this input feature vector into the final prediction model; in a preferred embodiment, the final prediction model is an extreme gradient boosting model with monotonicity constraints. During the inference process, the finalized extreme gradient boosting model uses the 12-dimensional input feature vector of the unknown water sample to integrate and predict multiple internal classification and regression trees, and outputs the predicted abundance of stable nitrate nitrogen isotopes for that unknown water sample. Through the forward inference link, the system obtains the predicted abundance of stable nitrate nitrogen isotopes for the unknown water sample in a pure computational mode, serving as an effective supplement to stable isotope mass spectrometry detection.
[0056] S52 executes operational applications for high-frequency online monitoring and data interpolation. Conventional nitrogen stable isotope determination relies on isotope ratio mass spectrometry, which suffers from high analysis costs and long testing cycles, limiting its application in large-scale watershed real-time monitoring. After obtaining the predicted values, the model prediction module applies them to typical environmental engineering scenarios. In the scenario of maintaining a historical environmental monitoring database, for records with complete conventional water quality parameters but missing nitrate nitrogen stable isotope abundance data, the system uses batch processing mode to call inference logic to numerically interpolate the missing nitrate nitrogen stable isotope abundance data to restore the integrity of the historical monitoring sequence. In the scenario of high-frequency tracking of watershed pollution sources, the system establishes data communication connections with conventional online water quality monitoring sensors deployed at river cross-sections. Parameters such as temperature, dissolved oxygen, and conventional nitrogen collected by conventional sensors are transmitted to the model prediction module in real time at a set time frequency. The system synchronously calculates and outputs the corresponding predicted values of nitrate nitrogen stable isotope abundance, thereby assisting in determining the current changes in the source of nitrate in the water and its biogeochemical transformation processes. At the engineering implementation boundary level, to avoid significant errors caused by extrapolating predictions within unobserved data ranges, the system incorporates data distribution boundary judgment logic. When any input feature value of an unknown water sample exceeds the value range of the corresponding feature in the training set, the model prediction module generates and attaches a low-confidence warning flag while outputting the predicted value, prompting operational personnel to pay attention to the reliability of the prediction result. This ensures the logical completeness and security of the algorithm in practical applications. The data acquisition interface settings and remote communication transmission protocol parsing of the online water quality monitoring sensor are well-known technologies in this field and will not be elaborated upon here.
[0057] Specific application examples: This specific application example is built upon a machine learning prediction system for identifying nitrate pollution sources in water bodies and for routine water quality monitoring. The system operates within a key watershed monitoring network in a certain city, responsible for acquiring routine water quality monitoring data and performing a closed-loop prediction of nitrate nitrogen stable isotope abundance.
[0058] During the data acquisition and periodic encoding phase, the data acquisition module extracts the sampled month data and calculates the month's sinusoidal periodic encoding value. The parameters are set as follows: Pi is set as a constant. The value is 3.14159, which represents the calendar month extracted from the sample sampling time. The value is 8. The data acquisition module substitutes the values into the formula to calculate the sinusoidal period code value for the month. : ; Substitute the values into the calculation: ; The results show that the system obtained a sinusoidal periodic code value of -0.866 for the month. The preset legal feature range for the periodic code is -1 to 1. Since the calculated sinusoidal periodic code value for the month falls within the legal feature range and meets the judgment condition, the data acquisition module determines that the one-sided periodic feature extraction was successful, and the system enters it into the feature cache area.
[0059] When completing the periodic feature, the system re-executes the feature parsing step. The parameters are set as follows: Pi is set as a constant. The value is 3.14159, which represents the calendar month extracted from the sample sampling time. The value is 8. The data acquisition module substitutes the values into the formula to calculate the cosine cycle encoding value for the month. : ; Substitute the values into the calculation: ; The results show that the cosine periodic encoding value of the month obtained by the system is -0.500. The preset legal feature range of the periodic encoding is -1 to 1. Since the calculated cosine periodic encoding value of the month is within the legal feature range, it meets the judgment condition, and the data acquisition module determines that the construction of the dual-period component is complete. The system performs the above operation on multiple historical water body sample data in batches, and horizontally concatenates the two periodic encoding features of each sample with its 10 conventional water quality monitoring data to successfully construct a 12-dimensional input feature vector set for all samples. Subsequently, the dataset partitioning module performs stratified quartile random partitioning of all samples according to the measured value of the target variable to generate training and test sets. The system inputs the training set into an extreme gradient boosting model with monotonicity constraints, and completes parameter shaping in conjunction with the Optuna framework.
[0060] During the key environmental factor screening stage, the model interpretation module calculates the mean absolute SHAP value by combining the test set inference data.
[0061] The parameters are set as follows: the total number of test set samples is set to 60, and the SHAP contribution value of each test sample in the test set to the ammonium nitrogen characteristics is obtained.
[0062] The model interpretation module calculates the mean absolute SHAP value according to the system's built-in operation rules: the absolute value of the SHAP contribution value of the same input feature in each test sample is taken and averaged.
[0063] Substituting the values into the calculation: the absolute values of the ammonium nitrogen SAP contribution values of the 60 test samples are summed to get 85.2, which is divided by the total number of samples 60, equals 1.42.
[0064] The results showed that the mean absolute SHAP value of ammonium nitrogen obtained by the system was 1.42. The model interpretation module sorted all input features from largest to smallest according to the mean absolute SHAP value. Since the calculated mean absolute SHAP value of ammonium nitrogen ranked among the top five of all features (e.g., second), it met the judgment criteria, and the model interpretation module confirmed that ammonium nitrogen was a key environmental factor. Furthermore, the system detected that the ammonium nitrogen concentration feature value of this batch of water samples was higher than the baseline, and its corresponding SHAP contribution value showed a negative sign. The system executed the mapping rule and successfully mapped the negative SHAP contribution value to nitrification kinetic fractionation. Finally, the system generated and output predicted values of stable isotope abundance of nitrate nitrogen containing biogeochemical mapping relationships.
[0065] To verify the accuracy and stability of the extreme gradient boosting model with monotonicity constraint mechanism during system operation, the system compared and output the error and prediction data of multiple model architectures under the same test set environment.
[0066] Reference Figure 8 , Figure 8 The horizontal axis represents the ascending sequence number of the test set samples, and the vertical axis represents the abundance of stable isotopes of nitrate nitrogen. In the figure, the conventional machine learning system, lacking a monotonicity constraint mechanism, exhibits abnormal fluctuations in its predicted values, frequently deviating from the observed trends. In contrast, the system of this invention, employing a monotonicity constraint mechanism, shows its predicted values closely following the trend of the observed value's line of variation. This result verifies the ability of this invention to improve the model's prediction accuracy and consistency with geochemical laws.
[0067] Based on the completion of prediction accuracy verification, in order to further verify the effectiveness of the mechanism explanation of the present invention under environmental factor attribution, the analytical results of different algorithms under feature importance evaluation were compared.
[0068] Reference Figure 9 , Figure 9 The horizontal axis represents the mean absolute SHAP value, and the vertical axis represents key environmental factors. The conventional ensemble tree system in the figure, lacking a model interpretation mechanism, exhibits a black-box-like distribution of feature influence weights in the graph, making it impossible to pinpoint the core driving factors. In contrast, the system of this invention, by introducing the SHAP algorithm to calculate contribution values, shows a stable distribution of the mean absolute SHAP values for nitrate nitrogen and ammonium nitrogen, indicating their dominance. This result verifies the ability of this invention to screen key environmental factors and establish biogeochemical mapping relationships.
[0069] In addition, to demonstrate the reliability of the model's generalization ability in business applications, the system statistically analyzed the prediction error status under different data partitioning methods.
[0070] Reference Figure 10 , Figure 10 The horizontal axis represents the prediction error evaluation index, and the vertical axis represents the error value. In the figure, the conventional system, due to its global random partitioning, suffers from uneven distribution of extreme value samples, resulting in a generally high root mean square error (RMSE) of 1.65. In contrast, the system of this invention, by employing a dataset partitioning module to extract the measured values of the target variable, reorganizing them into a hierarchical quartile structure using equal frequencies, and then calling the Optuna framework combined with a tree-structured Parzen estimator to perform hyperparameter optimization, exhibits an excellent RMSE distribution as low as 0.82. This result verifies the technical advantages of this invention in ensuring the generalization and reliability of model inference under complex nonlinear water quality data conditions.
Claims
1. A machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water, characterized in that, include: Obtain routine water quality monitoring data, sampling month, and measured values of nitrate nitrogen stable isotope abundance from water samples; construct monthly periodic coding features and form an input feature vector; wherein, the routine water quality monitoring data includes nitrate nitrogen features, ammonium nitrogen features, and dissolved oxygen features; Based on the measured abundance values of stable nitrate nitrogen isotopes, a hierarchical quartile random dataset was divided to construct training and test sets. Based on the training set and the Optuna framework, combined with the tree-structured Parzen estimator algorithm, an extreme gradient boosting model was determined. Based on the test set, the SHAP contribution value is calculated, key environmental factors are screened, and biogeochemical mapping relationships are established to determine the final prediction model. Obtain routine water quality monitoring data and sampling month for unknown water body samples, construct input feature vectors for unknown water body samples, input them into the final prediction model, and output predicted values of nitrate nitrogen stable isotope abundance.
2. The machine learning method for predicting the abundance of stable nitrate nitrogen isotopes in water bodies according to claim 1, characterized in that, The method involves acquiring routine water quality monitoring data, sampling month, and measured values of nitrate nitrogen stable isotope abundance from water samples, constructing monthly periodic coding features, and forming an input feature vector, including: The water temperature, dissolved oxygen, conductivity, turbidity, chlorophyll a, total nitrogen, nitrate nitrogen, nitrite nitrogen, ammonium nitrogen, and total organic carbon of the water sample are obtained as the routine water quality monitoring data. After multiplying the ratio of the sampled month to 12 by 2π, the sine and cosine values are calculated respectively to obtain the sine periodic code value and the cosine periodic code value of the month as the periodic code feature of the month; The input feature vector is formed by horizontally concatenating the sine cycle encoding value and the cosine cycle encoding value of the month with the conventional water quality monitoring data.
3. The machine learning method for predicting the abundance of stable nitrate nitrogen isotopes in water bodies according to claim 1, characterized in that, The step involves partitioning a stratified quartile random dataset based on the measured abundance values of nitrate nitrogen stable isotopes to construct training and testing sets, including: The water samples were sorted in ascending order based on the measured values of nitrate nitrogen stable isotope abundance. The sorted water samples are divided into six quartile intervals with equal frequency. Random sampling without replacement is performed independently within each quartile interval, and the samples are split into training and test subsets in a ratio of 80%:20%. The training set is formed by merging all the training subsets of the aforementioned quartile intervals, and the test set is formed by merging all the test subsets of the aforementioned quartile intervals.
4. The machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water bodies according to claim 1, characterized in that, The extreme gradient boosting model based on the training set and the Optuna framework combined with the tree-structured Parzen estimator algorithm includes: The extreme gradient boosting model includes a classification regression tree. During the node splitting process of the classification regression tree, a positive monotonic constraint is set for the nitrate nitrogen feature, a negative monotonic constraint is set for the ammonium nitrogen feature, and no monotonicity constraint is imposed on other features in the input feature vector, which serves as a preset monotonicity constraint. The search space boundary of the Optuna framework combined with the tree structure Parzen estimator algorithm is defined, and the minimum root mean square error of five-fold cross-validation is taken as the objective function. The hyperparameters are automatically optimized by iteratively using the Optuna framework combined with the tree structure Parzen estimator algorithm. The optimal hyperparameter combination is output and applied to the extreme gradient boosting model to complete the modeling.
5. The machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water according to claim 4, characterized in that, The method of using the Optuna framework combined with the tree-structured Parzen estimator algorithm to perform hyperparameter iterative automatic optimization includes: Based on the root mean square error performance obtained from historical evaluations during the automatic optimization process of hyperparameter iteration, a preset proportion of quantile thresholds is set. A probability density function with good performance is constructed based on hyperparameter combinations below the quantile threshold, and a probability density function with poor performance is constructed based on hyperparameter combinations above the quantile threshold. Calculate the ratio of the well-performing probability density function to the poorly performing probability density function, and determine the hyperparameter values for the next iteration based on the ratio.
6. The machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water according to claim 4, characterized in that, The calculation of SHAP contribution values based on the test set and the screening of key environmental factors include: The test set is input into the finalized extreme gradient boosting model, and the SHAP algorithm is used to calculate the SHAP contribution value of each feature in the input feature vector to the prediction result of each water sample in the test set. The absolute value of the SHAP contribution value of each of the aforementioned features in each of the aforementioned water samples in the test set is taken and averaged to obtain the mean absolute SHAP value of each of the aforementioned features. The features in the input feature vector are sorted from largest to smallest according to the mean absolute SHAP value, and the top preset number of features are selected as key environmental factors.
7. The machine learning method for predicting the abundance of stable nitrate nitrogen isotopes in water according to claim 6, characterized in that, The process of screening key environmental factors and establishing biogeochemical mapping relationships to determine the final prediction model includes: The average or median of each of the key environmental factors in the test set is used as a benchmark. The relative magnitude of the values of each of the key environmental factors in each of the water samples in the test set with the benchmark is analyzed, as well as the positive and negative directional relationship of the SHAP contribution values of each of the key environmental factors. When the key environmental factors selected, the relative magnitudes of the key environmental factors and the benchmark, and the positive and negative directions of the SHAP contribution values of the key environmental factors all satisfy the preset biogeochemical mapping relationship, the finalized extreme gradient boosting model is determined as the final prediction model. If the preset biogeochemical mapping relationship is not met, the search space boundary of the Optuna framework combined with the tree structure Parzen estimator algorithm or the preset monotonicity constraint is adjusted, and the extreme gradient boosting model is redefined.
8. The machine learning method for predicting the abundance of stable nitrate nitrogen isotopes in water according to claim 7, characterized in that, The biogeochemical mapping relationship includes at least one of the following types of mapping rules: When key environmental factors include ammonium nitrogen characteristics, and the values of ammonium nitrogen characteristics are higher than the baseline and the SHAP contribution value corresponding to the ammonium nitrogen characteristics is negative, it is mapped to the kinetic isotope fractionation effect in the nitrification process. When the key environmental factor includes nitrate nitrogen features, and the value of the nitrate nitrogen features is higher than the baseline and the SHAP contribution value corresponding to the nitrate nitrogen features is positive, it is mapped to a mixed nitrate source scenario dominated by anthropogenic input. When key environmental factors include dissolved oxygen characteristics, and the value of the dissolved oxygen characteristic is lower than the baseline and the SHAP contribution value corresponding to the dissolved oxygen characteristic is positive, it is mapped to a denitrification isotope enrichment process.
9. The machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water according to claim 1, characterized in that, The process of obtaining routine water quality monitoring data and sampling month for unknown water body samples, constructing input feature vectors for unknown water body samples, inputting these vectors into the final prediction model, and outputting predicted values for nitrate nitrogen stable isotope abundance includes: Obtain routine water quality monitoring data for the unknown water body sample and the sampling month of the unknown water body sample; Based on the sampling month of the unknown water body sample, a monthly periodic coding feature of the unknown water body sample is constructed. The regular water quality monitoring data of the unknown water body sample is concatenated with the monthly periodic coding feature of the unknown water body sample to form an unknown water body sample input feature vector with the same dimension as the input feature vector. This input feature vector is then input into the final prediction model. The final prediction model is used to make predictions and output the predicted value of the nitrate nitrogen stable isotope abundance.
10. The machine learning method for predicting the abundance of stable isotopes of nitrate nitrogen in water according to claim 9, characterized in that, After outputting the predicted abundance values of stable nitrate nitrogen isotopes, the method further includes: Determine whether the value of any feature in the input feature vector of the unknown water sample exceeds the value range of the same feature in the training set. If so, generate and attach a low confidence warning label while outputting the predicted abundance value of nitrate nitrogen stable isotopes.
