Using Hybrid Machine Learning to Predict Wastewater Effluent Quality and Ensure Treatment Plant Stability
Abstract
1. Introduction
2. Materials and Methods
2.1. Data Collection
2.2. Baseline Models
2.2.1. XGBoost
2.2.2. Long Short-Term Memory
2.3. Interpretable Machine Learning
2.3.1. SHAP
2.3.2. Attention Mechanism
2.4. Combination of LSTM and XGBoost
2.5. Hyperparameter Optimization
3. Results and Discussion
3.1. Statistical Analysis
3.2. Performance of Singular Models
3.3. Interpretability Analysis
3.4. Performance of Hybrid Models
4. Conclusions
- (1)
- The predictive performance of the individual LSTM and XGBoost models is relatively comparable, with R2 values for the four effluent parameters ranging from 0.810 to 0.877. However, the predictions for certain parameters exhibit a consistent underestimation of the actual values throughout the monitoring period. In contrast, the LSTM model incorporating the attention mechanism demonstrates improved predictive accuracy, with R2 values ranging from 0.850 to 0.899.
- (2)
- Interpretability analysis reveals that the feature importance rankings from SHAP and the attention mechanism are largely consistent. For a given effluent parameter, in addition to the corresponding influent parameter, other influent indicators also influence the outcome through interactions. However, the rankings from the weight method of XGBoost differ from those of SHAP and the attention mechanism. This discrepancy may result from XGBoost’s tendency to prioritize a single feature for splitting, disregarding other correlated features.
- (3)
- The prediction accuracy of the two hybrid models is markedly superior to that of the singular model. The first model utilizes the information by adjusting the residuals, achieving R2 values ranging from 0.952 to 0.982. The second model enhances the input features by capturing temporal dependencies, resulting in R2 values between 0.914 and 0.986. The hybrid framework strategically combines the strengths of XGBoost and LSTM models from complementary perspectives, offering a robust solution for treatment process stability evaluation and real-time effluent quality monitoring. This integration has the potential to enable proactive adjustments in wastewater treatment processes, thereby optimizing operational efficiency and improving system responsiveness and treatment system resilience.
Author Contributions
Funding
Data Availability Statement
Conflicts of Interest
References
- Silva, J.A. Wastewater treatment and reuse for sustainable water resources management: A systematic literature review. Sustainability 2023, 15, 10940. [Google Scholar] [CrossRef]
- Wang, M.; Bodirsky, B.L.; Rijneveld, R.; Beier, F.; Bak, M.P.; Batool, M.; Droppers, B.; Popp, A.; van Vliet, M.T.H.; Strokal, M. A triple increase in global river basins with water scarcity due to future pollution. Nat. Commun. 2024, 15, 880. [Google Scholar] [CrossRef] [PubMed]
- Newhart, K.B.; Holloway, R.W.; Hering, A.S.; Cath, T.Y. Data-driven performance analyses of wastewater treatment plants: A review. Water Res. 2019, 157, 498–513. [Google Scholar] [CrossRef] [PubMed]
- Flores-Alsina, X.; Ramin, E.; Ikumi, D.; Harding, T.; Batstone, D.; Brouckaert, C.; Sotemann, S.; Gernaey, K.V. Assessment of sludge management strategies in wastewater treatment systems using a plant-wide approach. Water Res. 2021, 190, 116714. [Google Scholar] [CrossRef]
- Feng, K.; Zhao, Z.; Li, M.; Tian, L.; An, T.; Zhang, J.; Xu, X.; Zhu, L. Novel intelligent control framework for WWTP optimization to achieve stable and sustainable operation. ACS ES&T Eng. 2022, 2, 2086–2094. [Google Scholar] [CrossRef]
- Jin, T.; Cai, S.; Jiang, D.; Liu, J. A data-driven model for real-time water quality prediction and early warning by an integration method. Environ. Sci. Pollut. Res. 2019, 26, 30374–30385. [Google Scholar] [CrossRef] [PubMed]
- Gujer, W.; Henze, M.; Mino, T.; Matsuo, T.; Wentzel, M.C.; Marais, G.V.R. The activated sludge model No. 2: Biological phosphorus removal. Water Sci. Technol. 1995, 31, 1–11. [Google Scholar] [CrossRef]
- Gujer, W.; Henze, M.; Mino, T.; Van Loosdrecht, M. Activated sludge model No. 3. Water Sci. Technol. 1999, 39, 183–193. [Google Scholar] [CrossRef]
- Henze, M.; Gujer, W.; Mino, T.; Matsuo, T.; Wentzel, M.C.; Marais, G.V.R.; Van Loosdrecht, M.C. Activated sludge model no. 2d, ASM2d. Water Sci. Technol. 1999, 39, 165–182. [Google Scholar] [CrossRef]
- Zhu, J.-J.; Kang, L.; Anderson, P.R. Predicting influent biochemical oxygen demand: Balancing energy demand and risk management. Water Res. 2018, 128, 304–313. [Google Scholar] [CrossRef]
- Bolyard, S.C.; Reinhart, D.R. Evaluation of leachate dissolved organic nitrogen discharge effect on wastewater effluent quality. Waste Manag. 2017, 65, 47–53. [Google Scholar] [CrossRef] [PubMed]
- El Shorbagy, W.E.; Radif, N.N.; Droste, R.L. Optimization of A2O BNR Processes Using ASM and EAWAG Bio-P Models: Model Performance. Water Environ. Res. 2013, 85, 2271–2284. [Google Scholar] [CrossRef]
- Jeppsson, U.; Alex, J.; Batstone, D.J.; Benedetti, L.; Comas, J.; Copp, J.B.; Corominas, L.; Flores-Alsina, X.; Gernaey, K.V.; Nopens, I.; et al. Benchmark simulation models, quo vadis? Water Sci. Technol. 2013, 68, 1–15. [Google Scholar] [CrossRef] [PubMed]
- Wan, W.; Yang, L.; Liu, L.; Zhang, Z.; Jia, R.; Choi, Y.-K.; Pan, J.; Theobalt, C.; Komura, T.; Wang, W. Learn to predict how humans manipulate large-sized objects from interactive motions. IEEE Robot. Autom. Lett. 2022, 7, 4702–4709. [Google Scholar] [CrossRef]
- Lin, S.; Kim, J.; Hua, C.; Park, M.-H.; Kang, S. Coagulant dosage determination using deep learning-based graph attention multivariate time series forecasting model. Water Res. 2023, 232, 119665. [Google Scholar] [CrossRef] [PubMed]
- Xie, C.; Yang, X.; Chen, T.; Fang, Q.; Wang, J.; Shen, Y. Short-term wind power prediction framework using numerical weather predictions and residual convolutional long short-term memory attention network. Eng. Appl. Artif. Intell. 2024, 133, 108543. [Google Scholar] [CrossRef]
- Zhang, S.; Yu, W.; Zhang, W. Interactive dynamic diffusion graph convolutional network for traffic flow prediction. Inf. Sci. 2024, 677, 120938. [Google Scholar] [CrossRef]
- Li, S.; Zhang, R. A novel interactive deep cascade spectral graph convolutional network with multi-relational graphs for disease prediction. Neural Netw. 2024, 175, 106285. [Google Scholar] [CrossRef]
- Liao, S.; Xie, L.; Du, Y.; Chen, S.; Wan, H.; Xu, H. Stock trend prediction based on dynamic hypergraph spatio-temporal network. Appl. Soft Comput. 2024, 154, 111329. [Google Scholar] [CrossRef]
- Zhao, Y.; Guo, L.; Liang, J.; Zhang, M. Seasonal artificial neural network model for water quality prediction via a clustering analysis method in a wastewater treatment plant of China. Desalin. Water Treat. 2016, 57, 3452–3465. [Google Scholar] [CrossRef]
- Jawad, J.; Hawari, A.H.; Zaidi, S.J. Artificial neural network modeling of wastewater treatment and desalination using membrane processes: A review. Chem. Eng. J. 2021, 419, 129540. [Google Scholar] [CrossRef]
- Zhang, L.; Chao, B.; Zhang, X. Modeling and optimization of microbial lipid fermentation from cellulosic ethanol wastewater by Rhodotorula glutinis based on the support vector machine. Bioresour. Technol. 2020, 301, 122781. [Google Scholar] [CrossRef] [PubMed]
- Hejabi, N.; Saghebian, S.M.; Aalami, M.T.; Nourani, V. Evaluation of the effluent quality parameters of wastewater treatment plant based on uncertainty analysis and post-processing approaches (case study). Water Sci. Technol. 2021, 83, 1633–1648. [Google Scholar] [CrossRef]
- Pham, Q.B.; Gaya, M.; Abba, S.; Abdulkadir, R.; Esmaili, P.; Linh, N.T.T.; Sharma, C.; Malik, A.; Khoi, D.N.; Dung, T.D.; et al. Modeling of Bunus regional sewage treatment plant using machine learning approaches. Desalin. Water Treat. 2020, 203, 80–90. [Google Scholar] [CrossRef]
- Mekaoussi, H.; Heddam, S.; Bouslimanni, N.; Kim, S.; Zounemat-Kermani, M. Predicting biochemical oxygen demand in wastewater treatment plant using advance extreme learning machine optimized by Bat algorithm. Heliyon 2023, 9, e21351. [Google Scholar] [CrossRef]
- Cheng, Q.; Chunhong, Z.; Qianglin, L. Development and application of random forest regression soft sensor model for treating domestic wastewater in a sequencing batch reactor. Sci. Rep. 2023, 13, 9149. [Google Scholar] [CrossRef]
- Zhou, P.; Li, Z.; Snowling, S.; Baetz, B.W.; Na, D.; Boyd, G. A random forest model for inflow prediction at wastewater treatment plants. Stoch. Environ. Res. Risk Assess. 2019, 33, 1781–1792. [Google Scholar] [CrossRef]
- Gao, J.; Wahlen, A.; Ju, C.; Chen, Y.; Lan, G.; Tong, Z. Reinforcement learning-based control for waste biorefining processes under uncertainty. Commun. Eng. 2024, 3, 38. [Google Scholar] [CrossRef]
- Negm, A.; Ma, X.; Aggidis, G. Deep reinforcement learning challenges and opportunities for urban water systems. Water Res. 2024, 253, 121145. [Google Scholar] [CrossRef]
- Yang, Q.; Cao, W.; Meng, W.; Si, J. Reinforcement-learning-based tracking control of waste water treatment process under realistic system conditions and control performance requirements. IEEE Trans. Syst. Man Cybern. Syst. 2021, 52, 5284–5294. [Google Scholar] [CrossRef]
- Xu, B.; Pooi, C.K.; Tan, K.M.; Huang, S.; Shi, X.; Ng, H.Y. A novel long short-term memory artificial neural network (LSTM)-based soft-sensor to monitor and forecast wastewater treatment performance. J. Water Process Eng. 2023, 54, 104041. [Google Scholar] [CrossRef]
- Voipan, D.; Voipan, A.E.; Barbu, M. Evaluating Machine Learning-Based Soft Sensors for Effluent Quality Prediction in Wastewater Treatment Under Variable Weather Conditions. Sensors 2025, 25, 1692. [Google Scholar] [CrossRef]
- Yin, H.; Chen, Y.; Zhou, J.; Xie, Y.; Wei, Q.; Xu, Z. A probabilistic deep learning approach to enhance the prediction of wastewater treatment plant effluent quality under shocking load events. Water Res. X 2025, 26, 100291. [Google Scholar] [CrossRef] [PubMed]
- Zhu, B. COD Prediction Model for Wastewater Treatment Based on Particle Swarm Algorithm. In Proceedings of the 2023 Asia-Europe Conference on Electronics, Data Processing and Informatics (ACEDPI), Prague, Czech Republic, 7–19 April 2023; pp. 454–459. [Google Scholar]
- Xie, Y.; Chen, Y.; Wei, Q.; Yin, H. A hybrid deep learning approach to improve real-time effluent quality prediction in wastewater treatment plant. Water Res. 2024, 250, 121092. [Google Scholar] [CrossRef]
- Yao, Z.; Wang, Z.; Huang, J.; Xu, N.; Cui, X.; Wu, T. Interpretable prediction, classification and regulation of water quality: A case study of Poyang Lake, China. Sci. Total Environ. 2024, 951, 175407. [Google Scholar] [CrossRef]
- Zhang, Y.; Li, C.; Jiang, Y.; Sun, L.; Zhao, R.; Yan, K.; Wang, W. Accurate prediction of water quality in urban drainage network with integrated EMD-LSTM model. J. Clean. Prod. 2022, 354, 131724. [Google Scholar] [CrossRef]
- Chen, Y.; Zhang, H.; You, Y.; Zhang, J.; Tang, L. A hybrid deep learning model based on signal decomposition and dynamic feature selection for forecasting the influent parameters of wastewater treatment plants. Environ. Res. 2025, 266, 120615. [Google Scholar] [CrossRef]
- Lv, J.-Q.; Yin, W.-X.; Xu, J.-M.; Cheng, H.-Y.; Li, Z.-L.; Yang, J.-X.; Wang, A.-J.; Wang, H.-C. Augmented machine learning for sewage quality assessment with limited data. Environ. Sci. Ecotechnol. 2025, 23, 100512. [Google Scholar] [CrossRef]
- Chen, T.; Guestrin, C. Xgboost: A scalable tree boosting system. In Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining, San Francisco, CA, USA, 13–17 August 2016; pp. 785–794. [Google Scholar]
- Friedman, J.H. Greedy function approximation: A gradient boosting machine. Ann. Stat. 2001, 29, 1189–1232. [Google Scholar] [CrossRef]
- Ching, P.; Zou, X.; Wu, D.; So, R.; Chen, G. Development of a wide-range soft sensor for predicting wastewater BOD5 using an eXtreme gradient boosting (XGBoost) machine. Environ. Res. 2022, 210, 112953. [Google Scholar] [CrossRef]
- Hochreiter, S.; Schmidhuber, J. Long short-term memory. Neural Comput. 1997, 9, 1735–1780. [Google Scholar] [CrossRef] [PubMed]
- Shapley, L.S. 17. A Value for n-Person Games. In Contributions to the Theory of Games; Kuhn, H.W., Tucker, A.W., Eds.; Princeton University Press: Princeton, NJ, USA, 2016; Volume II, pp. 307–318. Available online: https://www.degruyterbrill.com/document/doi/10.1515/9781400881970-018/html (accessed on 19 June 2025).
- Lundberg, S.M.; Lee, S.I. A unified approach to interpreting model predictions. In Proceedings of the 31st International Conference on Neural Information Processing Systems, Long Beach, CA, USA, 4–9 December 2017. [Google Scholar]
- Deng, Z.; Wan, J.; Ye, G.; Wang, Y. Data-driven prediction of effluent quality in wastewater treatment processes: Model performance optimization and missing-data handling. J. Water Process Eng. 2025, 71, 107352. [Google Scholar] [CrossRef]
- Treisman, A.M.; Gelade, G. A feature-integration theory of attention. Cogn. Psychol. 1980, 12, 97–136. [Google Scholar] [CrossRef] [PubMed]
- Zhu, J.; Wagner, M.; Cornel, P.; Chen, H.; Dai, X. Feasibility of on-site grey-water reuse for toilet flushing in China. J. Water Reuse Desalin. 2018, 8, 1–13. [Google Scholar] [CrossRef]
- Simbeye, C.; Courtney, C.; Simha, P.; Fischer, N.; Randall, D.G. Human urine: A novel source of phosphorus for vivianite production. Sci. Total Environ. 2023, 892, 164517. [Google Scholar] [CrossRef]
- Zhang, Y.; Wang, J.; Li, C.; Duan, H.; Wang, W. Attention-based deep learning models for predicting anomalous shock of wastewater treatment plants. Water Res. 2025, 275, 123192. [Google Scholar] [CrossRef]
Model | Range | COD | NH3-N | TP | TN |
---|---|---|---|---|---|
XGBoost | n_estimators = [50, 500] | n_estimators = 482 | n_estimators = 385 | n_estimators = 442 | n_estimators = 352 |
max_depth = [2, 7] | max_depth = 3 | max_depth = 5 | max_depth = 3 | max_depth = 3 | |
learning_rate = [0.01, 0.3] | learning_rate = 0.3 | learning_rate = 0.16 | learning_rate = 0.23 | learning_rate = 0.24 | |
subsample = [0.5, 1] | subsample = 0.5 | subsample = 0.65 | subsample = 0.38 | subsample = 0.6 | |
child_weight = [0.5, 1] | child_weight = 0.9 | child_weight = 0.85 | child_weight = 0.84 | child_weight = 0.5 | |
LSTM | epoch = [50, 350] | epoch = 200 | epoch = 300 | epoch = 200 | epoch = 250 |
batch size = [20, 80] | batch size = 50 | batch size = 45 | batch size = 65 | batch size = 60 | |
units = [120, 250] | units = 190 | units = 185 | units = 210 | units = 205 | |
timesteps = [3, 7] | timesteps = 5 | timesteps = 5 | timesteps = 5 | timesteps = 4 | |
Attention–LSTM | epoch = [50, 350] | epoch = 200 | epoch = 250 | epoch = 200 | epoch = 200 |
batch size = [20, 80] | batch size = 45 | batch size = 50 | batch size = 40 | batch size = 55 | |
units = [120, 250] | units = 210 | units = 210 | units = 225 | units = 190 | |
timesteps = [3, 7] | timesteps = 4 | timesteps = 4 | timesteps = 4 | timesteps = 3 | |
Attention–LSTM2–XGBoost | n_estimators = [50, 500] | n_estimators = 376 | n_estimators = 475 | n_estimators = 435 | n_estimators = 386 |
max_depth = [2, 7] | max_depth = 4 | max_depth = 4 | max_depth = 4 | max_depth = 4 | |
learning_rate = [0.01, 0.3] | learning_rate = 0.29 | learning_rate = 0.22 | learning_rate = 0.24 | learning_rate = 0.2 | |
subsample = [0.5, 1] | subsample = 0.3 | subsample = 0.48 | subsample = 0.7 | subsample = 0.5 | |
child_weight = [0.5, 1] | child_weight = 0.7 | child_weight = 0.86 | child_weight = 0.8 | child_weight = 1 | |
Attention–LSTM1–XGBoost | n_estimators = [50, 500] | n_estimators = 400 | n_estimators = 444 | n_estimators = 500 | n_estimators = 435 |
max_depth = [2, 7] | max_depth = 5 | max_depth = 4 | max_depth = 4 | max_depth = 5 | |
learning_rate = [0.01, 0.3] | learning_rate = 0.25 | learning_rate = 0.29 | learning_rate = 0.26 | learning_rate = 0.26 | |
subsample = [0.5, 1] | subsample = 0.4 | subsample = 0.56 | subsample = 0.82 | subsample = 0.35 | |
child_weight = [0.5, 1] | child_weight = 0.8 | child_weight = 0.76 | child_weight = 0.9 | child_weight = 0.97 |
Models | Effluent Parameters | Datasets | Metrics | ||
---|---|---|---|---|---|
R2 | RMSE | MAE | |||
LSTM | COD | Training | 0.896 | 0.856 | 0.705 |
Test | 0.867 | 0.968 | 0.732 | ||
NH3-N | Training | 0.873 | 0.169 | 0.069 | |
Test | 0.810 | 0.122 | 0.047 | ||
TN | Training | 0.943 | 0.543 | 0.360 | |
Test | 0.869 | 0.724 | 0.567 | ||
TP | Training | 0.889 | 0.053 | 0.046 | |
Test | 0.859 | 0.049 | 0.030 | ||
XGBoost | COD | Training | 0.893 | 0.871 | 0.725 |
Test | 0.841 | 0.404 | 0.292 | ||
NH3-N | Training | 0.855 | 0.181 | 0.082 | |
Test | 0.827 | 0.117 | 0.056 | ||
TN | Training | 0.922 | 0.638 | 0.457 | |
Test | 0.877 | 0.702 | 0.504 | ||
TP | Training | 0.879 | 0.056 | 0.041 | |
Test | 0.840 | 0.053 | 0.036 | ||
At-LSTM | COD | Training | 0.948 | 0.608 | 0.431 |
Test | 0.887 | 0.339 | 0.244 | ||
NH3-N | Training | 0.923 | 0.132 | 0.040 | |
Test | 0.865 | 0.103 | 0.038 | ||
TN | Training | 0.941 | 0.554 | 0.350 | |
Test | 0.899 | 0.636 | 0.416 | ||
TP | Training | 0.926 | 0.044 | 0.030 | |
Test | 0.850 | 0.040 | 0.050 |
Models | Effluent Parameters | Datasets | Metrics | ||
---|---|---|---|---|---|
R2 | RMSE | MAE | |||
Attention–LSTM1–XGBoost | COD | Training | 0.992 | 0.234 | 0.162 |
Test | 0.972 | 0.168 | 0.138 | ||
NH3-N | Training | 0.995 | 0.033 | 0.013 | |
Test | 0.982 | 0.037 | 0.015 | ||
TN | Training | 0.980 | 0.311 | 0.214 | |
Test | 0.957 | 0.417 | 0.326 | ||
TP | Training | 0.988 | 0.018 | 0.015 | |
Test | 0.952 | 0.028 | 0.024 | ||
Attention–LSTM2–XGBoost | COD | Training | 0.978 | 0.399 | 0.283 |
Test | 0.952 | 0.223 | 0.161 | ||
NH3-N | Training | 0.992 | 0.043 | 0.013 | |
Test | 0.986 | 0.034 | 0.012 | ||
TN | Training | 0.969 | 0.404 | 0.255 | |
Test | 0.946 | 0.464 | 0.304 | ||
TP | Training | 0.953 | 0.035 | 0.024 | |
Test | 0.914 | 0.038 | 0.030 |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Xiong, Z.; Liu, X.; Igou, T.; Li, Z.; Chen, Y. Using Hybrid Machine Learning to Predict Wastewater Effluent Quality and Ensure Treatment Plant Stability. Water 2025, 17, 1851. https://doi.org/10.3390/w17131851
Xiong Z, Liu X, Igou T, Li Z, Chen Y. Using Hybrid Machine Learning to Predict Wastewater Effluent Quality and Ensure Treatment Plant Stability. Water. 2025; 17(13):1851. https://doi.org/10.3390/w17131851
Chicago/Turabian StyleXiong, Zhaoyang, Xingyang Liu, Thomas Igou, Zhanchao Li, and Yongsheng Chen. 2025. "Using Hybrid Machine Learning to Predict Wastewater Effluent Quality and Ensure Treatment Plant Stability" Water 17, no. 13: 1851. https://doi.org/10.3390/w17131851
APA StyleXiong, Z., Liu, X., Igou, T., Li, Z., & Chen, Y. (2025). Using Hybrid Machine Learning to Predict Wastewater Effluent Quality and Ensure Treatment Plant Stability. Water, 17(13), 1851. https://doi.org/10.3390/w17131851