Water quality index prediction model training method, water quality index detection method and device
By using a multi-output ridge regression model and multimodal data processing, the problems of overfitting and data leakage in high-dimensional spectral modeling in water quality inversion were solved, and efficient water quality index prediction and anomaly detection were achieved.
Patent Information
- Application Number
- CN202611314919.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-27
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technologies are prone to overfitting and data leakage risks when performing high-dimensional spectral modeling in water quality inversion, especially under small sample conditions, which affects the reliability of water quality assessment results.
A multi-output ridge regression model was used to train a water quality index prediction model. The optimal regularization hyperparameter was determined by K-fold cross-validation and inner-layer cross-validation. Combined with the preprocessing and feature splicing of multimodal sensing data, a multimodal fusion feature vector was constructed to suppress overfitting and avoid data leakage.
It effectively suppresses overfitting in high-dimensional spectral modeling with small samples, improves the accuracy and stability of water quality index prediction, provides reliable residual distribution parameters, and provides a statistical basis for water quality anomaly detection.
Smart Images

Figure CN123158218A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of water quality testing technology, specifically to a method for training a water quality index prediction model, a method for testing water quality indicators, and an apparatus. Background Technology
[0002] Online monitoring of the water environment is an important technical support for water environment management and water quality assessment. Ultraviolet-visible spectroscopy inversion technology is widely used for multi-parameter detection of water bodies due to its advantages of not requiring chemical reagents and being able to detect quickly online.
[0003] Water quality inversion schemes based on related technologies typically focus on single-spectral mode processing. However, in actual water quality monitoring scenarios, the number of water samples that can complete the true value calibration of all indicators is usually small. This is a typical scenario of small sample high-dimensional modeling. The spectral module outputs thousands of high-dimensional spectral data. Direct modeling is prone to overfitting. The statistical parameters for preprocessing and feature extraction are calculated directly using the entire dataset, which poses a risk of data leakage and affects the credibility of water quality assessment results. Summary of the Invention
[0004] This invention provides a method for training a water quality index prediction model, a method for detecting water quality indexes, and an apparatus to address the problems of overfitting and data leakage risks in high-dimensional spectral modeling under small sample conditions in water quality inversion.
[0005] In a first aspect, the present invention provides a method for training a water quality index prediction model, wherein the water quality index prediction model is trained using a multi-output ridge regression model, and the method includes: A water sample dataset is constructed, which includes sample data of each water sample. The sample data of each water sample includes multimodal sensing data of the water sample and multiple water quality index labels of the water sample. The multimodal sensing data includes spectral mode data, electrochemical mode data and optical turbidity mode data. K-fold cross-validation was used to divide the water sample dataset, resulting in training and test fold sample sets for each iteration. In each iteration, the multimodal sensing data of each training sample in this iteration are preprocessed to generate modal feature vectors corresponding to each modality. Then, the corresponding modal feature vectors are selected according to the currently set input modality combination and concatenated to obtain the multimodal fusion feature vectors corresponding to the training samples. The optimal regularization hyperparameter of the multi-output ridge regression model is determined by inner-layer cross-validation optimization based on the multimodal fusion feature vectors corresponding to each training fold sample. The multi-output ridge regression model is then trained using the optimal regularization hyperparameters and the multimodal fusion feature vectors of each training fold sample. The joint weight matrix and bias vector are then obtained. The multi-output ridge regression model uses the joint weight matrix and bias vector to perform regression prediction on multiple water quality indicators. Obtain the multimodal fusion feature vectors of each test sample in this round, and input the multimodal fusion feature vectors of each test sample into the trained multi-output ridge regression model to output the prediction results of multiple water quality indicators for each test sample in this round. Based on the prediction results and water quality index labels of each test sample output in each iteration, calculate the model evaluation index under the current input mode combination; By resetting different input modality combinations and executing the above iterative training method, model evaluation metrics under different input modality combinations are obtained, and the optimal input modality combination is determined based on the model evaluation metrics corresponding to each group of input modality combinations. The multimodal sensing data of each sample in the water sample dataset are preprocessed and feature splicing is performed according to the optimal input modality combination. The multi-output ridge regression model is retrained to obtain the required water quality index prediction model. At the same time, the preprocessing parameters of each modal sensing data in the preprocessing are extracted, and the residual distribution parameters of each water quality index are statistically obtained based on the prediction results of each sample during the training process.
[0006] In some embodiments, the preprocessing includes: Electrochemical modal data preprocessing: Z-score standardization is performed on the electrochemical modal data of each sample to obtain electrochemical modal feature vectors; the standardized statistics of the electrochemical modes are calculated based on the feature mean and standard deviation of the electrochemical modal data of each sample under each feature dimension, and the preprocessing parameters of the electrochemical modes include the standardized statistics of the electrochemical modes; Optical turbidity mode data preprocessing: Z-score standardization is performed on the optical turbidity mode data of each sample to obtain the optical turbidity mode feature vector; the standardized statistics of the optical turbidity mode are calculated based on the feature mean and standard deviation of the optical turbidity mode data of each sample under each feature dimension, and the preprocessing parameters of the optical turbidity mode include the standardized statistics of the optical turbidity mode. Spectral modal data preprocessing: Savitzky-Golay smoothing, baseline calibration, first derivative processing, and Z-score standardization are performed on the spectral modal data of each sample sequentially. Full-spectrum PCA features, PLS latent variable features, and multi-scale spectral segment features are extracted and concatenated to obtain the spectral modal feature vector. Standardized statistics of the spectral modality are calculated based on the mean and standard deviation of the Z-score standardized spectral modal data for each sample across each feature dimension. The PCA feature projection matrix is calculated based on the Z-score standardized spectral modal data and full-spectrum PCA features for each sample. The PLS feature projection matrix is calculated based on the Z-score standardized spectral modal data and PLS latent variable features for each sample. The preprocessing parameters for the spectral modality include the standardized statistics, PCA feature projection matrix, and PLS feature projection matrix of the spectral modality.
[0007] In some embodiments, the residual distribution parameters of each water quality index obtained statistically from the prediction results of each sample during training include: The prediction residuals for each sample are calculated based on the prediction results and labels of the water quality indicators for each sample during the training process. The residual distribution parameters of various water quality indicators are obtained from the statistical analysis of the prediction residuals of each sample during the training process. The residual distribution parameters include the mean and standard deviation.
[0008] In some embodiments, the step of selecting corresponding modal feature vectors according to the currently set input modality combination and concatenating them to obtain a multimodal fusion feature vector of the training samples includes: If the currently set input mode combination includes a combination of spectral and electrochemical modes, then the spectral mode feature vector and the electrochemical mode feature vector of the training sample are concatenated to obtain the multimodal fusion feature vector of the training sample, or... If the currently set input mode combination includes a combination of spectral mode, electrochemical mode and optical turbidity mode, then the spectral mode feature vector, the electrochemical mode feature vector and the optical turbidity mode feature vector in the training sample are concatenated to obtain the multimodal fusion feature vector in the training sample.
[0009] In some embodiments, the spectral modal data includes absorbance spectra and / or transmittance spectra; The electrochemical mode data includes pH value and / or conductivity; The optical turbidity modal data includes one or more of the following: suspended matter concentration, turbidity, and near-infrared scattering characteristics; The aforementioned water quality indicators include one or more of the following: dissolved oxygen, ammonia nitrogen, permanganate index, total phosphorus, total nitrogen, and chlorophyll a.
[0010] In some embodiments, obtaining the multimodal fusion feature vector of each test sample in this round includes: The electrochemical modal data of the test sample are transformed using the standardized statistics of the electrochemical modes obtained in this round of calculation to obtain the electrochemical modal feature vector of the test sample. The optical turbidity mode data of the test sample are transformed using the standardized statistics of the optical turbidity mode obtained in this round of calculation to obtain the optical turbidity mode feature vector of the test sample. The spectral modal feature vectors of the test sample are obtained by transforming the spectral modal data using the standardized statistics and spectral feature projection matrix of the spectral modalities calculated in this round. Based on the currently set input modality combination, the corresponding modal feature vectors are concatenated to obtain the multimodal fusion feature vector of each test sample.
[0011] In some embodiments, the loss function of the multi-output ridge regression model includes: ; Where X represents the input feature matrix composed of the multimodal fusion feature vectors of each training sample; Y represents the label matrix composed of multiple water quality index labels of each training sample. Let W represent the prediction matrix composed of the predicted values of multiple water quality indicators from each training sample; I is a column vector with all elements equal to 1; W is the joint weight matrix of the model; the first term of the loss function is the squared Frobenius norm of the residual between the label matrix and the prediction matrix, used to measure the overall prediction error of multiple water quality indicators; the second term of the loss function is the L2 regularization term of the joint weight matrix W; α is the regularization hyperparameter of the model, determined through inner cross-validation; b is a bias vector composed of the bias parameters of each water quality indicator, which does not participate in regularization.
[0012] Secondly, the present invention also provides a method for detecting water quality indicators, the method comprising: Acquire multimodal sensing data of the water sample to be tested, including spectral mode data, electrochemical mode data, and optical turbidity mode data of the water sample to be tested; Based on the preprocessing parameters of each mode output during the model training phase, preprocessing is performed on the multimodal sensing data of the water sample to be tested to obtain the feature vectors of each mode of the water sample to be tested. Based on the optimal input mode combination determined during the model training phase, the corresponding modal feature vectors are selected and concatenated to generate a multimodal fusion feature vector for the water sample to be tested. The multimodal fusion feature vector of the water sample to be tested is input into a pre-trained water quality index prediction model, which outputs the predicted values of multiple water quality indicators of the water sample to be tested.
[0013] In some embodiments, the method further includes: Using the residual distribution parameters corresponding to each water quality index output during the model training phase and the predicted residuals of each water quality index of the water sample to be tested, the standardized residuals of each water quality index of the water sample to be tested are calculated; the predicted residuals are the differences between the predicted values of the water quality indexes of the water sample to be tested and the water quality index labels of the water sample to be tested obtained in advance through laboratory measurement. For any water quality indicator, when the absolute value of its standardized residual is greater than a preset threshold, the water quality indicator is determined to be abnormal, and the prediction result and abnormal indicator information are output.
[0014] Thirdly, the present invention also provides a water quality index prediction model training device, wherein the water quality index prediction model is trained using a multi-output ridge regression model, and the water quality index prediction model training device includes: The dataset construction module is used to construct a water sample dataset, which includes sample data of each water sample. The sample data of each water sample includes multimodal sensing data of the water sample and multiple water quality index labels of the water sample. The multimodal sensing data includes spectral mode data, electrochemical mode data and optical turbidity mode data. The dataset partitioning module is used to partition the water sample dataset using K-fold cross-validation to obtain the training fold sample set and the test fold sample set for each iteration round; The preprocessing module is used to preprocess the multimodal sensing data of each training sample in each iteration, generate the modal feature vector corresponding to each modality, and select the corresponding modal feature vector according to the currently set input modality combination for feature concatenation to obtain the multimodal fusion feature vector corresponding to the training sample. The model training module is used to determine the optimal regularization hyperparameter of the multi-output ridge regression model by performing inner-layer cross-validation optimization based on the multimodal fusion feature vectors corresponding to each training fold sample, and to train the multi-output ridge regression model using the optimal regularization hyperparameters and the multimodal fusion feature vectors of each training fold sample, thereby solving for the joint weight matrix and bias vector. The multi-output ridge regression model then performs regression prediction on multiple water quality indicators using the joint weight matrix and bias vector. The model testing module is used to obtain the multimodal fusion feature vectors of each test sample in this round, and input the multimodal fusion feature vectors of each test sample into the trained multi-output ridge regression model to output the prediction results of multiple water quality indicators for each test sample in this round. The model evaluation module is used to calculate the model evaluation index under the current input mode combination based on the prediction results and water quality index labels of each test sample output in each iteration round; to obtain the model evaluation index under different input mode combinations by resetting different input mode combinations and executing the above iteration round training method; and to determine the optimal input mode combination based on the model evaluation index corresponding to each group of input mode combinations. The model training module is also used to preprocess the multimodal sensing data of each sample in the water sample dataset, and to perform feature splicing according to the optimal input modality combination, retrain the multi-output ridge regression model, obtain the required water quality index prediction model, extract the preprocessing parameters of each modal sensing data in the preprocessing, and statistically obtain the residual distribution parameters of each water quality index based on the prediction results of each sample during the training process.
[0015] The water quality index prediction model training method according to embodiments of the present invention constructs a water sample dataset containing multimodal sensing data of spectral, electrochemical, and optical turbidity to achieve unified modeling of high-dimensional spectral and low-dimensional physicochemical auxiliary modes. It employs K-fold cross-validation with in-fold isolation, ensuring that standardized statistics and spectral feature extraction projection matrices are obtained only from training fold samples, thus avoiding data leakage and suppressing overfitting in small-sample high-dimensional spectral modeling. Multi-output ridge regression is used to achieve joint prediction of multiple water quality indicators. Model evaluation indicators are obtained based on test folds, which can be used to compare and evaluate different combinations of input modes and quantitatively determine the true gain of auxiliary modes. Simultaneously, reliable residual distribution parameters are obtained, providing a statistical basis for subsequent water quality anomaly detection. Attached Figure Description
[0016] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0017] Figure 1 This is a schematic diagram of an application scenario according to an embodiment of the present invention; Figure 2 A flowchart illustrating a water quality index prediction model training method provided in an embodiment of the present invention; Figure 3 A schematic flowchart of a water quality index detection method provided in an embodiment of the present invention; Figure 4 This is a structural block diagram of a water quality index prediction model training device provided in an embodiment of the present invention; Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0018] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of 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, 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.
[0019] The terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. In the description of this invention, "a plurality of" means two or more, unless otherwise explicitly specified.
[0020] Figure 1 This is a schematic diagram of an application scenario of an embodiment of the present invention. As an optional application scenario of an embodiment of the present invention, such as... Figure 1 As shown, the water quality indicator detection system may include at least one terminal device and at least one server. Figure 1 The system is illustrated in the example, which includes a computer 101, a mobile terminal 102, and a server 103, and the terminal devices such as the computer 101 and the mobile terminal 102 are connected to the server 103 through a network 110.
[0021] Specifically, the terminal device can be a smartphone, tablet, laptop, PDA, desktop computer, game console, smart TV, smart wearable device, in-vehicle terminal, VR (Virtual Reality) device, AR (Augmented Reality) device, etc. Server 103 can be a standalone physical server, a server cluster, a distributed system, or a cloud server providing cloud services. Network 110 can be a wired or wireless network, examples of which include, but are not limited to, the Internet, corporate intranet, local area network, wide area network, mobile communication network, and combinations thereof.
[0022] According to an embodiment of the present invention, a method for training a water quality index prediction model is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0023] This invention provides a method for training a water quality index prediction model. The water quality index prediction model is trained using a multi-output ridge regression model and can be used in the aforementioned terminal devices or servers. Figure 2 This is a flowchart illustrating a water quality index prediction model training method provided in an embodiment of the present invention, as shown below. Figure 2 As shown, the training method for this water quality index prediction model includes the following steps: Step S201: Construct a water sample dataset. The water sample dataset includes sample data for each water sample. The sample data for each water sample includes multimodal sensing data and multiple water quality index labels for the water sample. The multimodal sensing data includes spectral mode data, electrochemical mode data, and optical turbidity mode data.
[0024] In this embodiment of the invention, the water quality index prediction model is trained based on a small sample (a small number of samples).
[0025] Multiple water samples were collected simultaneously from multiple monitoring sections, resulting in a total of multiple valid water sample data. Among the multimodal sensing data of each sample data, the electrochemical mode outputs low-dimensional physicochemical characteristics such as pH value and conductivity; the optical turbidity mode outputs suspended solids (SS) concentration or near-infrared scattering and other suspended solids-related characteristics; and the spectral mode outputs high-dimensional spectral characteristics such as full-spectrum or broadband absorbance / transmittance.
[0026] For example, the three-modal data acquisition method is as follows: the spectral mode uses a full-spectrum spectrometer to acquire the absorbance spectrum of each water sample, ranging from 185.5 to 1023.9 nm, for a total of 2048 wavelength points; the electrochemical mode acquires the pH value, which is determined according to the national standard method; and the optical turbidity mode acquires the suspended solids (SS) concentration, which is determined according to the national standard method.
[0027] Multiple water quality indicators include six indicators: dissolved oxygen (DO), ammonia nitrogen (NH3-N), permanganate index (CODMn), total phosphorus (TP), total nitrogen (TN), and chlorophyll a (Chl-a). All indicators are measured according to national environmental monitoring standards and methods. The water quality indicator labels can express the indicator concentration.
[0028] Each sample was strictly aligned with its spectral curve and label record by numbering. The verification conditions included a spectral length of 2048 points, consistent wavelength range, unique sample number, and no missing input or label.
[0029] Step S202: Use K-fold cross-validation to divide the water sample dataset to obtain the training fold sample set and the test fold sample set for each iteration round.
[0030] Based on the K-fold cross-validation mechanism, the water sample dataset is divided into K data partitions. In each iteration, the sample data in K-1 of the data partitions are used as training fold samples to form the training fold sample set, and the sample data in the remaining 1 data partition are used as test fold samples to form the test fold sample set. There are a total of K iterations, and each iteration uses a different data partition as the test fold sample set.
[0031] For example, if there are 51 sample data, the fold number K can be 5, that is, the sample dataset is divided into 5 data partitions, of which 4 data partitions each have 10 sample data, and the remaining data partition has 11 sample data; or, the leave-one-out (LOO) partitioning method can be used to partition the sample dataset.
[0032] Step S203: In each iteration, the multimodal sensing data of each training sample in this iteration is preprocessed to generate modal feature vectors corresponding to each modality. The corresponding modal feature vectors are selected according to the currently set input modality combination and concatenated to obtain the multimodal fusion feature vectors corresponding to the training samples.
[0033] The preprocessing includes: electrochemical mode data preprocessing, optical turbidity mode data preprocessing, and spectral mode data preprocessing.
[0034] Electrochemical modal data preprocessing: Z-score standardization is performed on the electrochemical modal data of each sample to obtain the electrochemical modal feature vector; the standardized statistics of the electrochemical mode are calculated based on the feature mean and standard deviation of the electrochemical modal data of each sample under each feature dimension. The preprocessing parameters of the electrochemical mode include the standardized statistics of the electrochemical mode. Z-score normalization of low-dimensional scalar characteristics such as pH and conductivity of electrochemical modes can bring electrochemical parameters of different dimensions into a unified numerical scale.
[0035] Optical turbidity mode data preprocessing: Z-score standardization is performed on the optical turbidity mode data of each sample to obtain the optical turbidity mode feature vector; the standardized statistics of the optical turbidity mode are calculated based on the feature mean and standard deviation of the optical turbidity mode data of each sample under each feature dimension. The preprocessing parameters of the optical turbidity mode include the standardized statistics of the optical turbidity mode. The turbidity, SS, or near-infrared scattering of suspended matter in the optical turbidity mode are normalized by Z-score so that they can be used as auxiliary features to be input into the model along with spectral features.
[0036] Preprocessing of spectral modal data: The spectral modal data of each sample were sequentially subjected to Savitzky-Golay smoothing, baseline calibration, first derivative processing, and Z-score normalization to reduce the impact of random noise, baseline drift, and background interference on subsequent feature extraction. Full-spectrum PCA (Principal Components Analysis) features and PLS (Partial Least Squares) features were then extracted from the processed spectral modal data. The spectral modality feature vector is obtained by concatenating latent variable features and multi-scale spectral segment features using Squares (partial least squares) method. This reduces the risk of overfitting in small-sample modeling of high-dimensional spectra and retains the main spectral information related to water quality indicators. The standardized statistics of the spectral modality are calculated based on the mean and standard deviation of the spectral modality data of each sample after Z-score standardization at each feature dimension. The PCA feature projection matrix is calculated based on the spectral modality data of each sample after Z-score standardization and the full-spectrum PCA features. The PLS feature projection matrix is calculated based on the spectral modality data of each sample after Z-score standardization and the PLS latent variable features. The preprocessing parameters of the spectral modality include the standardized statistics of the spectral modality, the PCA feature projection matrix, and the PLS feature projection matrix.
[0037] Within each fold, the standardized statistics are the mean and standard deviation vectors required to perform Z-score standardization, including the mean and standard deviation of each feature dimension. In each fold of cross-validation, the Z-score standardized mean and standard deviation are calculated only on the training fold samples within the fold.
[0038] The PCA feature projection matrix and the PLS feature projection matrix are transformation matrices for linear dimensionality reduction of high-dimensional spectra, and are both obtained by fitting and calculating on each training sample within the fold.
[0039] In this embodiment of the invention, multiple input mode combinations are pre-configured, each including a combination of a spectral mode and other auxiliary modes (such as an electrochemical mode and an optical turbidity mode). Each input mode combination is iterated over, and a complete K-fold cross-validation and model training are performed on the currently configured input mode combination.
[0040] In this embodiment of the invention, the spectral feature vector f spec It is composed of three types of features: PCA features (retaining principal components with a cumulative variance contribution rate ≥95%), PLS latent variable features, and multi-scale segmental statistical features (mean, standard deviation, and global statistics after segmenting the full spectrum / half spectrum / 1 / 4 spectrum). The concatenated dimension is d. spec Auxiliary feature vector uaux This refers to electrochemical modal features or a concatenation of electrochemical modal features and optical turbidity modal features; the multimodal fusion feature vector is a direct concatenation of spectral feature vectors and auxiliary feature vectors: x fuse =[f spec ;u aux ].
[0041] For example, the auxiliary feature vector is either the pH value of the electrochemical mode or the pH value of the electrochemical mode plus the SS concentration of the optical turbidity mode, both of which are Z-score normalized.
[0042] In some embodiments, if the currently set input mode combination includes a combination of spectral modes and electrochemical modes, the spectral mode feature vector and the electrochemical mode feature vector of the training sample are concatenated to obtain the multimodal fusion feature vector of the training sample.
[0043] In some embodiments, if the currently set input mode combination includes a combination of spectral mode, electrochemical mode and optical turbidity mode, then the spectral mode feature vector, electrochemical mode feature vector and optical turbidity mode feature vector in the training sample are concatenated to obtain the multimodal fusion feature vector in the training sample.
[0044] Step S204: Based on the multimodal fusion feature vectors corresponding to each training fold sample, perform inner-layer cross-validation optimization to determine the optimal regularization hyperparameter of the multi-output ridge regression model. Then, use the optimal regularization hyperparameter and the multimodal fusion feature vectors of each training fold sample to train the multi-output ridge regression model and solve for the joint weight matrix and bias vector. The multi-output ridge regression model uses the joint weight matrix and bias vector to perform regression prediction on multiple water quality indicators.
[0045] Specifically, in the inner cross-validation, the training sample set is further divided into an inner training subset and an inner validation subset. The inner training subset is used to train the multi-output ridge regression model, and the inner validation subset is used to calculate the evaluation index. Candidate regularization hyperparameters are traversed, and the optimal regularization hyperparameter is obtained by screening based on the evaluation index of the inner validation subset.
[0046] In the outer cross-validation, the multi-output ridge regression model is trained using the optimal regularization hyperparameter and the multimodal fusion feature vectors of each training fold sample. The joint weight matrix and bias vector are obtained by solving the joint weight matrix and bias vector. The multi-output ridge regression model performs regression prediction on multiple water quality indicators through the joint weight matrix and bias vector, and obtains the prediction results of multiple water quality indicators for each training fold sample.
[0047] The loss function of the multi-output ridge regression model includes: ; Where X represents the input feature matrix composed of the multimodal fused feature vectors of each training sample. , Let n be the number of samples, d be the dimension of the multimodal fusion feature vector, and d represent the number of features in the multimodal fusion feature vector; Y represents the label matrix composed of multiple water quality index labels for each training sample. m represents the number of water quality indicators; Let I represent the prediction matrix composed of the predicted values of multiple water quality indicators from each training sample; I is a column vector with all elements equal to 1. W is the joint weight matrix of the model. The joint weight matrix is the model parameter matrix used in the multi-output ridge regression model to map multi-modal fusion features to multiple water quality indicators. It consists of the contribution weights of different modal features to each water quality indicator. Each column of the matrix corresponds to a water quality indicator, and each row corresponds to a modal feature. The first term of the loss function is the sum of the label matrix Y and the prediction matrix. The squared Frobenius norm of the prediction residuals is used to measure the overall prediction error of multiple water quality indicators; the second term of the loss function is the L2 regularization term of the joint weight matrix W, which applies L2 regularization constraints only to the joint weight matrix W; b is a bias vector composed of the bias parameters of each water quality indicator, and the bias vector does not participate in regularization. α is the regularization hyperparameter of the model, determined through inner-layer cross-validation.
[0048] Step S205: Obtain the multimodal fusion feature vector of each test sample in this round, and input the multimodal fusion feature vector of each test sample into the trained multi-output ridge regression model to output the prediction results of multiple water quality indicators for each test sample in this round.
[0049] In some embodiments, obtaining the multimodal fusion feature vector of each test sample in this round includes: The electrochemical modal data of the test sample are transformed using the standardized statistics of the electrochemical modes obtained in this round of calculation to obtain the electrochemical modal feature vector of the test sample. The optical turbidity mode data of the test sample are transformed using the standardized statistics of the optical turbidity mode obtained in this round of calculation to obtain the optical turbidity mode feature vector of the test sample. The spectral modal feature vectors of the test sample are obtained by transforming the spectral modal data using the standardized statistics and spectral feature projection matrix of the spectral modalities calculated in this round. Based on the currently set input modality combination, the corresponding modal feature vectors are concatenated to obtain the multimodal fusion feature vector of each test sample.
[0050] In the transformation of the spectral modal data of the test folded sample, the spectral modal data of the test folded sample is first subjected to Savitzky-Golay smoothing, baseline calibration and first derivative processing. Then, the standardized statistics of the spectral modes obtained in this round are subjected to Z-score standardization. The spectral feature projection matrix is used to transform the Z-score standardized spectral modal data to obtain the spectral modal feature vector of the test folded sample. The spectral feature projection matrix includes the PCA feature projection matrix and the PLS feature projection matrix.
[0051] Step S206: Calculate the model evaluation index under the current input mode combination based on the prediction results and water quality index labels of each test sample output in each iteration round.
[0052] The model evaluation metrics include, but are not limited to, one or more of the following: MAE (Mean Absolute Error), RMSE (Root Mean Squared Error), and R² (coefficient of determination), which are used to evaluate the model's generalization and prediction capabilities, and to make a horizontal comparison of the model performance for different combinations of input modes to determine the optimal combination of input modes.
[0053] Step S207: Reset different input modality combinations and execute the above iterative training method to obtain model evaluation indicators under different input modality combinations, and determine the optimal input modality combination based on the model evaluation indicators corresponding to each group of input modality combinations.
[0054] In some embodiments, the model evaluation metrics include mean absolute error (MAE) or root mean square error (RMSE). The input mode combination with the smallest mean absolute error (MAE) or root mean square error (RMSE) is selected from each group of input mode combinations and determined as the optimal input mode combination.
[0055] In some embodiments, the model evaluation metrics include the coefficient of determination R. 2 The determination coefficient R is selected from each combination of input modes. 2 The combination of input modes with the largest value is determined as the optimal combination of input modes.
[0056] In some embodiments, model evaluation metrics include mean absolute error (MAE), root mean square error (RMSE), and coefficient of determination (R²). 2 The mean absolute error (MAE), root mean square error (RMSE), and coefficient of determination (R²) of each water quality indicator were calculated. 2 After normalization, the comprehensive score of each input mode combination is calculated. The comprehensive score = normalized R 2-Normalized MAE-Normalized RMSE, sorted from high to low based on comprehensive score, the input mode combination with the highest comprehensive score is determined as the optimal input mode combination.
[0057] Step S208: The multimodal sensing data of each sample in the water sample dataset are preprocessed, and the features are spliced according to the optimal input modality combination. The multi-output ridge regression model is retrained to obtain the required water quality index prediction model. At the same time, the preprocessing parameters of each modal sensing data in the preprocessing are extracted, and the residual distribution parameters of each water quality index are statistically obtained according to the prediction results of each sample during the training process.
[0058] Specifically, the preprocessing includes the above-mentioned electrochemical mode data preprocessing, optical turbidity mode data preprocessing, and spectral mode data preprocessing. For a detailed description, please refer to the aforementioned description of preprocessing, which will not be repeated here.
[0059] After preprocessing, feature vectors for each modality (electrochemical mode feature vector, optical turbidity mode feature vector, and spectral mode feature vector) are obtained for each sample. For each sample, features are concatenated according to the optimal input mode combination to obtain the multimodal fusion feature vector for each sample. The multimodal fusion feature vector of each sample is input into a multi-output ridge regression model. Based on the loss between the prediction results of multiple water quality indicators and the labels of multiple water quality indicators for each sample, the multi-output ridge regression model is retrained, and the joint weight matrix and bias vector are solved to obtain the required water quality indicator prediction model. The loss function of the model can be the loss function L(W) mentioned above. In this case, the parameters in the loss function L(W) can be adaptively adjusted according to each sample in the water sample dataset and the multimodal fusion feature vector based on the optimal input mode combination, which will not be elaborated here.
[0060] In some embodiments, the regularization hyperparameter α of the multi-output ridge regression model during retraining can be the globally optimal regularization hyperparameter calculated based on the optimal regularization hyperparameter within each fold of the K-fold cross-validation. The globally optimal regularization hyperparameter can be the mean or median of the K optimal regularization hyperparameters, or a set of optimal regularization hyperparameters that performs best in the inner validation subset can be selected as the globally optimal regularization hyperparameter.
[0061] In some embodiments, the global optimal regularization hyperparameter of the multi-output ridge regression model is determined by inner-layer cross-validation optimization based on the multimodal fusion feature vectors corresponding to each sample in the water sample dataset.
[0062] In some embodiments, the residual distribution parameters of each water quality index obtained by statistical analysis based on the prediction results of each sample during the training process include: calculating the prediction residual of each sample based on the prediction results and labels of each sample during the training process; and obtaining the residual distribution parameters of each water quality index by statistical analysis based on the prediction residuals of each sample during the training process, wherein the residual distribution parameters include the mean and standard deviation of the prediction residuals.
[0063] Prediction residuals are the differences between the predicted values of water quality indicators and the labels of the water quality indicators. The residual distribution parameters for each water quality indicator include the mean and standard deviation, which are used for the detection of anomalies in water quality indicators.
[0064] The water quality index prediction model training method according to embodiments of the present invention constructs a water sample dataset containing multimodal sensing data including spectral, electrochemical, and optical turbidity data. This achieves unified modeling of high-dimensional spectral modes and low-dimensional physicochemical auxiliary modes, extracts different modal features of water samples, and improves the accuracy of water quality index prediction. It employs K-fold cross-validation with internal isolation. In the inner loop, the optimal regularization hyperparameter is determined through inner-layer cross-validation, and a multi-output ridge regression model is trained using training folded samples. In the outer loop, test folded samples are used to evaluate the model evaluation index under the currently set input mode combination. This effectively avoids data leakage and effectively suppresses the overfitting problem of the multi-output ridge regression model, improving the model's performance. The model possesses generalized predictive capabilities for unknown water samples, making it suitable for water quality modeling scenarios involving small samples and high-dimensional spectral data. By setting multiple sets of different input mode combinations for comparative training and performance evaluation, and selecting the optimal input mode combination based on objective model evaluation indicators, the model can quantitatively verify the actual performance gain of each auxiliary mode, avoiding the subjectivity of manual experience-based selection and improving the overall accuracy and stability of the water quality prediction model. Finally, based on the full range of water samples and the optimal input mode combination, the model is retrained to obtain the water quality index prediction model. At the same time, the preprocessing parameters are solidified and reliable residual distribution parameters are statistically obtained, enabling the model to not only have excellent predictive performance but also provide a statistical data foundation for subsequent water quality testing and anomaly detection.
[0065] This invention provides a method for detecting water quality indicators, which can be used in the aforementioned terminal equipment or server. Figure 3 This is a flowchart illustrating a water quality indicator detection method provided in an embodiment of the present invention, as shown below. Figure 3 As shown, the water quality indicator detection method includes the following steps: Step S301: Obtain multimodal sensing data of the water sample to be tested, wherein the multimodal sensing data includes spectral mode data, electrochemical mode data, and optical turbidity mode data of the water sample to be tested; Step S302: Based on the preprocessing parameters of each mode output during the model training phase, preprocess the multimodal sensing data of the water sample to be tested, and obtain the feature vectors of each mode of the water sample to be tested. The preprocessing parameters for the electrochemical mode include standardized statistics of the electrochemical mode (such as the characteristic mean and standard deviation of the electrochemical mode under each characteristic dimension), the preprocessing parameters for the optical turbidity mode include standardized statistics of the optical turbidity mode (such as the characteristic mean and standard deviation of the optical turbidity mode under each characteristic dimension), and the preprocessing parameters for the spectral mode include standardized statistics of the spectral mode (such as the characteristic mean and standard deviation of the spectral mode under each characteristic dimension) and spectral feature projection matrices (PCA feature projection matrix and PLS feature projection matrix).
[0066] In step S302, the preprocessing includes: electrochemical mode data preprocessing, optical turbidity mode data preprocessing, and spectral mode data preprocessing.
[0067] Electrochemical modal data preprocessing: The electrochemical modal data is Z-score standardized based on the standardized statistics of the electrochemical modes to obtain the electrochemical modal feature vectors; Optical turbidity mode data preprocessing: The optical turbidity mode data is Z-score normalized according to the normalized statistics of the optical turbidity modes to obtain the optical turbidity mode feature vectors; Spectral modal data preprocessing: The spectral modal data are sequentially subjected to Savitzky-Golay smoothing, baseline calibration, and first derivative processing. Z-score standardization is then performed on the spectral modal data based on the standardized statistics of the spectral modes. Feature transformation is then performed on the Z-score standardized spectral modal data using spectral feature projection matrices (PCA feature projection matrix and PLS feature projection matrix) to extract full-spectrum PCA features, PLS latent variable features, and multi-scale spectral segment features, which are then concatenated to obtain the spectral modal feature vector.
[0068] Step S303: Select the corresponding modal feature vectors based on the optimal input modal combination determined during the model training phase, perform feature concatenation, and generate a multimodal fusion feature vector for the water sample to be tested. Step S304: Input the multimodal fusion feature vector of the water sample to be tested into the pre-trained water quality index prediction model, and output the predicted values of multiple water quality indicators of the water sample to be tested.
[0069] In some embodiments, the water quality index detection method further includes: using the residual distribution parameters corresponding to each water quality index output during the model training phase and the predicted residuals of each water quality index of the water sample to be tested, calculating the standardized residuals of each water quality index of the water sample to be tested; the predicted residual is the difference between the predicted value of the water quality index of the water sample to be tested and the water quality index label of the water sample to be tested obtained in advance through laboratory measurement; for any water quality index, when the absolute value of its standardized residual is greater than a preset threshold (such as 2 or 3), the water quality index is determined to be abnormal, and the prediction result and abnormal index information (such as abnormal index name and score value) are output.
[0070] The standardized residuals are: , This indicates the new prediction residual for the water quality indicator. This represents the mean value among the residual distribution parameters of this water quality index. This represents the standard deviation of the residual distribution parameter for the water quality index.
[0071] This invention also provides a water quality index prediction model training device, which is used to implement the above embodiments and preferred embodiments; details already described will not be repeated. As used below, the term "module" can refer to a combination of software and / or hardware that performs a predetermined function. Although the device described in the following embodiments is preferably implemented in software, hardware implementation, or a combination of software and hardware, is also possible and contemplated.
[0072] Figure 4 This is a structural block diagram of a water quality index prediction model training device provided in an embodiment of the present invention. This embodiment provides a water quality index prediction model training device, such as... Figure 4 As shown, the device includes: The dataset construction module 401 is used to construct a water sample dataset, which includes sample data of each water sample. The sample data of each water sample includes multimodal sensing data of the water sample and multiple water quality index labels of the water sample. The multimodal sensing data includes spectral mode data, electrochemical mode data and optical turbidity mode data. The dataset partitioning module 402 is used to partition the water sample dataset using K-fold cross-validation to obtain the training fold sample set and the test fold sample set for each iteration round; The preprocessing module 403 is used to preprocess the multimodal perception data of each training sample in each iteration, generate the modal feature vector corresponding to each modality, and select the corresponding modal feature vector according to the currently set input modality combination for feature concatenation to obtain the multimodal fusion feature vector corresponding to the training sample. The model training module 404 is used to perform inner-layer cross-validation optimization based on the multimodal fusion feature vectors corresponding to each training fold sample to determine the optimal regularization hyperparameter of the multi-output ridge regression model, and to train the multi-output ridge regression model using the optimal regularization hyperparameter and the multimodal fusion feature vectors of each training fold sample, and solve for the joint weight matrix and bias vector. The multi-output ridge regression model performs regression prediction on multiple water quality indicators through the joint weight matrix and bias vector. The model testing module 405 is used to obtain the multimodal fusion feature vectors of each test sample in this round, and input the multimodal fusion feature vectors of each test sample into the trained multi-output ridge regression model to output the prediction results of multiple water quality indicators of each test sample in this round. The model evaluation module 406 is used to calculate the model evaluation index under the current input mode combination based on the prediction results and water quality index labels of each test sample output in each iteration round; to obtain the model evaluation index under different input mode combinations by resetting different input mode combinations and executing the above iteration round training method; and to determine the optimal input mode combination based on the model evaluation index corresponding to each group of input mode combinations. The model training module 404 is also used to preprocess the multimodal sensing data of each sample in the water sample dataset, and to perform feature splicing according to the optimal input modality combination, retrain the multi-output ridge regression model, obtain the required water quality index prediction model, extract the preprocessing parameters of each modal sensing data in the preprocessing, and statistically obtain the residual distribution parameters of each water quality index based on the prediction results of each sample during the training process.
[0073] The water quality index prediction model training device provided in this embodiment of the invention can execute the water quality index prediction model training method provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method. Further functional descriptions of the above modules and units are the same as in the corresponding embodiments described above, and will not be repeated here.
[0074] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention.
[0075] The following is a detailed reference. Figure 5The diagram illustrates a structural schematic suitable for implementing an electronic device according to embodiments of the present invention. The electronic device may include a processor (e.g., a central processing unit, graphics processor, etc.) 501, which can perform various appropriate actions and processes according to a program stored in read-only memory (ROM) 502 or a program loaded from memory 508 into random access memory (RAM) 503. The RAM 503 also stores various programs and data required for the operation of the electronic device. The processor 501, ROM 502, and RAM 503 are interconnected via a bus 504. An input / output (I / O) interface 505 is also connected to the bus 504.
[0076] Typically, the following devices can be connected to I / O interface 505: input devices 506 including, for example, touchscreens, touchpads, keyboards, mice, cameras, microphones, accelerometers, gyroscopes, etc.; output devices 507 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; memory devices 508 including, for example, magnetic tapes, hard disks, etc.; and communication devices 509. Communication device 509 allows electronic devices to communicate wirelessly or wiredly with other devices to exchange data. Although Figure 5 Electronic devices with various devices are shown, but it should be understood that it is not required to implement or have all of the devices shown, and more or fewer devices may be implemented or have instead.
[0077] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device 509, or installed from a memory 508, or installed from a ROM 502. When the computer program is executed by the processor 501, it performs the functions defined in the water quality index prediction model training method or water quality index detection method of the embodiments of the present invention.
[0078] Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments of the present invention.
[0079] This invention also provides a computer-readable storage medium. The methods described above according to embodiments of the invention can be implemented in hardware or firmware, or implemented as computer code that can be recorded on a storage medium, or implemented as computer code downloaded via a network and originally stored on a remote storage medium or a non-transitory machine-readable storage medium and then stored on a local storage medium. Thus, the methods described herein can be processed by software stored on a storage medium using a general-purpose computer, a dedicated processor, or programmable or dedicated hardware. The storage medium can be a magnetic disk, optical disk, read-only memory, random access memory, flash memory, hard disk, or solid-state drive, etc.; further, the storage medium can also include combinations of the above types of memory. It is understood that computers, processors, microprocessor controllers, or programmable hardware include storage components capable of storing or receiving software or computer code. When the software or computer code is accessed and executed by the computer, processor, or hardware, the water quality indicator prediction model training method or water quality indicator detection method shown in the above embodiments is implemented.
[0080] A portion of this invention can be applied as a computer program product, such as computer program instructions, which, when executed by a computer, can invoke or provide the methods and / or technical solutions according to the invention through the operation of the computer. Those skilled in the art will understand that the forms in which computer program instructions exist in a computer-readable medium include, but are not limited to, source files, executable files, installation package files, etc. Correspondingly, the ways in which computer program instructions are executed by a computer include, but are not limited to: the computer directly executing the instructions, or the computer compiling the instructions and then executing the corresponding compiled program, or the computer reading and executing the instructions, or the computer reading and installing the instructions and then executing the corresponding installed program. Here, the computer-readable medium can be any available computer-readable storage medium or communication medium accessible to a computer.
[0081] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.
Claims
1. A method for training a water quality index prediction model, characterized in that, The water quality index prediction model is trained using a multi-output ridge regression model, and the method includes: A water sample dataset is constructed, which includes sample data of each water sample. The sample data of each water sample includes multimodal sensing data of the water sample and multiple water quality index labels of the water sample. The multimodal sensing data includes spectral mode data, electrochemical mode data and optical turbidity mode data. K-fold cross-validation was used to divide the water sample dataset to obtain the training fold sample set and the test fold sample set for each iteration. In each iteration, the multimodal sensing data of each training sample in this iteration are preprocessed to generate modal feature vectors corresponding to each modality. Then, the corresponding modal feature vectors are selected according to the currently set input modality combination and concatenated to obtain the multimodal fusion feature vectors corresponding to the training samples. The optimal regularization hyperparameter of the multi-output ridge regression model is determined by inner-layer cross-validation optimization based on the multimodal fusion feature vectors corresponding to each training fold sample. The multi-output ridge regression model is then trained using the optimal regularization hyperparameters and the multimodal fusion feature vectors of each training fold sample. The joint weight matrix and bias vector are then obtained. The multi-output ridge regression model uses the joint weight matrix and bias vector to perform regression prediction on multiple water quality indicators. Obtain the multimodal fusion feature vectors of each test sample in this round, and input the multimodal fusion feature vectors of each test sample into the trained multi-output ridge regression model to output the prediction results of multiple water quality indicators for each test sample in this round. Based on the prediction results and water quality index labels of each test sample output in each iteration, calculate the model evaluation index under the current input mode combination; By resetting different input modality combinations and executing the above iterative training method, model evaluation metrics under different input modality combinations are obtained, and the optimal input modality combination is determined based on the model evaluation metrics corresponding to each group of input modality combinations. The multimodal sensing data of each sample in the water sample dataset are preprocessed and feature splicing is performed according to the optimal input modality combination. The multi-output ridge regression model is retrained to obtain the required water quality index prediction model. At the same time, the preprocessing parameters of each modal sensing data in the preprocessing are extracted, and the residual distribution parameters of each water quality index are statistically obtained based on the prediction results of each sample during the training process.
2. The method according to claim 1, characterized in that, The preprocessing includes: Electrochemical modal data preprocessing: Z-score standardization is performed on the electrochemical modal data of each sample to obtain electrochemical modal feature vectors; the standardized statistics of the electrochemical modes are calculated based on the feature mean and standard deviation of the electrochemical modal data of each sample under each feature dimension, and the preprocessing parameters of the electrochemical modes include the standardized statistics of the electrochemical modes; Optical turbidity mode data preprocessing: Z-score standardization is performed on the optical turbidity mode data of each sample to obtain the optical turbidity mode feature vector; the standardized statistics of the optical turbidity mode are calculated based on the feature mean and standard deviation of the optical turbidity mode data of each sample under each feature dimension, and the preprocessing parameters of the optical turbidity mode include the standardized statistics of the optical turbidity mode. Spectral modal data preprocessing: Savitzky-Golay smoothing, baseline calibration, first derivative processing, and Z-score standardization are performed on the spectral modal data of each sample sequentially. Full-spectrum PCA features, PLS latent variable features, and multi-scale spectral segment features are extracted and concatenated to obtain the spectral modal feature vector. Standardized statistics of the spectral modality are calculated based on the mean and standard deviation of the Z-score standardized spectral modal data for each sample across each feature dimension. The PCA feature projection matrix is calculated based on the Z-score standardized spectral modal data and full-spectrum PCA features for each sample. The PLS feature projection matrix is calculated based on the Z-score standardized spectral modal data and PLS latent variable features for each sample. The preprocessing parameters for the spectral modality include the standardized statistics, PCA feature projection matrix, and PLS feature projection matrix of the spectral modality.
3. The method according to claim 1, characterized in that, The residual distribution parameters of each water quality indicator obtained statistically from the prediction results of each sample during the training process include: The prediction residuals for each sample are calculated based on the prediction results and labels of the water quality indicators for each sample during the training process. The residual distribution parameters of various water quality indicators are obtained from the statistical analysis of the prediction residuals of each sample during the training process. The residual distribution parameters include the mean and standard deviation.
4. The method according to claim 2, characterized in that, The step of selecting corresponding modal feature vectors according to the currently set input modality combination and concatenating them to obtain the multimodal fusion feature vector of the training samples includes: If the currently set input mode combination includes a combination of spectral and electrochemical modes, then the spectral mode feature vector and the electrochemical mode feature vector of the training sample are concatenated to obtain the multimodal fusion feature vector of the training sample, or... If the currently set input mode combination includes a combination of spectral mode, electrochemical mode and optical turbidity mode, then the spectral mode feature vector, the electrochemical mode feature vector and the optical turbidity mode feature vector in the training sample are concatenated to obtain the multimodal fusion feature vector in the training sample.
5. The method according to claim 1, characterized in that, The spectral modal data includes absorbance spectra and / or transmittance spectra; The electrochemical mode data includes pH value and / or conductivity; The optical turbidity modal data includes one or more of the following: suspended matter concentration, turbidity, and near-infrared scattering characteristics; The aforementioned water quality indicators include one or more of the following: dissolved oxygen, ammonia nitrogen, permanganate index, total phosphorus, total nitrogen, and chlorophyll a.
6. The method according to claim 2, characterized in that, The process of obtaining the multimodal fusion feature vector of each test sample in this round includes: The standardized statistics of the electrochemical modes obtained in this round of calculation are used to transform the electrochemical mode data of the test sample to obtain the electrochemical mode feature vector of the test sample. The optical turbidity mode data of the test sample are transformed using the standardized statistics of the optical turbidity mode obtained in this round of calculation to obtain the optical turbidity mode feature vector of the test sample. The spectral modal feature vectors of the test sample are obtained by transforming the spectral modal data using the standardized statistics and spectral feature projection matrix of the spectral modalities calculated in this round. Based on the currently set input modality combination, the corresponding modal feature vectors are concatenated to obtain the multimodal fusion feature vector of each test sample.
7. The method according to claim 1, characterized in that, The loss function of the multi-output ridge regression model includes: ; Where X represents the input feature matrix composed of the multimodal fusion feature vectors of each training sample; Y represents the label matrix composed of multiple water quality index labels of each training sample. Let W represent the prediction matrix composed of the predicted values of multiple water quality indicators from each training sample; I is a column vector with all elements equal to 1; W is the joint weight matrix of the model; the first term of the loss function is the squared Frobenius norm of the residual between the label matrix and the prediction matrix, used to measure the overall prediction error of multiple water quality indicators; the second term of the loss function is the L2 regularization term of the joint weight matrix W; α is the regularization hyperparameter of the model, determined through inner cross-validation; b is a bias vector composed of the bias parameters of each water quality indicator, which does not participate in regularization.
8. A method for detecting water quality indicators, characterized in that, The method includes: Acquire multimodal sensing data of the water sample to be tested, including spectral mode data, electrochemical mode data, and optical turbidity mode data of the water sample to be tested; Based on the preprocessing parameters of each mode output during the model training phase, preprocessing is performed on the multimodal sensing data of the water sample to be tested to obtain the feature vectors of each mode of the water sample to be tested. Based on the optimal input mode combination determined during the model training phase, the corresponding modal feature vectors are selected and concatenated to generate a multimodal fusion feature vector for the water sample to be tested. The multimodal fusion feature vector of the water sample to be tested is input into a pre-trained water quality index prediction model, which outputs the predicted values of multiple water quality indicators of the water sample to be tested.
9. The water quality testing method according to claim 8, characterized in that, The method further includes: Using the residual distribution parameters corresponding to each water quality index output during the model training phase and the predicted residuals of each water quality index of the water sample to be tested, the standardized residuals of each water quality index of the water sample to be tested are calculated; the predicted residuals are the differences between the predicted values of the water quality indexes of the water sample to be tested and the water quality index labels of the water sample to be tested obtained in advance through laboratory measurement. For any water quality indicator, when the absolute value of its standardized residual is greater than a preset threshold, the water quality indicator is determined to be abnormal, and the prediction result and abnormal indicator information are output.
10. A training device for a water quality index prediction model, characterized in that, The water quality index prediction model is trained using a multi-output ridge regression model, and the device includes: The dataset construction module is used to construct a water sample dataset, which includes sample data of each water sample. The sample data of each water sample includes multimodal sensing data of the water sample and multiple water quality index labels of the water sample. The multimodal sensing data includes spectral mode data, electrochemical mode data and optical turbidity mode data. The dataset partitioning module is used to partition the water sample dataset using K-fold cross-validation to obtain the training fold sample set and the test fold sample set for each iteration round; The preprocessing module is used to preprocess the multimodal sensing data of each training sample in each iteration, generate the modal feature vector corresponding to each modality, and select the corresponding modal feature vector according to the currently set input modality combination for feature concatenation to obtain the multimodal fusion feature vector corresponding to the training sample. The model training module is used to determine the optimal regularization hyperparameter of the multi-output ridge regression model by performing inner-layer cross-validation optimization based on the multimodal fusion feature vectors corresponding to each training fold sample, and to train the multi-output ridge regression model using the optimal regularization hyperparameters and the multimodal fusion feature vectors of each training fold sample, thereby solving for the joint weight matrix and bias vector. The multi-output ridge regression model then performs regression prediction on multiple water quality indicators using the joint weight matrix and bias vector. The model testing module is used to obtain the multimodal fusion feature vectors of each test sample in this round, and input the multimodal fusion feature vectors of each test sample into the trained multi-output ridge regression model to output the prediction results of multiple water quality indicators for each test sample in this round. The model evaluation module is used to calculate the model evaluation index under the current input mode combination based on the prediction results and water quality index labels of each test sample output in each iteration round; to obtain the model evaluation index under different input mode combinations by resetting different input mode combinations and executing the above iteration round training method; and to determine the optimal input mode combination based on the model evaluation index corresponding to each group of input mode combinations. The model training module is also used to preprocess the multimodal sensing data of each sample in the water sample dataset, and to perform feature splicing according to the optimal input modality combination, retrain the multi-output ridge regression model, obtain the required water quality index prediction model, extract the preprocessing parameters of each modal sensing data in the preprocessing, and statistically obtain the residual distribution parameters of each water quality index based on the prediction results of each sample during the training process.
