Pipe network residual chlorine prediction and early warning method based on XGBoost-LSTM model
Patent Information
- Application Number
- CN202610887466.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-06-18
- Publication Date
- 2026-09-11
AI Technical Summary
[0004]本发明的目的在于提供一种基于XGBoost-LSTM模型的管网余氯预测及预警方法,旨在解决供水管网安培法余氯电极信号衰减导致的测量偏差问题,并推动水质监测从“被动应对”向“主动预测预警”转型
Smart Images

Figure CN122738696A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of water quality monitoring and intelligent early warning technology for water supply networks, specifically involving an intelligent prediction and early warning method for residual chlorine in water supply networks based on an XGBoost-LSTM hybrid model. Background Technology
[0002] Urban water supply networks are critical infrastructure for national welfare and people's livelihood, and water quality safety directly impacts public health. Residual chlorine, as a core indicator for inhibiting microbial regeneration and ensuring the safety of water transmission and distribution, makes the establishment of online water quality monitoring systems an important requirement for smart water management. Amperometric electrodes are widely used due to their advantages of fast response, low cost, and easy integration; however, their long-term operation has inherent drawbacks: maintaining a constant polarization voltage requires application, which easily leads to oxidative contamination of the electrode surface and the formation of an insulating coating, causing continuous signal attenuation and negative drift in measured values, severely affecting data reliability and increasing maintenance costs.
[0003] Currently, the industry mainly uses regular manual cleaning and mechanical scraping for hardware maintenance. While these methods can restore performance in the short term, they are reactive, prone to monitoring interruptions, and difficult to adapt to complex water quality environments. Furthermore, their high cost restricts the large-scale application of urban lifeline water quality monitoring projects. Therefore, there is an urgent need for an intelligent method that can solve the problem of electrode signal attenuation and achieve proactive water quality prediction and early warning. Summary of the Invention
[0004] The purpose of this invention is to provide a method for predicting and warning of residual chlorine in water supply networks based on the XGBoost-LSTM model, which aims to solve the measurement deviation problem caused by the signal attenuation of the amperometric residual chlorine electrode in water supply networks, and to promote the transformation of water quality monitoring from "passive response" to "proactive prediction and early warning".
[0005] To achieve the above objectives, the present invention adopts the following technical solution:
[0006] A method for predicting and warning of residual chlorine in pipeline networks based on the XGBoost-LSTM model includes the following steps:
[0007] Step S1: Deploy a parallel monitoring system for colorimetry and electrode method, construct a dataset containing the original electrode measurement value FCL_ect and the true colorimetric value HCL_true, and use the attenuation deviation Δ = HCL_true - FCL_ect as the learning target;
[0008] Step S2: Construct a compensation model based on the extreme gradient boosting XGBoost algorithm. Use a two-stage process of "offline training - online application" to dynamically correct the electrode signal and obtain the compensated residual chlorine sequence FCL_comped = FCL_ect + Δ̂, where Δ̂ is the attenuation deviation predicted by the XGBoost model.
[0009] Step S3: Construct a time series prediction model based on the Long Short-Term Memory (LSTM) network. Using the compensated residual chlorine sequence FCL_comped obtained in Step S2 as the data source, and employing the sliding window technique, the model uses the time series data of the past 24 hours as input to predict the residual chlorine concentration for the next hour and multiple steps.
[0010] Step S4: Construct a three-level dynamic threshold early warning mechanism based on the predicted value, compare the deviation between the current monitored value and the predicted value of the LSTM model in real time, and trigger a first-level reminder, a second-level warning or a third-level alarm response according to the degree of deviation;
[0011] Step S5: Integrate steps S2 to S4 to form an integrated technical closed loop of "precise compensation - intelligent prediction - early warning".
[0012] In step S2, the construction of the XGBoost compensation model specifically includes:
[0013] The residual chlorine error data of the first 9 time steps of the sequence are used as input features, and the residual chlorine error of the 10th time step is used as the prediction target.
[0014] The model parameters were set as follows: number of estimators 120, learning rate 0.5, maximum tree depth 10, and the squared error loss function was used.
[0015] When used in online applications, the system dynamically iterates through an autoregressive sliding window mechanism, embedding the previous round's predicted value into the lag_1 position of the lagged feature sequence to complete continuous predictions.
[0016] In step S3, the structure of the LSTM time series prediction model is as follows: it contains 4 LSTM hidden layers, each with 160 hidden units, and the end is connected to a linear output layer; the training uses the AdamW optimizer, with mean squared error (MSE) as the loss function, an initial learning rate of 0.0001, and 1500 training rounds.
[0017] The three-level dynamic threshold early warning mechanism in step S4 is as follows:
[0018] Level 1 Alert: Triggered when the deviation of the monitored value from the predicted value is within ±0.02 mg / L, prompting maintenance personnel to pay attention to the equipment's operating status;
[0019] Level 2 Warning: Activated when the deviation exceeds the normal fluctuation range of ±0.03 mg / L, automatically marking abnormal data segments and pushing out troubleshooting suggestions;
[0020] Level 3 alarm: Activated when the deviation reaches the upper limit of the water quality safety standard ±0.05mg / L, simultaneously triggering audible and visual alarms, mobile terminal push notifications, and linking to the preset emergency response process.
[0021] In step S1, the data collection frequency is 30 seconds / time, and preprocessing is performed using 60-minute interval sliding aggregation resampling to obtain a normalized dataset; the dataset is divided in chronological order, with the first 30 days of data as the training set and the last 4 days of data as the validation set.
[0022] The mean absolute error (MAE) of the XGBoost compensation model on the validation set decreased from 0.2526 mg / L before compensation to 0.1102 mg / L after compensation, a reduction of 56.37%, and the coefficient of determination (R²) increased to over 0.89.
[0023] The LSTM time series prediction model had a prediction bias of 0.0166 mg / L to 0.0264 mg / L in the first 2 hours, with a relative error of 3.5% to 5.7%; the mean absolute error (MAE) was 0.0346 mg / L, the mean relative error was 8.03%, and the coefficient of determination (R²) was 0.812.
[0024] The LSTM model is deployed on an edge computing device and obtains real-time residual chlorine monitoring data from a MySQL database via an industrial Ethernet network. It uses data from the past 24 hours to predict the residual chlorine concentration for the next 4 hours and automatically calculates the MAE, MAPE, and R² accuracy indicators.
[0025] The system integrates a fault self-diagnosis function: when the original electrode signal is detected to be continuously and slowly decreasing while the compensated data remains accurate, a sensor performance degradation prompt is generated based on the signal attenuation characteristics, realizing the transformation from "post-event maintenance" to "predictive maintenance".
[0026] During continuous operation testing at multiple monitoring nodes in the water supply network, the system can identify local pollution intrusion events characterized by a sudden drop in residual chlorine accompanied by a slight increase in turbidity, and trigger a level-three early warning before the anomaly occurs, thus providing a time window for emergency response.
[0027] Compared with the prior art, the present invention has the following beneficial effects:
[0028] 1. Precise compensation to solve the signal attenuation problem: The XGBoost compensation model proposed in this invention reduces the mean absolute error (MAE) of electrode measurements over 34 days from 0.2526 mg / L to 0.1102 mg / L, a reduction of 56.37%. This effectively corrects the signal attenuation deviation of the residual chlorine electrode, significantly improving the accuracy and reliability of measurement data, and providing an innovative solution to overcome the problem of electrode signal attenuation.
[0029] 2. Intelligent prediction for early warning: The LSTM prediction model constructed in this invention has a prediction deviation of 0.0166 mg / L to 0.0264 mg / L in the first 2 hours, with a relative error of 3.5% to 5.7%. It can accurately capture the overall trend of change within 4 hours, providing a quantitative basis for early warning of water quality anomalies.
[0030] Tiered early warning improves operation and maintenance efficiency: The constructed three-level dynamic threshold early warning mechanism enables early identification and tiered control of abnormal situations. Through verification of real pipeline network anomalies, the system can successfully achieve online prediction and early warning of residual chlorine, effectively shortening the event handling time and promoting the transformation of water quality safety management from passive response to proactive intervention.
[0031] 3. Low cost and easy to promote: The solution of this invention can be implemented by simply upgrading the software algorithm without modifying the existing hardware. It has the advantages of low cost, quick results and easy promotion, providing a feasible path for intelligent monitoring of water quality in water supply networks. Attached Figure Description
[0032] Figure 1 This is a flowchart of the XGBoost-LSTM hybrid early warning model of the present invention.
[0033] Figure 2 This is a data curve diagram of the XGBoost model of this invention.
[0034] Figure 3 This is a curve showing the fitting of the training data for the XGBoost model of this invention.
[0035] Figure 4 This is a prediction curve of the XGBoost model of this invention.
[0036] Figure 5 This is a performance comparison curve before and after the correction of the compensation model of this invention.
[0037] Figure 6 This is a graph showing the residual chlorine data of the pipeline network over 30 days according to the present invention.
[0038] Figure 7 This is a graph showing the fitting effect of the LSTM model training data in this invention.
[0039] Figure 8 This is a graph showing the residual chlorine prediction using the LSTM model of this invention.
[0040] Figure 9 Add a hysteresis feature example table to this invention. Figure 10 This is a comparison table of the performance of the electrodes before and after compensation in this invention. Figure 11 This is an hourly error table between the predicted and actual values of the model in this invention. Detailed Implementation
[0041] To make the objectives, technical solutions, and advantages of the present invention clearer, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0042] like Figure 1 As shown, a method for predicting and warning of residual chlorine in a pipeline network based on the XGBoost-LSTM model includes the following steps:
[0043] Step 1: Deploy a parallel monitoring system using colorimetric and electrode methods, and build a dataset.
[0044] A parallel monitoring system combining colorimetric and electrode methods was deployed. The experimental group used a commercial residual chlorine electrode to output the raw measurement value in real time (denoted as FCL_ect); the control group used a high-precision colorimetric residual chlorine analyzer to simultaneously obtain the true residual chlorine value (denoted as HCL_true). Based on a 34-day parallel monitoring dataset, the attenuation deviation Δ = HCL_true - FCL_ect was used as the core learning objective to construct a model training and validation dataset.
[0045] Step 2: Build and train the XGBoost compensation model
[0046] A regression prediction model based on the Extreme Gradient Boosting (XGBoost) algorithm was constructed to compensate for electrode signals. A two-stage execution flow of "offline training - online application" was adopted.
[0047] Offline phase: Based on the dataset from step 1, the model parameters are trained by taking the residual chlorine error data of the first 9 time steps of the sequence as input and the residual chlorine error of the 10th time step as the prediction target.
[0048] In the online application phase: real-time collected electrode measurements are input into the trained XGBoost model to generate a predicted attenuation deviation value Δ̂. The residual chlorine concentration is then dynamically corrected using the compensation formula FCL_comped = FCL_ect + Δ̂.
[0049] Step 3: Build and train the LSTM time series prediction model
[0050] A time-series prediction model based on a Long Short-Term Memory (LSTM) network was constructed. Using the high-precision residual chlorine sequence (FCL_comped) compensated in step 2 as the data source, and employing the time-series data from the past 24 hours as input features, the model predicts the residual chlorine value for the next hour and continuously predicts residual chlorine values for multiple hours to come. The LSTM model consists of four LSTM layers, each with 160 neurons, and is trained using the AdamW optimizer with mean squared error (MSE) as the loss function.
[0051] Step 4: Construct a three-level dynamic threshold early warning mechanism based on predicted values
[0052] A three-level dynamic threshold early warning mechanism based on model predictions is constructed. By comparing the deviation between the current monitored value and the LSTM model prediction value in real time, a three-level progressive early warning response is triggered.
[0053] Level 1 Alert: Automatically triggered when the deviation of the monitored value from the predicted value is within ±0.02 mg / L, used to remind maintenance personnel to pay attention to the equipment's operating status;
[0054] Level 2 Warning: This level is activated when the deviation continues to increase and exceeds the normal fluctuation range of ±0.03 mg / L. The system automatically marks the abnormal data segment and pushes preliminary troubleshooting suggestions.
[0055] Level 3 alarm: Activated when the deviation reaches the upper limit of the water quality safety standard ±0.05mg / L, simultaneously triggering multiple channels of notification, including audible and visual alarms and mobile push notifications, and linking with the preset emergency response process.
[0056] Step 5: Form an integrated technology closed loop of "precise compensation - intelligent prediction - early warning"
[0057] Integrating the above steps forms an intelligent prediction and early warning system that ranges from data correction and time-series prediction to tiered early warning.
[0058] Example 1: Data Acquisition and Preprocessing (Combined) Figure 2 and Figure 9 )
[0059] The experimental data for this invention comes from the online residual chlorine monitoring system of a residential water supply network in Changzhou. The data collection period was from September 10th to October 14th, 2024, with a sampling frequency of approximately 30 seconds per data entry, accumulating to 92,195 sets of continuous monitoring data. To reduce data volatility and highlight trends, a time window resampling method was used to preprocess the raw data: sliding aggregation was performed at 60-minute intervals, ultimately resulting in 816 sets of normalized datasets containing standard residual chlorine values (HCL_true) and original sensor measurements (FCL_ect). Their temporal distribution characteristics are as follows: Figure 2 As shown.
[0060] The dataset was divided according to the principle of time series continuity. The first 30 days, totaling 720 sets of data, were set as the training set for feature construction and model training; the last 4 days, totaling 96 sets of data, were set as the validation set for model evaluation.
[0061] The process of constructing the model's target variable involves calculating the residual chlorine measurement error sequence using Δ_t = HCL_true - FCL_ect to quantify the bias caused by sensor attenuation. In the feature engineering stage, a sliding window technique is used to construct a multi-dimensional input feature set, specifically generating hysteresis features of orders 1 to 9, which serve as key input variables for the prediction model. For example... Figure 9As shown, each record contains the date, time, current residual chlorine value, and residual chlorine lag characteristic values (lag_1 to lag_9) for the previous 1 to 9 time steps.
[0062] Example 2: Construction and Training of the XGBoost Compensation Model (Combined with...) Figure 3 , Figure 4 , Figure 5 and Figure 10 )
[0063] To accurately capture the hysteresis correlation characteristics of residual chlorine error sequences, a regression prediction model based on the XGBoost algorithm was constructed. For example... Figure 1 As shown in the flowchart, the model input variable selects the residual chlorine error data of the first 9 time steps of the sequence, and uses the residual chlorine error of the 10th time step as the prediction target. The squared error loss function is used, the number of estimators is set to 120, the learning rate is 0.5, and the maximum tree depth is set to 10. The model training data fitting results are shown below. Figure 3 As shown, the mean absolute error (MAE) is 0.019233 mg / L, and the coefficient of determination R² reaches 0.9997, indicating that the model has excellent fitting accuracy on the training set.
[0064] To verify the predictive ability of the constructed model, a multi-step time series prediction framework based on lag features was used for validation. The prediction process is dynamically iterated through an autoregressive sliding window mechanism: each time, the lag feature window is shifted one step to the right along the time axis, and the latest predicted value from the previous round is embedded into the lag_1 position of the lag feature sequence. This dynamic update mechanism is used to continuously predict the residual chlorine decay value. The XGBoost model prediction curve is shown below. Figure 4 As shown, the mean absolute error (MAE) on the test set is 0.110203 mg / L.
[0065] Performance evaluation of compensation model: such as Figure 10 and Figure 5 As shown, the compensation model demonstrates significant correction performance on the test set compared to the original measurement results of the uncompensated electrodes. Figure 10 Data shows that the mean absolute error (MAE) before compensation was 0.2526 mg / L and the coefficient of determination (R²) was -1.13539; after compensation, the MAE decreased to 0.1102 mg / L, a reduction of 56.37%, and the R² increased to 0.89065. Figure 5 The performance comparison curves further show that the compensated data curve (solid line) matches the results of the standard measurement method (dashed line) well, and the attenuation deviation of the original electrode signal accumulated over time has been successfully calibrated.
[0066] Example 3: Construction and Training of LSTM Time Series Prediction Model (Combined with...) Figure 6 , Figure 7 , Figure 8 and Figure 11 )
[0067] The model development and training environment configuration for this study is as follows: operating system is Windows 11, programming language is Python 3.10, deep learning framework is PyTorch; hardware configuration is AMD Ryzen 9 7945HX processor, 16GB memory and NVIDIA GeForce RTX 4060 graphics card (8GB video memory).
[0068] Data preprocessing: Based on the raw residual chlorine data (sampling frequency of about 30 seconds, a total of 82,730 data points), the data was resampled and transformed into a 30-minute average sequence, resulting in 1,440 valid samples. Figure 6 The historical monitoring curves of residual chlorine concentration over 30 consecutive days are presented, clearly showing a stable fluctuation trend and strong time-series dependence. The sample division adopted a time-series method: the data from the first 29 days (1392 samples) served as the training set, and the data from the 30th day (48 samples) served as the test set. To optimize the training effect, the training set underwent a three-stage processing: first, 696 samples were extracted at hourly intervals to capture instantaneous fluctuation characteristics; then, normalization was performed; and finally, 672 time-series samples were generated using a 24-hour sliding window technique.
[0069] Model architecture and training: such as Figure 1 As shown on the right, the LSTM residual chlorine prediction model employs a four-layer LSTM hidden layer stacked structure, with 160 hidden units in each layer, connected to a linear output layer for regression prediction. The training process uses mean squared error (MSE) as the loss function, employing the AdamW optimizer for 1500 training epochs with an initial learning rate of 0.0001 and a dynamic scheduling mechanism. After 1500 training epochs (56.47 minutes), the loss value converged to 1.18 × 10⁻⁶. The training data fitting effect is shown below. Figure 7 As shown, the model performed well on 672 samples: the mean absolute error (MAE) was 0.000036 mg / L, the coefficient of determination (R²) was 0.999992, the mean absolute percentage error (MAPE) was 0.007353%, the maximum relative error was 0.42%, and the mean relative error was 0.01%.
[0070] Model Prediction and Evaluation: Considering engineering applications, the trained LSTM prediction model was deployed on an edge computing device with an Intel N95 processor and 16GB of memory, based on Python 3.10 and the PyTorch framework. The prediction model retrieves residual chlorine monitoring data from a MySQL database via industrial Ethernet and uses a sliding window to achieve multi-step prediction: predicting the concentration for the next hour based on data from the past 24 hours, and generating 4-hour and 6-hour prediction results in a rolling manner (e.g., ...). Figure 8 (As shown). The system integrates data preprocessing, model inference, and visualization modules to form a complete "acquisition-output" closed loop.
[0071] The LSTM model built based on the compensated data showed good predictive performance on the test set. Hourly assessment results of residual chlorine concentration are shown below. Figure 11 At 00:00, the actual value was 0.4742 mg / L, the predicted value was 0.4909 mg / L, the error was +0.0166 mg / L, and the relative error was 3.5%; at 01:00, the actual value was 0.4628 mg / L, the predicted value was 0.4892 mg / L, the error was +0.0264 mg / L, and the relative error was 5.7%; at 02:00, the error was +0.0361 mg / L, and the relative error was 8.2%; at 03:00, the error was +0.0593 mg / L, and the relative error was 14.7%. The relative error for the first two hours was 3.5%~5.7%, the mean absolute error (MAE) was 0.0346 mg / L, the mean relative error was 8.03%, and the coefficient of determination (R²) was 0.812. The results confirm that the model can effectively capture the temporal variation of residual chlorine, and the prediction accuracy increases gradually with time. However, the prediction results for the first two hours can directly serve water quality early warning and chlorination process control.
[0072] Example 4: Water Quality Early Warning System and Case Validation (Combined) Figure 1 (Three-level early warning process)
[0073] Early warning mechanism: such as Figure 1 As shown in the early warning module, this system constructs a three-level dynamic response mechanism based on absolute deviation by comparing the compensated monitoring data with the LSTM model prediction values in real time: a level one early warning is triggered when the relative deviation exceeds ±0.02 mg / L; a level two early warning is initiated when it exceeds ±0.03 mg / L; and a level three early warning is issued when it exceeds ±0.05 mg / L. The system monitors the above indicators in real time, and activates the corresponding early warning and automatically records the event when the threshold is exceeded.
[0074] Case 1 (Gradual Attenuation of Electrode Signal – Early Identification of Sensor Performance Degradation): In May 2025, the system detected a continuous and gradual decline in the original signal of an electrode at a pipeline node in a residential community. The model continuously corrected the signal to maintain data accuracy, and no water quality alarm was triggered. Based on the signal attenuation characteristics, the fault diagnosis module generated a sensor performance degradation warning on June 3. Maintenance personnel performed maintenance accordingly and discovered a dense oxide film on the electrode surface. This case demonstrates how the system, while ensuring data reliability, achieves a shift from "reactive maintenance" to "predictive maintenance."
[0075] Case 2 (Sudden Drop in Residual Chlorine Accompanied by Slight Increase in Turbidity – Suspected Localized Pollution Intrusion): On July 15, 2025, at 14:30, the residual chlorine at the entrance node of a residential community suddenly dropped from 0.35 mg / L to 0.18 mg / L within 30 minutes, while the turbidity increased from 0.12 NTU to 0.28 NTU during the same period. The LSTM model predicted that the residual chlorine would drop to 0.05 mg / L after 2 hours, and the system triggered a Level 3 warning at 15:00. The maintenance team, based on the characteristics of the pipeline network's end points, determined that the pollution was caused by a sudden change in hydraulic conditions, and the water quality recovered within 40 minutes after on-site flushing. In this case, the system provided a critical window for emergency response, effectively preventing user complaints.
[0076] In summary, this invention constructs an integrated technical closed loop of "precise compensation - intelligent prediction - early warning," providing intelligent technical support for ensuring urban water supply security. A six-month continuous operation test was conducted at 13 monitoring nodes in the Changzhou urban water supply network, and the results further confirmed its effectiveness and stability.
[0077] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. Those skilled in the art can make various improvements and modifications without departing from the principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A pipe network residual chlorine prediction and early warning method based on an XGBoost-LSTM model, characterized in that, Includes the following steps: Step S1: Deploy a parallel monitoring system for colorimetry and electrode method, construct a dataset containing the original electrode measurement value FCL_ect and the true colorimetric value HCL_true, and use the attenuation deviation Δ = HCL_true - FCL_ect as the learning target; Step S2: Construct a compensation model based on the extreme gradient boosting XGBoost algorithm. Use a two-stage process of "offline training - online application" to dynamically correct the electrode signal and obtain the compensated residual chlorine sequence FCL_comped = FCL_ect + Δ̂, where Δ̂ is the attenuation deviation predicted by the XGBoost model. Step S3: Construct a time series prediction model based on the Long Short-Term Memory (LSTM) network. Using the compensated residual chlorine sequence FCL_comped obtained in Step S2 as the data source, and employing the sliding window technique, the model uses the time series data of the past 24 hours as input to predict the residual chlorine concentration for the next hour and multiple steps. Step S4: Construct a three-level dynamic threshold early warning mechanism based on the predicted value, compare the deviation between the current monitored value and the predicted value of the LSTM model in real time, and trigger a first-level reminder, a second-level warning or a third-level alarm response according to the degree of deviation; Step S5: Integrate steps S2 to S4 to form an integrated technical closed loop of "precise compensation - intelligent prediction - early warning".
2. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, In step S2, the construction of the XGBoost compensation model specifically includes: The residual chlorine error data of the first 9 time steps of the sequence are used as input features, and the residual chlorine error of the 10th time step is used as the prediction target. The model parameters were set as follows: number of estimators 120, learning rate 0.5, maximum tree depth 10, and the squared error loss function was used. When used in online applications, the system dynamically iterates through an autoregressive sliding window mechanism, embedding the previous round's predicted value into the lag_1 position of the lagged feature sequence to complete continuous predictions.
3. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, In step S3, the structure of the LSTM time series prediction model is as follows: it contains 4 LSTM hidden layers, each with 160 hidden units, and the end is connected to a linear output layer; the training uses the AdamW optimizer, with mean squared error (MSE) as the loss function, an initial learning rate of 0.0001, and 1500 training rounds.
4. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, The three-level dynamic threshold early warning mechanism in step S4 is as follows: Level 1 Alert: Triggered when the deviation of the monitored value from the predicted value is within ±0.02 mg / L, prompting maintenance personnel to pay attention to the equipment's operating status; Level 2 Warning: Activated when the deviation exceeds the normal fluctuation range of ±0.03 mg / L, automatically marking abnormal data segments and pushing out troubleshooting suggestions; Level 3 alarm: Activated when the deviation reaches the upper limit of the water quality safety standard ±0.05mg / L, simultaneously triggering audible and visual alarms, mobile terminal push notifications, and linking to the preset emergency response process.
5. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, In step S1, the data collection frequency is 30 seconds / time, and preprocessing is performed using 60-minute interval sliding aggregation resampling to obtain a normalized dataset; the dataset is divided in chronological order, with the first 30 days of data as the training set and the last 4 days of data as the validation set.
6. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, The mean absolute error (MAE) of the XGBoost compensation model on the validation set decreased from 0.2526 mg / L before compensation to 0.1102 mg / L after compensation, a reduction of 56.37%, and the coefficient of determination (R²) increased to over 0.
89.
7. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, The LSTM time series prediction model had a prediction bias of 0.0166 mg / L to 0.0264 mg / L in the first 2 hours, with a relative error of 3.5% to 5.7%; the mean absolute error (MAE) was 0.0346 mg / L, the mean relative error was 8.03%, and the coefficient of determination (R²) was 0.
812.
8. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, The LSTM model is deployed on an edge computing device and obtains real-time residual chlorine monitoring data from a MySQL database via an industrial Ethernet network. It uses data from the past 24 hours to predict the residual chlorine concentration for the next 4 hours and automatically calculates the MAE, MAPE, and R² accuracy indicators.
9. The pipe network residual chlorine prediction and early warning method based on the XGBoost-LSTM model according to claim 1, characterized in that, The system integrates a fault self-diagnosis function: when the original electrode signal is detected to be continuously and slowly decreasing while the compensated data remains accurate, a sensor performance degradation prompt is generated based on the signal attenuation characteristics, realizing the transformation from "post-event maintenance" to "predictive maintenance".
10. The method for predicting and early warning of residual chlorine in a pipeline network based on the XGBoost-LSTM model according to claim 1, characterized in that, During continuous operation testing at multiple monitoring nodes in the water supply network, the system can identify local pollution intrusion events characterized by a sudden drop in residual chlorine accompanied by a slight increase in turbidity, and trigger a level-three early warning before the anomaly occurs, thus providing a time window for emergency response.