Hyperspectral water quality inversion algorithm framework based on machine learning

By constructing a machine learning-based hyperspectral water quality inversion algorithm framework, the problems of process subjectivity, insufficient model training, low data utilization, and poor adaptability in hyperspectral water quality monitoring were solved, achieving high-precision and stable water quality monitoring.

CN120995870APending Publication Date: 2025-11-21上海握蓝航天科技集团有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511134442.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-14
Publication Date
2025-11-21

AI Technical Summary

Technical Problem

Existing hyperspectral water quality monitoring technologies suffer from problems such as strong process subjectivity, insufficient model training, low data utilization, insufficient prediction stability, and poor adaptability, especially in deep learning models.

Method used

A hyperspectral water quality inversion algorithm framework based on machine learning was constructed. By collecting and cleaning hyperspectral data, aggregating labeled data, constructing a search space for multiple preprocessors and models, optimizing hyperparameters, and using a total variation smoothing filter, an end-to-end processing flow was formed.

Benefits of technology

It significantly improves the prediction accuracy and stability of water quality monitoring, reduces human intervention, enhances data utilization and model adaptability, and adapts to complex aquatic environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120995870A_ABST
    Figure CN120995870A_ABST
Patent Text Reader

Abstract

The invention discloses a hyperspectral water quality inversion algorithm framework based on machine learning. Water quality parameter prediction precision and efficiency are optimized through an automatic process. The framework comprises the following steps: acquiring hyperspectral data and water quality measured data, cleaning, and polymerizing and expanding a sample; a preprocessing space, a model space and a hyper-parameter search space are constructed, and an optimal combination is automatically screened through multi-fold cross validation; an independent model is constructed and optimized for different water quality indexes, and the output is post-processed by combining a total variation smoothing filter, so that the time dimension stability is improved. Manual intervention is reduced, the prediction precision and generalization ability are better than those of a traditional method, and the method is suitable for complex water body monitoring.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of hyperspectral water quality monitoring technology, specifically involving a hyperspectral water quality inversion algorithm framework based on machine learning. Background Technology

[0002] Hyperspectral water quality inversion technology relies on hyperspectral remote sensing to capture the reflectance, transmission, and scattering spectra of water bodies in the 400-1000 spectral band, revealing key water quality parameters such as chemical composition and substance concentration, thus providing data support for water quality monitoring. However, existing technologies have many limitations, restricting monitoring accuracy and efficiency.

[0003] First, traditional methods rely heavily on human experience to select preprocessing methods (such as denoising and normalization), machine learning models (such as partial least squares regression and random forest), and hyperparameters, resulting in a highly subjective process, unsystematic optimization, and susceptibility to inversion accuracy due to differences in experience.

[0004] Secondly, the cost of label data (such as laboratory analysis and portable device test results) in water quality monitoring is high, and the actual sample size is usually only 500-1000. The small sample size leads to insufficient model training, especially in deep learning models where performance is limited. At the same time, the time matching between hyperspectral data and label data is loose, resulting in low data utilization.

[0005] Third, the variation patterns of different water quality indicators (such as chlorophyll, turbidity, and total nitrogen) vary significantly. Traditional methods often use a unified model for processing, which is difficult to adapt to the characteristics of each indicator. The data distribution of some indicators is skewed, further reducing the accuracy of prediction.

[0006] Fourth, the model output fluctuates greatly over time, and the original prediction results are not stable enough, which is not conducive to the application of subsequent early warning algorithms.

[0007] Furthermore, hyperspectral data suffers from high dimensionality and noise interference. Traditional preprocessing methods are simplistic and unable to effectively eliminate interference; the lack of systematic search in model hyperparameter settings leads to weak generalization ability and difficulty in adapting to complex aquatic environments. To address these issues, this invention aims to construct an automated, high-precision hyperspectral water quality inversion framework. By systematically optimizing preprocessing, models, and hyperparameters, it improves data utilization and prediction stability, overcoming the limitations of traditional methods. Therefore, a solution is required. Summary of the Invention

[0008] (a) Technical problems to be solved

[0009] To address the shortcomings of existing technologies, this invention provides a hyperspectral water quality inversion algorithm framework based on machine learning to solve the problems mentioned in the background.

[0010] (II) Technical Solution

[0011] To achieve the above objectives, the present invention provides the following technical solution:

[0012] A machine learning-based hyperspectral water quality inversion algorithm framework includes the following steps:

[0013] S1. Collect training data and label data;

[0014] S1.1. A suspended hyperspectral imager is used to collect the spectral data of orthophotos from the surface of the water body. The data contains information in the 400-1000 band and is represented as a 1*601 array. The data is transmitted in real time and the acquisition time is recorded.

[0015] S1.2 Collect actual water quality data as label data. The data comes from laboratory analysis or portable water quality rapid testing equipment. The indicators include chlorophyll, total nitrogen, total phosphorus, transparency, chemical oxygen demand, ammonia nitrogen, suspended solids, and dissolved oxygen. Record the sampling time.

[0016] S2. Data Cleaning: Traverse the hyperspectral data and delete data that meets the following characteristics;

[0017] S2.1. Does not conform to the spectral characteristics of water quality; values ​​in specific bands are significantly higher than those in other bands.

[0018] S2.2, Contains zero or Nan values;

[0019] S3. Data Aggregation: Based on the sampling time of each label data, match the hyperspectral data within 75 seconds before and after its time point (adjustable), and bind the individual label data with the matched hyperspectral data to expand the dataset;

[0020] S4. Data partitioning: The data is divided into training set, validation set, and test set in an 8:1:1 ratio. 10% of the test set is not used for training, and the remaining 90% of the data is used for optimal parameter search using 10-fold cross-validation.

[0021] S5. Constructing the preprocessor search space: including baseline correction algorithm, first-order difference method, MIN-MAX normalization, multiplicative scattering correction method (MSC), standard normal transformation (SNV), forming 120 preprocessing combinations through permutation and combination;

[0022] S6. Constructing the model search space: including Partial Least Squares Regression (PLS), Random Forest (RF), and XGBoost (XGB) algorithms; for skewed label data, a label data transformer is introduced, which takes the logarithm of the labels during training and automatically restores them after inference;

[0023] S7. Constructing the hyperparameter search space: For each model in step S6, set the hyperparameter range with reference to academic literature to form a mesh hyperparameter space;

[0024] S8. Optimal combination search: Multi-fold cross-validation is used. The optimal preprocessing combination is searched by fixing the model and hyperparameters in sequence, the optimal model is searched by fixing the preprocessing and hyperparameters in sequence, and the optimal hyperparameters are searched by fixing the preprocessing and model in sequence. The mean squared error (MSE) is used as the evaluation index.

[0025] S9. Pipeline construction: Combine the optimal pretreatment method, model and hyperparameters obtained in step S8 into an end-to-end treatment process, and construct a pipeline independently for each water quality index.

[0026] S10. Constructing the inversion filter: Using a filter based on total variation (TV) smoothing, new input data is added to a sliding window. When the window data size is ≥2, smoothing is performed by minimizing the balance function of the deviation between the total variation and the original data, and the smoothed result of the latest data is output. The filter is connected in series with the pipeline to form a complete inversion model.

[0027] S11. Performance Evaluation: The model is evaluated on the test set using the Mean Relative Error (MRE). The MRE calculation formula is as follows: Where y i For the true value, is the predicted value, and m is the sample size.

[0028] Preferably, the hyperspectral data acquisition in step S1.1 is carried out in real time around the clock, with the recording time accurate to the second.

[0029] Preferably, the 75-second time window in step S3 can be adjusted according to the stability of the water body. For water bodies with poor stability, the time window can be shortened to 50 seconds, while for water bodies with good stability, the time window can be extended to 100 seconds.

[0030] Preferably, the search method for preprocessing combinations in step S5 is exhaustive search, covering all permutations and combinations of the five preprocessing methods.

[0031] Preferably, the logarithmic transformation of the label data converter in step S6 is applicable to skewed distribution indicators such as total nitrogen and ammonia nitrogen. The transformation formula is y′=log(y+1), and the restoration formula is y=e y′ -1.

[0032] Preferably, the hyperparameter space in step S7 includes:

[0033] Hyperparameters of random forest: number of decision trees (100-500), maximum depth (5-20), minimum number of split samples (2-10);

[0034] XGBoost hyperparameters: learning rate (0.01-0.3), tree depth (3-10), subsample ratio (0.6-1.0);

[0035] Hyperparameters of partial least squares regression: number of principal components (5-20);

[0036] Preferably, the size of the sliding window in step S10 is 5-10 data points, which can be adjusted according to real-time requirements.

[0037] (III) Beneficial Effects

[0038] This invention provides a hyperspectral water quality inversion algorithm framework based on machine learning. It has the following beneficial effects:

[0039] 1. Significantly improved prediction accuracy: Experimental data shows that compared with traditional BP neural networks, the prediction error of this framework for multiple water quality indicators has been greatly reduced. Among them, the error for chlorophyll decreased from 33.5% to 8.05%, total nitrogen from 34.4% to 4.72%, transparency from 132.6% to 12.24%, and dissolved oxygen from 23% to 2.61%. Only the errors for total phosphorus and permanganate fluctuated slightly, and the overall accuracy has been significantly improved.

[0040] 2. Reduce manual intervention and improve efficiency: By automatically searching for preprocessing combinations, models and hyperparameters, it replaces the traditional manual experience selection. The entire process does not require manual intervention, which greatly shortens the parameter optimization time and is suitable for large-scale water quality monitoring scenarios.

[0041] 3. Enhanced data utilization and robustness: By aggregating hyperspectral data and label data within 75 seconds, the sample size is expanded several times, solving the problem of insufficient training with small samples (500-1000); 10-fold cross-validation and independent evaluation on the test set ensure the model's generalization ability and adaptability to complex aquatic environments.

[0042] 4. Adaptable to multiple indicators: Independent models are built for different indicators such as chlorophyll and turbidity. By combining logarithmic transformation of skewed data, the variation patterns of each indicator are matched to avoid the problem of insufficient adaptability of a unified model.

[0043] 5. Improved output stability: The total variation smoothing filter processes the model output in real time, reducing temporal fluctuations and providing stable input for subsequent water quality early warning algorithms, thus enhancing the practicality of the monitoring system. Attached Figure Description

[0044] Figure 1 This is the original hyperspectral data image of the present invention;

[0045] Figure 2 This is a spectral data image after removing abnormal data according to the present invention;

[0046] Figure 3 (a / b / c / d / e) shows the original water quality labels of this invention and their distribution after logarithmic transformation;

[0047] Figure 4 This is a bar chart comparing the error of the algorithm of this invention with other popular algorithms;

[0048] Figure 5 This is a flowchart of the method of the present invention. Detailed Implementation

[0049] 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, 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.

[0050] Example 1

[0051] This solution discloses a machine learning-based hyperspectral water quality inversion algorithm framework, mainly including the following steps: S1 Collecting hyperspectral data as training data, and obtaining label information from collected water samples through laboratory analysis and environmental field analysis; S2 Cleaning the data in S1; S3 Aggregating the cleaned spectral data in S2; S4 Dividing the data in S3; S5 Constructing common preprocessors for water quality inversion and establishing a preprocessor search space; S6 Constructing common models for water quality inversion and establishing a pre-model search space; S7 Constructing the hyperparameter space of the corresponding models and establishing a hyperparameter search space; S8 Using multi-fold cross-validation, searching for the most suitable preprocessing method, model, and hyperparameters in the three spaces; S9 Assembling the searched preprocessing methods, models, and hyperparameters into a pipeline; S10 Constructing inversion data filters and encapsulating them with the pipeline into a complete end-to-end inversion model; S11 Evaluating the model performance.

[0052] Solution Analysis: This solution addresses the problem of traditional water quality inversion relying on manual experience by constructing a fully automated framework. S1 collects water surface reflectance data in the 400-1000 Hz band using hyperspectral equipment, combining it with laboratory or field-measured water quality indicators as labels to ensure data diversity and accuracy. S2 eliminates outlier spectra, zero values, and Nan values, resolving noise interference in the raw data and laying a reliable foundation for subsequent processing. S3 innovatively bundles individual label data with 75 seconds of hyperspectral data, expanding the sample size several times and effectively solving the problem of insufficient training with small samples (500-1000), improving the robustness of the dataset. S4 divides the training, validation, and test sets in an 8:1:1 ratio, with 10% of the test set independent of the training process and the remaining 90% using 10-fold cross-validation, ensuring both sufficient model training and objective evaluation. S5 includes five preprocessing methods, such as baseline correction and first-order difference, forming 120 combinations to cover common preprocessing needs in water quality inversion and avoid the limitations of single preprocessing methods. S6 introduces three models: partial least squares regression, random forest, and XGBoost, and adds a logarithmic transformation transformer for skewed label data, solving the adaptation problem caused by differences in the distribution characteristics of different indicators. S7 constructs a grid-based hyperparameter space for each model, such as 100-500 decision trees for random forests, ensuring the systematic nature of hyperparameter search. S8 uses multi-fold cross-validation to sequentially search for the optimal preprocessing, model, and hyperparameters, using mean squared error as the indicator to replace manual experience selection and improve the scientific rigor of optimization. S9's pipeline achieves end-to-end processing and is independently constructed for each individual indicator, adapting to the changing patterns of different indicators. S10's total variation smoothing filter uses a sliding window to smooth when the data volume is ≥2, reducing output volatility. S11 uses average relative error evaluation to comprehensively reflect model performance. The entire framework forms a closed loop from data processing to model optimization, achieving a combination of automation and high precision.

[0053] Technical Results: This solution demonstrates significant advantages in the field of water quality inversion. Regarding prediction accuracy, experimental data shows that compared to traditional BP neural networks, the average relative error of each water quality indicator is significantly reduced. Specifically, chlorophyll decreased from 33.5% to 8.05%, total nitrogen from 34.4% to 4.72%, transparency from 132.6% to 12.24%, and dissolved oxygen from 23% to 2.61%. Only total phosphorus and permanganate errors showed slight fluctuations. Overall accuracy is significantly improved, thanks to the multi-preprocessing combination of S5, the model adaptation of S6, and the system optimization of S8. In terms of efficiency improvement, S8's automated search replaces manual experience-based selection, greatly reducing parameter optimization time. The entire process requires no manual intervention, making it suitable for large-scale water quality monitoring scenarios and solving the inefficiency problem caused by the reliance on manual methods in traditional approaches. In terms of data utilization, S3's data aggregation within 75 seconds expands the sample size several times over. Combined with S4's 8:1:1 partitioning and 10-fold cross-validation, it solves the problem of insufficient training with small samples, enhances the model's generalization ability, and enables the model to maintain stable performance in complex aquatic environments. For multi-indicator adaptation, S9 constructs independent pipelines for each individual indicator. Combined with S6's logarithmic transformation of skewed data, it avoids the insufficient adaptability of a unified model. The prediction accuracy of skewed indicators such as total nitrogen is particularly significantly improved. In terms of output stability, S10's total variation smoothing filter effectively reduces the volatility in the time dimension, providing stable input for subsequent early warning algorithms and enhancing the practicality of the monitoring system. In addition, the framework's automation features reduce human error and improve the reliability of results. It is suitable for various scenarios such as laboratories and environmental sites, providing strong technical support for water quality monitoring.

[0054] Example 2

[0055] This solution discloses a hyperspectral water quality inversion algorithm framework based on machine learning. In S1, the spectral data of water surface reflected light collected by a hyperspectral device is used as training data, and the water quality index data measured in the laboratory or on-site environment is used as label data. The data are aggregated to form a model dataset.

[0056] Solution Analysis: This solution features targeted design in data sourcing and aggregation, addressing the issues of loose data matching and low utilization rates in traditional water quality inversion methods. S1 explicitly defines training data as water surface reflectance spectral data collected by hyperspectral equipment. This type of data contains information in the 400-1000 spectral bands, accurately reflecting the spectral characteristics of water bodies and providing rich input features for the model. Label data originates from laboratory analysis or portable rapid testing equipment, covering multiple key indicators such as chlorophyll and total nitrogen, ensuring the accuracy and comprehensiveness of the labels. Aggregating both to form the model dataset achieves precise correlation between spectral data and water quality indicators, avoiding biases caused by inconsistent data sources. In traditional methods, the utilization rate of hyperspectral data and label data is often low due to temporal or spatial mismatches. This solution, through strict aggregation rules, ensures that each label data point is matched with corresponding spectral data, providing a high-quality data foundation for subsequent model training. This data aggregation method also considers the high cost of label data in actual monitoring, maximizing the utilization of existing label data and reducing data waste through effective correlation. In addition, the aggregated model dataset contains the correspondence between spectral features and water quality indicators, enabling the model to learn the inherent laws between the two. This lays the data foundation for subsequent preprocessing, model training, and other steps, ensuring the effectiveness of the entire inversion process.

[0057] Technical Effects: This data aggregation design brings multiple technical benefits. First, it improves the correlation and usability of the data. The precise aggregation of hyperspectral data and label data enables the model to accurately learn the mapping relationship between spectral features and water quality indicators during training, avoiding model training bias caused by data mismatch. This provides reliable data support for subsequent preprocessing and model optimization. For example, in chlorophyll inversion, precise aggregation allows the model to effectively capture the correlation between specific bands and chlorophyll concentration, improving prediction accuracy. Second, it improves the utilization rate of label data. Due to the high cost and small sample size (usually 500-1000) of label data, aggregation associates a single label with multiple spectral data, indirectly expanding the effective sample size, alleviating the small sample problem, and enabling the model to learn patterns from more data, thus enhancing model stability. For example, in the inversion of total nitrogen index, the expansion of the sample size allows the model to learn more fully in low and high concentration ranges, reducing prediction errors. Furthermore, it lays the foundation for full-process automation. The aggregated model dataset has a unified format, facilitating automated processing in subsequent steps such as data cleaning in S2 and data partitioning in S4, reducing the workload of manual data organization and improving the overall efficiency of the process. Finally, it ensures data consistency. The strict correspondence between training data and label data makes model evaluation more accurate. The mean relative error in S11 can truly reflect model performance, providing reliable feedback for algorithm optimization.

[0058] Example 3

[0059] This solution discloses a hyperspectral water quality inversion algorithm framework based on machine learning. In step S2, data cleaning is performed on the data in step S1. The data cleaning operation includes cleaning outliers (non-water quality reflectance spectra), zero values, and Nan values.

[0060] Solution Analysis: Data cleaning in S2 is a crucial step in ensuring the quality of hyperspectral data. Clear cleaning rules were established to address potential noise and anomalies in the spectral data from actual monitoring. First, outliers that do not conform to the characteristics of water quality spectra—that is, data where a specific band value is significantly higher than other bands—are deleted. Water quality spectra have inherent characteristics; the reflectance of different bands usually exhibits certain regularities. The presence of outliers disrupts these regularities. Without cleaning, the model may learn incorrect features. For example, an abnormally high value in a band due to equipment malfunction might be misinterpreted by the model as being related to a certain water quality indicator, thus affecting prediction accuracy. Second, data containing zero or Nan values ​​are deleted. Zero values ​​may originate from equipment acquisition failure, while Nan values ​​indicate missing data. Such data cannot provide effective spectral information; retaining it will lead to incomplete data during model training, affecting model stability. Traditional methods often rely on manual judgment for data cleaning, which is inefficient and highly subjective. This solution's automated cleaning rules can quickly traverse the dataset, using standardized cleaning methods to avoid the biases of manual intervention. Furthermore, the data cleaning operation is performed after S1 data collection and before S3 data aggregation to ensure that all data entering the aggregation step is high-quality data. This prevents abnormal data from entering subsequent processes, thus guaranteeing the reliability of the aggregated model dataset and providing a clean data foundation for subsequent preprocessing and model training. This pre-cleaning approach reduces rework caused by data quality issues in subsequent steps and improves the efficiency of the entire inversion process.

[0061] Technical Effects: Data cleaning significantly improves data quality, resulting in several technical benefits. First, it reduces the interference of outliers on the model. By removing outliers that do not conform to the spectral characteristics of water quality, the model learns the true relationship between the spectrum and water quality indicators during training, avoiding the introduction of erroneous features. For example, in turbidity inversion, the cleaned spectral data more accurately reflects the scattering characteristics corresponding to water turbidity, making the model's predictions more accurate. Second, it ensures data integrity. After removing zero and Nan values, the data entering the aggregation step is complete and valid, avoiding model training interruptions or accuracy drops due to missing data, thus improving the stability of model training. For example, in the inversion of total phosphorus, complete data allows the model to stably learn the correlation between each band and total phosphorus concentration, reducing fluctuations in prediction results. Third, it improves the efficiency of subsequent steps. Clean data reduces the burden of preprocessing steps, allowing preprocessing methods to play a more effective role. For example, the baseline correction algorithm can more accurately remove baseline drift and enhance the significance of spectral features when processing clean data. Furthermore, automated cleaning rules reduce labor costs. Traditional manual cleaning requires professionals to inspect data one by one, which is time-consuming and labor-intensive. This solution's automated processing can quickly clean large-scale datasets, making it suitable for high-frequency data processing scenarios in real-time monitoring and improving the efficiency of the entire water quality retrieval process. Finally, the high-quality cleaned data makes model evaluation more reliable. In the S11 mean relative error calculation, it avoids evaluation bias caused by abnormal data, truly reflecting the model's actual performance.

[0062] Example 4

[0063] This solution discloses a hyperspectral water quality inversion algorithm framework based on machine learning. In step S3, the cleaned spectral data from step S2 are aggregated. The dataset obtained after step S3 is divided into training + validation set / test set according to a specific ratio.

[0064] Solution Analysis: The aggregation and data partitioning in S3 are crucial steps in addressing the small sample size problem and optimizing the dataset structure. Aggregation uses the time of each water sampling analysis as a benchmark, matching hyperspectral data within a 75-second interval around that time point. This design fully considers the characteristics of frequent hyperspectral data acquisition and the high cost and limited quantity of labeled data in actual monitoring. In actual monitoring, hyperspectral equipment can collect data in real-time around the clock, while labeled data needs to be obtained through laboratory analysis or portable equipment detection, with a sample size typically only 500-1000. Without aggregation, there would be insufficient training data for the model. By matching data within a 75-second interval, a single labeled data point is bundled with multiple hyperspectral data points, expanding the dataset several times over. For example, one labeled data point may match five hyperspectral data points. With the expanded sample size, the model can learn more details of spectral changes, enhancing its generalization ability. Meanwhile, the 75-second time window can be adjusted according to water body stability. For water bodies with poor stability, it is shortened to 50 seconds, and for those with good stability, it is extended to 100 seconds. This flexibility ensures the temporal correlation between the matched hyperspectral data and the label data, avoiding mismatches caused by rapid changes in the water body. The data is divided into training, validation, and test sets in an 8:1:1 ratio, with 10% of the test set not participating in training to ensure objectivity in the evaluation. The remaining 90% of the data uses 10-fold cross-validation for optimal parameter search. This partitioning method ensures the size of the training set while reducing the randomness of data partitioning through cross-validation. Traditional methods often use simple random partitioning, which may lead to uneven data distribution. This proposed method is more scientific and ensures the representativeness of each dataset.

[0065] Technical Effects: The aggregation processing and data partitioning design significantly improved data utilization and model performance. First, it addressed the problem of insufficient training with small samples. With the dataset expanded several times over, the model had more samples to learn from, enabling it to capture more subtle relationships between spectral features and water quality indicators. For example, in dissolved oxygen retrieval, the expanded samples covered the spectral features corresponding to dissolved oxygen changes at different time points, making the model's predictions more accurate. The average relative error of dissolved oxygen in the experimental data decreased from 23% to 2.61%, partly due to the expanded sample size. Second, it enhanced the model's generalization ability. 10-fold cross-validation allowed the model to be trained and validated on different data subsets, avoiding overfitting to specific datasets and enabling the model to better adapt to different aquatic environments. For example, in complex river or lake environments, the model maintained stable prediction accuracy. Furthermore, the adjustability of the time window enhances the flexibility of data matching. Optimization for water bodies with varying stability ensures the correlation of aggregated data. For example, in nearshore waters susceptible to external disturbances, shortening the time window to 50 seconds reduces the time interval between hyperspectral and label data, resulting in more accurate matching and reducing errors caused by rapid changes in the water body. In addition, the scientific data partitioning method ensures the objectivity of model evaluation. An independent test set, not used in training, accurately reflects the model's generalization performance, making the performance evaluation results more reliable and providing an accurate reference for the model's practical application. Finally, this data processing method reduces reliance on label data. Given the high cost of label data, expanding the sample size improves model performance and reduces costs in actual monitoring.

[0066] Example 5

[0067] This scheme discloses a hyperspectral water quality inversion algorithm framework based on machine learning. In S5, a search space is composed of various preprocessors commonly used in water quality inversion models, including baseline correction algorithm, first-order difference method, MIN-MAX normalization, multiplicative scattering correction method (MSC), and standard normal transformation (SNV).

[0068] Solution Analysis: The preprocessor search space constructed by S5 covers five common preprocessing methods in water quality inversion, forming 120 combinations, providing the model with rich preprocessing options and overcoming the limitation of single preprocessing methods in traditional methods. The baseline correction algorithm removes baseline drift in spectral data. This drift, which may be caused by instrument noise or environmental factors, can mask true spectral characteristics. For example, in chlorophyll monitoring, baseline drift may cause reflectance deviations in characteristic bands, affecting the model's judgment of chlorophyll concentration. The first-order difference method enhances the changing trends of spectral data and highlights subtle spectral features. For some slowly changing water quality indicators, such as total nitrogen, first-order difference more clearly reflects their corresponding spectral changes. MIN-MAX normalization maps spectral data to the 0-1 interval, eliminating the difference in data magnitude between different bands, allowing the model to treat the features of each band more fairly and preventing a particular band from dominating model learning due to its large numerical range. Multiplicative scattering correction (MSC) is used to correct spectral changes caused by particle scattering. In water bodies with high turbidity, scattering has a significant impact, and MSC can effectively reduce this impact, improving the consistency of spectral data. Standard normal transformation (SNV) reduces differences between samples through standardization, making it suitable for spectral data collected under different conditions and enhancing data comparability. 120 combinations cover the effects of single methods and the synergistic effects of multiple methods. For example, the combination of baseline correction and MSC can remove baseline drift and correct for scattering effects, making it suitable for complex aquatic environments. Traditional methods rely on manual selection of a single preprocessing method, which may not be able to cope with diverse aquatic conditions. In contrast, this scheme automatically searches for the optimal combination, ensuring the targetedness and effectiveness of preprocessing.

[0069] Technical Effects: The construction of the preprocessor search space significantly improves the adaptability of preprocessing and model accuracy. First, multiple preprocessing combinations can address various water body interference factors. For example, in water bodies with high suspended matter content, the combination of the multiplicative scattering correction method (MSC) and the first-order difference method effectively removes scattering effects and highlights feature changes, reducing the average relative error of suspended matter from 27.8% to 7.71%. Second, automated search for the optimal combination replaces manual selection, avoiding inappropriate preprocessing methods due to insufficient experience and improving the scientific rigor of preprocessing. For example, for the transparency index, traditional methods may result in errors as high as 132.6% due to inappropriate preprocessing selection, while this scheme reduces the error to 12.24% by searching for the optimal combination. Furthermore, the preprocessing combination enhances the saliency of spectral features. Baseline correction algorithms remove drift, and MIN-MAX normalization eliminates magnitude differences, enabling the model to more clearly identify spectral features related to water quality indicators, improving model learning efficiency and shortening training time. Furthermore, the comprehensiveness of 120 combinations ensures that suitable preprocessing methods can be found in different water environments. For example, in different water bodies such as lakes and rivers, the model can search for and select appropriate combinations, enhancing the framework's versatility. Finally, the high-quality spectral data after preprocessing lays the foundation for subsequent model training, enabling the model to learn the mapping relationship between spectra and water quality indicators more accurately, thus improving the stability and reliability of the entire inversion framework.

[0070] Example 6

[0071] This solution discloses a hyperspectral water quality inversion algorithm framework based on machine learning. In S6, a variety of models commonly used in water quality inversion tasks are used to form the search space, including partial least squares, random forest, and XGBoost algorithm. For skewed label data, a label data converter is introduced, which takes the logarithm during training and automatically restores the logarithm after inference.

[0072] Solution Analysis: The S6 model search space design takes into account the characteristics of different models and the distribution features of water quality indicators, solving the problem of insufficient adaptability of traditional single models. Partial least squares is suitable for processing high-dimensional data, effectively extracting the main components in spectral data and reducing the impact of the curse of dimensionality. It is often used to establish a linear relationship between spectra and indicators in water quality inversion. Random forest, as an ensemble learning model, has strong anti-overfitting ability through the voting mechanism of multiple decision trees and can handle nonlinear relationships. It is suitable for scenarios where there are complex nonlinear correlations between spectral features and water quality indicators, such as the inversion of suspended solids concentration. XGBoost is an optimization based on random forest, which improves the model's accuracy and training speed through gradient boosting technology. It is suitable for the inversion of water quality indicators with high accuracy requirements, such as total nitrogen and ammonia nitrogen. The combination of the three models covers scenarios with linear, nonlinear, and high-precision requirements, providing suitable model selection for different water quality indicators. To address the skewed distribution of some label data, a label data transformer is introduced. During training, the logarithm is taken to make the data distribution closer to a normal distribution, solving the problem that skewed data causes the model to predict high or low values. For example, the raw data distribution of indicators such as total nitrogen and ammonia nitrogen often exhibits skewness. Taking the logarithm makes the distribution more uniform, allowing the model to learn features from different value ranges more evenly. During inference, the model is automatically restored to ensure the accuracy of the output results. In traditional methods, model selection often relies on experience and does not handle skewed data, resulting in low prediction accuracy for some indicators. The design of this scheme is more scientific and improves the adaptability of the model.

[0073] Technical Results: The design of the model search space and label converter significantly improved the model's adaptability and prediction accuracy. First, the selection of multiple models allowed for optimal matching of different water quality indicators. For example, in chlorophyll retrieval, the XGBoost model better captured its complex relationship with the spectrum, reducing the average relative error from 33.5% to 8.05%. Partial least squares performed better when handling indicators with strong linear relationships, ensuring the retrieval accuracy of each indicator. Second, the label data converter effectively solved the problem of skewed distribution. After logarithmic transformation, the model could more evenly learn the characteristics of different concentration ranges for indicators such as total nitrogen and ammonia nitrogen. In the experimental data, the average relative error of total nitrogen decreased from 34.4% to 4.72%, and that of ammonia nitrogen decreased from 39.2% to 4.74%, demonstrating significant improvement. Furthermore, the introduction of ensemble models enhances the model's robustness against interference. Random forests and XGBoost effectively handle noise and redundant information in hyperspectral data, reducing prediction errors caused by fluctuations in spectral data. For example, in turbidity inversion, the model can stably capture spectral changes corresponding to water turbidity, reducing the average relative error from 61.3% to 11.98%. In addition, the diversity of models improves the framework's versatility. Regardless of whether the water environment is simple or complex, a suitable model can be found through search, enhancing the framework's applicability in different scenarios. For example, it can maintain high-accuracy inversion results in different water bodies such as lakes, rivers, and reservoirs. Finally, the automatic restoration function of the label converter ensures the usability of the output results without manual intervention, improving the framework's automation and practicality.

[0074] Example 7

[0075] This scheme discloses a hyperspectral water quality inversion algorithm framework based on machine learning, wherein the hyperparameters applicable to each model in S7 are listed in a grid-like hyperparameter space.

[0076] Solution Analysis: The grid-based hyperparameter space constructed by S7 provides a systematic search range for the optimization of each model, solving the problems of arbitrary hyperparameter settings and insufficient optimization in traditional methods. For partial least squares (PLS), the hyperparameter space includes 5-20 principal components. The choice of the number of principal components directly affects the model's dimensionality reduction effect on spectral data; too few may lose important information, while too many may introduce noise. By setting the grid-based space, the optimal number of principal components can be found, balancing information preservation and noise removal. The hyperparameters of random forest include 100-500 decision trees, a maximum depth of 5-20, and a minimum number of split samples of 2-10. The number of decision trees affects the model's stability and training time; too few trees result in high model variance, while too many trees lead to time-consuming training. The maximum depth controls the complexity of the decision trees; too deep trees are prone to overfitting, while too shallow trees lead to underfitting. The minimum number of split samples affects the precision of node splits. The grid-based space ensures that the combination of these parameters can be fully searched to find the optimal configuration. XGBoost's hyperparameters include a learning rate of 0.01-0.3, tree depth of 3-10, and subsample ratio of 0.6-1.0. The learning rate controls the step size of each iteration; too small a rate leads to slow convergence, while too large a rate can cause overfitting. Tree depth and subsample ratio affect the model's complexity and generalization ability. The grid space provides a reasonable search range for these parameters. In traditional methods, hyperparameters are often set to fixed values ​​based on experience, making it difficult to adapt to different datasets. However, this approach combines grid space with multi-fold cross-validation search to find suitable hyperparameter combinations for each model, thereby improving model performance.

[0077] Technical Results: The construction of the grid-based hyperparameter space significantly improves the accuracy and generalization ability of the models. First, hyperparameter optimization for each model optimizes its performance. For example, by optimizing the number and maximum depth of decision trees, Random Forest enhances its resistance to overfitting in suspended matter retrieval, reducing the average relative error from 27.8% to 7.71%. XGBoost, by optimizing the learning rate and tree depth, significantly improves accuracy in total nitrogen retrieval, reducing the error from 34.4% to 4.72%. Second, the systematic search for hyperparameters avoids the subjectivity of manual settings, enabling the model to maintain stable performance across different datasets. For instance, in water monitoring across different seasons, optimized hyperparameters allow the model to adapt to seasonal changes in spectral characteristics, ensuring consistency in retrieval results. Third, the reasonable setting of hyperparameter space intervals balances search efficiency and optimization effectiveness. The intervals set according to academic literature reduce ineffective searches, making the search process more efficient and enabling the rapid finding of optimal hyperparameters even on large-scale datasets, thus enhancing the overall practicality of the framework. Furthermore, hyperparameter optimization enhances the model's generalization ability, enabling it to perform well not only on the training set but also maintain high accuracy on independent test sets. For example, the test set error for transparency decreased from 132.6% to 12.24%, validating the model's generalization capability. Finally, the mesh-based search of hyperparameters provides a foundation for subsequent iterative optimization of the model, allowing for continuous adjustment of hyperparameter ranges based on new datasets to continuously improve model performance.

[0078] Example 8

[0079] This scheme discloses a hyperspectral water quality inversion algorithm framework based on machine learning, wherein S8 performs optimal model search based on multi-fold cross-validation for three spaces respectively; the optimal preprocessing method, optimal model and optimal hyperparameters found are encapsulated into a pipeline.

[0080] Solution Analysis: S8's optimal model search and pipeline encapsulation design achieves systematic optimization of preprocessing, model, and hyperparameters, solving the problem of unsystematic optimization in traditional methods. Multi-fold cross-validation divides the dataset into multiple subsets, alternating between training and validation sets, allowing the model to be evaluated on different data distributions, reducing the impact of randomness in data partitioning on the selection of the optimal combination. The search process proceeds sequentially: first, the model and hyperparameters are fixed to search for the optimal preprocessing combination; then, the preprocessing and hyperparameters are fixed to search for the optimal model; finally, the preprocessing and model are fixed to search for the optimal hyperparameters. This step-by-step search reduces the complexity of the search and ensures that each step finds the optimal solution under the current conditions. Using mean squared error as the evaluation metric effectively reflects the model's prediction accuracy and guides the selection of the optimal combination. Encapsulating the optimal preprocessing method, model, and hyperparameters into a pipeline achieves end-to-end processing from data input to prediction output, avoiding connection problems between steps and ensuring the consistency of the processing flow. In traditional methods, the selection of preprocessing, models, and hyperparameters is independent, often leading to poor combined results. However, the step-by-step search and encapsulation design in this approach allows these three elements to work collaboratively for optimal performance. Furthermore, the pipeline is constructed independently for each individual water quality indicator, ensuring that each indicator has a suitable optimal combination. This avoids the problem of low accuracy for some indicators due to uniform processing. For example, the pipelines for chlorophyll and turbidity use different preprocessing, models, and hyperparameters, each achieving optimal accuracy.

[0081] Technical Results: The optimal model search and pipeline encapsulation design significantly improve the overall performance and practicality of the model. First, the systematic search enables the preprocessing, model, and hyperparameters to form an optimal combination, synergistically improving prediction accuracy. The average relative error of multiple indicators in the experimental data was significantly reduced; for example, chlorophyll decreased from 33.5% to 8.05%, and total nitrogen from 34.4% to 4.72%, validating the effectiveness of the combined optimization. Second, multi-fold cross-validation reduces the impact of data partitioning, making the selection of the optimal combination more robust and avoiding bias caused by a single data partition. For example, in transparency inversion, cross-validation ensures that the selected combination maintains low error across different data subsets, ultimately reducing the error from 132.6% to 12.24%. Third, the pipeline encapsulation automates the process, integrating preprocessing, model, and hyperparameters into an end-to-end processing flow. The entire process from data input to prediction output can be completed without manual intervention, improving inversion efficiency and making it suitable for real-time water quality monitoring scenarios. By constructing independent pipelines for each individual metric, the optimal processing flow is achieved for each metric. For example, the ammonia nitrogen pipeline uses a specific combination of preprocessing, an XGBoost model, and optimized hyperparameters, reducing the error from 39.2% to 4.74%. The dissolved oxygen pipeline, using different combinations, reduced the error from 23% to 2.61%, demonstrating the advantages of personalized processing. Furthermore, the encapsulation of pipelines facilitates model deployment and migration, allowing direct application to new hyperspectral data inversion, reducing the difficulty of model deployment and enhancing the framework's practicality. Finally, this systematic optimization approach enables continuous improvement of the framework. By adding new preprocessing methods, models, or hyperparameter ranges, the pipeline can be continuously updated, improving inversion accuracy.

[0082] Example 9

[0083] This scheme discloses a hyperspectral water quality inversion algorithm framework based on machine learning. In S10, an inversion data filter based on TV smoothing is constructed, which can perform smoothing and stabilization processing in real time based on the generated inversion data, effectively mitigating the volatility of the results. It needs to be connected in series with the pipeline to generate a stable water quality inversion model.

[0084] Solution Analysis: The S10 inversion data filter design addresses the issue of large fluctuations in model output over time, improving the stability of the inversion results. The filter, based on total variation (TV) smoothing, processes new input data through a sliding window mechanism. When the amount of data within the window is ≥2, smoothing is performed by minimizing the balance function between the TV and original data deviations, preserving the overall trend of the data while reducing local fluctuations. The core of TV smoothing is to avoid feature loss due to over-smoothing while smoothing the data, balancing data stability and accuracy. The filter is connected in series with the pipeline, ensuring that the original prediction results output by the pipeline are smoothed before being output, forming a complete inversion model and ensuring the stability of the output results. In traditional methods, model outputs often change significantly due to small fluctuations in spectral data, which is detrimental to subsequent water quality early warning algorithms. This solution's filter can process data in real time. For example, in continuous monitoring, the fluctuation amplitude of dissolved oxygen inversion results is significantly reduced after smoothing, providing a stable input for the early warning algorithm. In addition, the size of the sliding window can be adjusted according to real-time requirements (5-10 data points), balancing smoothness and real-time performance. It is suitable for different monitoring scenarios, such as using a smaller window for drinking water source monitoring with high real-time requirements and a larger window for lake monitoring with high stability requirements.

[0085] Technical Effects: The design of the inversion data filter significantly improves the stability and practicality of the inversion results. Firstly, it effectively mitigates the volatility of the results. TV smoothing balances the total variation with the original data bias, making the output results smoother over time. For example, after smoothing, the turbidity inversion results show more gradual changes in values ​​between adjacent time points, avoiding interference from drastic fluctuations on the early warning algorithm, allowing the algorithm to more accurately judge water quality change trends. Secondly, real-time processing capabilities ensure that the filter can adapt to online monitoring scenarios. New data is immediately added to the sliding window and processed, outputting the smoothed results of the latest data, meeting the real-time requirements of water quality monitoring. For example, in the event of a sudden water pollution incident, it can output stable inversion results in a timely manner, supporting rapid response. Furthermore, the cascading of the filter and the pipeline forms a complete inversion model, creating a closed loop from data input to stable output, improving the framework's integrity and ease of use. Users can obtain stable water quality index data without additional processing. In the experimental data, the smoothed inversion results of each indicator showed a reduction of over 30% in fluctuation over time, providing a reliable data foundation for subsequent water quality trend analysis and early warning. Furthermore, the adjustability of the sliding window size enhances the filter's adaptability. Appropriate window sizes can be selected for different water environments and monitoring needs. For example, in fast-flowing rivers, a smaller window (5 data points) is used to quickly respond to water quality changes; in calm lakes, a larger window (10 data points) is used to obtain more stable results. Finally, the introduction of the filter did not reduce the model's prediction accuracy; rather, it improved stability while maintaining accuracy. For instance, the average relative error of dissolved oxygen remained at 2.61%, while fluctuations over time were significantly reduced, balancing accuracy and stability.

[0086] Specifically, a comparison of relevant test data and practical application data for this solution.

[0087]

[0088] Data Description: The experimental data were obtained from comparative tests under the same water environment, using the same hyperspectral data and label data. Water quality inversion was performed using both the traditional BP neural network method and this proposed method. The traditional method did not employ automated preprocessing search, multi-model selection, or hyperparameter optimization, nor did it perform data aggregation or output smoothing. This proposed method, however, strictly followed steps S1-S11 to ensure consistency of experimental conditions.

[0089] Data validity explanation: The experimental sample size was 800 sets (covering water body data under different seasons and weather conditions), with the test set accounting for 10% (80 sets), independent of the training process, ensuring the objectivity of the evaluation results. The mean relative error was used as the evaluation index, effectively reflecting the differences in prediction accuracy between different methods. The errors for total phosphorus and permanganate increased slightly, mainly because these two indicators have a weak correlation with spectral characteristics, and the optimization of this scheme had limited improvement on them; however, the overall improvement is still within an acceptable range. The significant improvement in other indicators validates the effectiveness of this scheme.

[0090] Working Principle: This solution primarily utilizes a fully automated hyperspectral water quality inversion framework to achieve end-to-end processing from data acquisition to stable inversion result output. First, S1 collects water surface reflectance spectral data in the 400-1000 Hz band using a suspended hyperspectral analyzer, combining it with tag data acquired from laboratory or portable devices to provide raw data for the inversion. S2 cleans the spectral data, removing outliers, zero values, and Nan values ​​to ensure data quality. S3 aggregates hyperspectral data within 75 seconds, based on the sampling time of the tag data, expanding the sample size and addressing the small sample size issue. S4 divides the data into training, validation, and test sets in an 8:1:1 ratio, with 90% of the data used for 10-fold cross-validation and 10% for independent evaluation of the test set. S5 constructs a search space encompassing five preprocessing methods, resulting in 120 combinations to cover different preprocessing needs. S6 constructs search spaces for three models: partial least squares regression, random forest, and XGBoost, and introduces a label converter to handle skewed data. S7 constructs a mesh-based hyperparameter space for each model, such as 100-500 decision trees for a random forest. S8 employs multi-fold cross-validation, sequentially searching for the optimal preprocessing, model, and hyperparameters. Using mean squared error as the metric, the optimal combination is encapsulated into a pipeline, with independent construction for each metric. S10 introduces a TV-based inversion data filter, smoothing the pipeline output through a sliding window, achieving stable results when the data volume is ≥2. S11 evaluates model performance on the test set using the mean relative error. The entire process replaces manual experience with automated search, independently optimizing for different metrics, and combining data smoothing to achieve high-precision and stable water quality inversion.

[0091] Technical Effects of Implementing this Solution: This solution achieves several technological breakthroughs in the field of water quality monitoring. In terms of prediction accuracy, compared to traditional BP neural networks, the average relative error of each water quality indicator is significantly reduced: chlorophyll from 33.5% to 8.05%, total nitrogen from 34.4% to 4.72%, transparency from 132.6% to 12.24%, and dissolved oxygen from 23% to 2.61%. This significantly improves the accuracy of water quality parameter retrieval, providing more reliable data for water quality assessment. In terms of automation, through S8's multi-fold cross-validation search and pipeline encapsulation, preprocessing, model, and hyperparameter selection are fully automated, reducing manual intervention, significantly shortening parameter optimization time, and enabling the framework to adapt to large-scale, high-frequency water quality monitoring needs, thus improving monitoring efficiency. In terms of data utilization, S3's 75-second data aggregation expands the sample size several times over. Combined with S4's scientific partitioning and 10-fold cross-validation, it solves the problem of insufficient training with small samples (500-1000), enhances the model's generalization ability, and enables the model to maintain stable performance in complex aquatic environments, such as rivers and lakes, achieving accurate inversion. Regarding multi-indicator adaptability, S9 constructs independent pipelines for each indicator. Combined with S6's skewed data logarithmic transformation, it ensures that different indicators (such as chlorophyll, total nitrogen, and suspended solids) can obtain suitable processing flows, avoiding the problem of insufficient adaptability of a unified model and improving the inversion accuracy of each indicator. In terms of output stability, S10's TV smoothing filter effectively reduces temporal fluctuations, making the inversion results smoother and providing stable input for subsequent water quality early warning algorithms, enhancing the practicality of the monitoring system. Furthermore, the framework is highly flexible; the time window and sliding window size can be adjusted according to actual conditions, making it suitable for different aquatic environments and monitoring needs, and has broad application prospects.

[0092] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. It will be apparent to those skilled in the art that the present invention is not limited to the details of the exemplary embodiments described above, and that the invention can be implemented in other specific forms without departing from its spirit or essential characteristics. Therefore, the embodiments should be considered illustrative and non-limiting in all respects, and the scope of the invention is defined by the appended claims rather than the foregoing description. Thus, all variations falling within the meaning and scope of equivalents of the claims are intended to be included within the present invention. No reference numerals in the claims should be construed as limiting the scope of the claims.

[0093] Furthermore, it should be understood that although this specification describes embodiments, not every embodiment contains only one independent technical solution. This narrative style is merely for clarity. Those skilled in the art should consider the specification as a whole, and the technical solutions in each embodiment can also be appropriately combined to form other embodiments that can be understood by those skilled in the art.

Claims

1. A hyperspectral water quality inversion algorithm framework based on machine learning, characterized in that: Includes the following steps: S1. Collect training data and label data; S1.

1. A suspended hyperspectral imager is used to collect the spectral data of orthophotos from the surface of the water body. The data contains information in the 400-1000 band and is represented as a 1*601 array. The data is transmitted in real time and the acquisition time is recorded. S1.2 Collect actual water quality data as label data. The data comes from laboratory analysis or portable water quality rapid testing equipment. The indicators include chlorophyll, total nitrogen, total phosphorus, transparency, chemical oxygen demand, ammonia nitrogen, suspended solids, and dissolved oxygen. Record the sampling time. S2. Data Cleaning: Traverse the hyperspectral data and delete data that meets the following characteristics; S2.

1. Does not conform to the spectral characteristics of water quality; values ​​in specific bands are significantly higher than those in other bands. S2.2, Contains zero or Nan values; S3. Data Aggregation: Based on the sampling time of each label data, match the hyperspectral data within 75 seconds before and after its time point (adjustable), and bind the individual label data with the matched hyperspectral data to expand the dataset; S4. Data partitioning: The data is divided into training set, validation set, and test set in an 8:1:1 ratio. 10% of the test set is not used for training, and the remaining 90% of the data is used for optimal parameter search using 10-fold cross-validation. S5. Constructing the preprocessor search space: including baseline correction algorithm, first-order difference method, MIN-MAX normalization, multiplicative scattering correction method (MSC), standard normal transformation (SNV), forming 120 preprocessing combinations through permutation and combination; S6. Constructing the model search space: including Partial Least Squares Regression (PLS), Random Forest (RF), and XGBoost (XGB) algorithms; for skewed label data, a label data transformer is introduced, which takes the logarithm of the labels during training and automatically restores them after inference; S7. Constructing the hyperparameter search space: For each model in step S6, set the hyperparameter range with reference to academic literature to form a mesh hyperparameter space; S8. Optimal combination search: Multi-fold cross-validation is used. The optimal preprocessing combination is searched by fixing the model and hyperparameters in sequence, the optimal model is searched by fixing the preprocessing and hyperparameters in sequence, and the optimal hyperparameters are searched by fixing the preprocessing and model in sequence. The mean squared error (MSE) is used as the evaluation index. S9. Pipeline construction: Combine the optimal pretreatment method, model and hyperparameters obtained in step S8 into an end-to-end treatment process, and construct a pipeline independently for each water quality index. S10. Constructing the inversion filter: Using a filter based on total variation (TV) smoothing, new input data is added to a sliding window. When the window data size is ≥2, smoothing is performed by minimizing the balance function of the deviation between the total variation and the original data, and the smoothed result of the latest data is output. The filter is connected in series with the pipeline to form a complete inversion model. S11. Performance Evaluation: The model is evaluated on the test set using the Mean Relative Error (MRE). The MRE calculation formula is as follows: Where y i For the true value, is the predicted value, and m is the sample size.

2. The hyperspectral water quality inversion algorithm framework based on machine learning according to claim 1, characterized in that: In step S1.1, the hyperspectral data acquisition is carried out in real time around the clock, with the recording time accurate to the second.

3. The hyperspectral water quality inversion algorithm framework based on machine learning according to claim 1, characterized in that: The 75-second time window in step S3 can be adjusted according to the stability of the water body. For water bodies with poor stability, it can be shortened to 50 seconds, while for water bodies with good stability, it can be extended to 100 seconds.

4. The hyperspectral water quality inversion algorithm framework based on machine learning according to claim 1, characterized in that: In step S5, the search method for preprocessing combinations is exhaustive, covering all permutations and combinations of the five preprocessing methods.

5. The hyperspectral water quality inversion algorithm framework based on machine learning according to claim 1, characterized in that: The logarithmic transformation of the label data converter in step S6 is applicable to skewed distribution indicators such as total nitrogen and ammonia nitrogen. The transformation formula is y′=log(y+1), and the restoration formula is y=e y′ -1.

6. The hyperspectral water quality inversion algorithm framework based on machine learning according to claim 1, characterized in that: The hyperparameter space in step S7 includes: Hyperparameters of random forest: number of decision trees (100-500), maximum depth (5-20), minimum number of split samples (2-10); XGBoost hyperparameters: learning rate (0.01-0.3), tree depth (3-10), subsample ratio (0.6-1.0); Hyperparameters of partial least squares regression: number of principal components (5-20).

7. The hyperspectral water quality inversion algorithm framework based on machine learning according to claim 1, characterized in that: In step S10, the size of the sliding window is 5-10 data points, which can be adjusted according to real-time requirements.