Introduction

Monitoring water resources is essential to manage water quality and the health of aquatic ecosystems efficiently. Biological measures have indirectly detected the entrance of nonspecific contaminants into bodies of water, and variations in organism response, such as abrupt behavioural changes, reveal changes in environmental circumstances. Predicting changes in water quality indices and modelling and analysing data of typical river waters based on features of water quality changes would offer a solid foundation for managing water body habitats holistically and conserving river ecosystems (Uddin et al. 2022). Several environmental issues, such as water quality management, have found effective solutions using machine learning (ML) algorithms (Kruk 2023). The number of water quality parameters used by ML models has been significantly reduced without sacrificing accuracy thanks to feature selection approaches to select critical characteristics (Lap et al. 2023). Many machine-learning models have been compared when estimating the maximum water temperature at unmeasured places on a regional scale (Singh et al. 2024). These models include RF, XGBoost, MARS and GAM (Souaissi, Ouarda and St-Hilaire, 2023). For a long time, water quality prediction has relied on a handful of simple models. A few examples include the AutoRegressive Integrated Moving Average model (ARIMA) (Fernandes de Souza et al. 2022), support vector machine regression (SVR) (Adaryani et al. 2022) and Grey model (Lao and Sun 2022). They are good at handling water data and making it easy to understand, which will help us refine our models even more.

On the other hand, AI has recently surfaced as a promising avenue for future advancements in water quality prediction (He et al. 2022; Lao and Sun 2022). Several popular data-driven RNN models, including LSTM (Adaryani et al. 2022), GRU (Fahad et al. 2023) and Transformer (Feng et al. 2022), have been used to construct sophisticated prediction systems for use in either the near or far future. Wan et al. (2022a) talked about how non-point source pollution (NPS) affects water quality and how typical deep learning approaches fail to predict water quality when NPS pollution is present adequately. To overcome this shortcoming, a new deep learning model amalgamating physical process–based SOD, spatially aware VGG and deep learning–based LSTM modules was created; it is referred to as SOD-VGG-LSTM. Compared to other models such as ARIMA, SVR and RNN, the model demonstrated better performance in extreme value prediction when evaluated in the Lijiang River watershed (Fowdar et al. 2022). This paper evaluates the performance of the stormwater management model, which uses regression and first-order decay models to inform the design and planning of green infrastructure for managing stormwater pollution (Chen and Xue 2023). Accurately predicting water quality using data-driven models (e.g. neural networks) and handling missing data in water quality series are the main topics of this study. The authors introduce a new piecewise multivariate imputation (PWIMP) method to deal with missing data. They employ wavelet shrinkage denoising based on the maximum overlap discrete wavelet transform (MODWT) to improve the data after imputation. Using LSTM neural networks and six statistical indices, the authors compare four datasets using different imputation and denoising approaches to determine the effectiveness of the PWIMP method (Asadollah et al. 2021). Here, we present Extra Tree Regression (ETR), a novel ensemble machine learning model, to forecast the monthly water quality index (WQI) values along the Lam Tsuen River in Hong Kong. Ho et al. (2019) suggests utilising a decision tree machine learning technique to predict the WQI and identify the water quality class of the Klang River in Malaysia. It takes a lot of time and money to calculate WQI the old-fashioned way. The proposed model uses six water quality characteristics to predict the WQI and its classification within a specific water quality class. The suggested model provides a more efficient and cost-effective way to forecast WQI classes, and the results demonstrate that it has promising potential in this regard (Yao et al. 2023). The effects of LULC on river water quality in a fast-growing metropolitan region in China are investigated in this study. Foretelling future LULC with a cellular automata-Markov model is a crucial metric for predicting water quality with a multiple linear regression model. Paul et al. (2022) discusses the importance of water quality prediction in managing water resources and preventing pollution. The model employs data scaling, a hybrid LSTM-DBN technique and a Sparrow search optimisation algorithm to recognise and classify water quality. The model achieves a high accuracy of 99.84%, demonstrating its effectiveness in predicting water quality. Islam and Irshad (2022) discuss using artificial intelligence for water quality prediction and classification. The authors present a model called AEODL-WQPC that uses data normalisation, an optimal stacked bidirectional gated recurrent unit (OSBiGRU) model for WQI prediction and an artificial ecosystem optimisation with enhanced Elman Neural Network (AEO-IENN) model for water quality categorisation. The AEODL-WQPC model is validated using a benchmark dataset and outperforms other state-of-the-art methods. The need for such a model is driven by the deterioration of water quality due to rapid industrialisation and urbanisation, leading to a rise in the prevalence of serious diseases. The paper suggests this model can provide a fast and economical alternative to traditional laboratory investigations for water quality monitoring. The researcher employs various algorithms still, and there is potential to improve the performance of the prediction using hybrid algorithms (L. Chen et al. 2023a; Ding et al. 2019; M, 2024; Song et al. 2021; Zheng et al. 2023).

According to the literature studies, the performance prediction of the water quality index for the river using the hybrid deep learning algorithm needs to be reported. In this work, the LSTM is adopted to predict the performance of the water quality dataset. A new meta-heuristic optimisation method called COOT mimics the actions of a flock of coot birds, and the cuckoo bird’s reproductive strategy inspired the CSO optimisation method, which is adapted for the hybrid optimisation method.

Materials and methods

In Tamil Nadu, 32 stations along the Cauvery, Tamiraparani, Palar and Vaigai rivers and Ooty, Kodaikanal and Yercaurd lakes are monitored for water quality inland. Afterwards, in November 2010, the CPCB approved 23 more water quality monitoring stations for the 11th plan period, and monitoring began in December 2010. While this is happening, TNPCB is keeping an eye on 55 stations. The CPCB, Delhi, provides funding for the programmes. All the lakes and rivers being monitored under the Monitoring of Indian Notional Aquatic Resources Series (MINARS) initiative. This research developed a novel time-series processing framework for water quality prediction. Using past patterns as a guide, this case study will examine how to foretell how water quality will change. Data sourcing, preprocessing, model creation and model assessment are the four essential parts of the suggested framework, as seen in Fig. 1.

Fig. 1
figure 1

Site location Vaigai River

Profile of study area

South India’s Tamil Nadu state is home to the 7393 square kilometres occupied by the Vaigai River, which flows northeast and passes through the districts of Theni, Madurai, Dindigul, Sivagangai and Ramanathapuram. Near Gandamanaiken Zamin on the eastern slope of the Western Ghats, the river begins its journey at 1524 m above mean sea level. From its headwaters to its eventual merging with the ocean, the river travels about 258 km. You can see the basin map in Fig. 1. Figure 2 shows the methodology adopted in the study.

Fig. 2
figure 2

Methodology adopted in this study

Implementation to the CSOA and COOA and LSTM-CSOA-COOA

COOT optimisation algorithm

A new meta-heuristic optimisation method called COOT mimics the actions of a flock of coot birds (Naruei and Keynia 2021). The COOT method outperforms other optimisation algorithms in terms of convergence accuracy and speed when compared to them. These algorithms include differential evolution and particle swarm optimisation. Along with pressure vessel design, welded beam design, stepped cone pulley and rolling bearing difficulties, the COOT algorithm has also been verified for these applications (Naruei and Keynia 2021).

This study employs the Coot optimization algorithm, inspired by the movement behaviours of coot birds on the water, to determine unknown parameters. The algorithm mimics four types of coot movements: chain movement, leader movement, random movement and position adjustment according to the leader, reflecting their group behaviours aimed at reaching food or specific locations. Equations (1) and (2) implement the specific procedure of the Coot algorithm (Naruei and Keynia 2021). Equation (1) builds the random initialization of the population:

  1. 1.

    Determine the starting point for the coot populations’ fitness levels and location:

    $${R}_{i}={M}_{nb}+\text{rand}\left(1,d\right)*({M}_{xb}-{M}_{nb})$$
    (1)

The random initialisation of individuals produces the variables Ri, where d is the problem’s dimension and Mxb and Mnb are the upper and lower limits of the population’s placements, respectively. The coots’ whereabouts are shown in this matrix:

$${C}_{ps}T=\left[{A}_{x,1},{A}_{x,d},{{A}^{t}}_{x,d}\right]$$
(2)

Cps is the total number of coot locations, and N is the population scale. The following is the population-level fitness matrix for coots, obtained by feeding their locations into the fitness function:

$${FT}^{t}=\left[{FT}_{1}^{t}, {FT}_{2}^{t},\dots {FT}_{x}^{t}\right]$$
(3)

Specifically, fitl I is the value of the individual’s fitness at the time of the lth iteration.

Cuckoo search optimisation algorithm

The cuckoo bird’s reproductive strategy inspired the CSO optimisation method. For a better chance of hatching, these birds deposit their eggs in the nests of other birds and sometimes even steal eggs from the host species. The name for this kind of reproduction is brood parasitism. Below are three examples of the three behavioural patterns used to develop the CSO algorithm, which aims to achieve the global optimal value by mimicking brood parasitism (Yogambal Jayalakshmi et al. 2021):

  1. 1.

    A cuckoo will lay an egg and then, entirely at random, drop it into the nest of another kind of bird. An egg represents a solution or a component of an array of solutions. A solution array or a cluster of eggs forms a nest.

  2. 2.

    The following generation will get the nests that have the best eggs or solutions.

  3. 3.

    The nest count is constant. The host bird will either abandon the nest or build a new one close by if it discovers that all of the eggs are not its own. It will also discard the alien eggs.

Result and discussion

Numerous sources contribute to the water supply that the Vaigai River receives. Notable rivers that flow into the Vaigai include Varahanadhi, Manjalar, Theniar, Marudhandhi, Varatar, Sirumalayar, Nagalar, Sathiar, Uppar and Suriliar. Suriliar is a significant tributary of the Vaigai as it flows from Thoovanam to the last river, Surulipatti. Midway through June marks the beginning of the basin’s monsoon season, which lasts into December. January begins the non-monsoon season, which concludes in the second week of June. With the monsoon accounting for 58% and the non-monsoon for 42%, the total annual rainfall is estimated to be 693.30 mm. Wind speeds average 1.86 km/h, sunshine hours are 7.5 per day, and relative humidity is 57.55%. Temperatures range from 23.62 °C during the low season to 34.38 °C in the high season.

The model suggested specific enhancements to the LSTM-CSOA, LSTM-COOA and LSTM-CSOA-COOA to accomplish the dual goals of increasing the rate of convergence and the precision of predictions. To assess the performance of the modified algorithm, we use the specific water quality monitoring data from the Vaigai River, given in Fig. 3. This data includes six indicators: pH, DO, COD, NH3-N, TP and WQG, all collected from weekly measurements. The performance of the approach is greatly affected by four parameters of the LSTM model used in this paper: the learning rate Lr, the number of training iterations K, the number of neurons in the LSTM hidden layer L1, and the number of LSTM units in the first and second layers, respectively. With the help of the LSTM CSOA, LSTM-COOA and LSTM-CSOA-COOA algorithms, the LSTM model is fine-tuned and optimised with these four critical characteristics serving as features for particle search. Both the test and training datasets for the Vaigai River are displayed in Fig. 3. Maximising LSTM accuracy is the primary objective of LSTM CSOA, LSTM-COOA and LSTM-CSOA-COOA, which aim to optimise LSTM hyperparameters. The best mean square error (MSE) obtained by The LSTM-COOA, LSTM-CSOA-COOA and LSTM-LSTM CSOA fitness functions are utilised during training. Figure 4 shows the DO results of LSTM-COOA, LSTM-CSOA and LSTM-COOA combined for DO prediction in the Vaigai River. The errors of LSTM-COOA, LSTM-CSOA and LSTM-CSOA-COOA converged rapidly as the number of iterations increased. In just five cycles, the fitness evolution curves of LSTM-CSOA, LSTM-COOA and LSTM-CSOA-COOA achieved the needed accuracy and maintained the appropriate fitness value, demonstrating excellent performance and high learning capacity. Coots update their positions based on certain rules inspired by their natural behaviours: foraging behaviour: Coots search for food by moving towards promising areas. This behaviour helps in exploring the search space. Nesting behaviour: Coots build nests in areas they deem safe and resource-rich. This behaviour helps in exploiting good solutions. Avoidance of predators: coots move away from threats, helping them to avoid poor solutions.

Fig. 3
figure 3

Test and training dataset of the Vaigai River

Fig. 4
figure 4

Prediction of DO in the Vaigai River with LSTM CSOA, LSTM-COOA and LSTM-CSOA-COOA

Following the smoothing of the time series, the in-sample data is fitted using the LSTM CSOA, LSTM-COOA and LSTM-CSOA-COOA model in the first step. To find the optimum model for predicting the out-of-sample data, the parameters of the prediction model are further optimised depending on the fit of the multivariate data. To obtain the final prediction results, the residuals from data fitting are fed into a residual feedback network, which in turn produces the out-of-sample data prediction residuals. Applying a moving average to the output predictions can help reduce noise and improve the smoothness of the predicted sequence. Proper tuning of hyperparameters such as learning rate, batch size and the number of epochs can significantly affect the smoothness and stability of the model’s predictions.

Forecasts of COD in the Vaigai River using LSTM CSOA, LSTM-COOA and LSTM-CSOA-COOA have their data inaccuracies remedied due to non-strictly stable and nonlinear variables in the multidimensional series. Figure 5 compares the hybrid model’s COD prediction results to those of the other models.

Fig. 5
figure 5

Prediction of COD in the Vaigai River with LSTM CSOA, LSTM-COOA and LSTM-CSOA-COOA

The best performing model is determined using three assessment metrics: RMSE, MAPE and NSE. LSTM-COOA, LSTM-CSOA and LSTM-COOA. The study’s three techniques for predicting water quality measurements are displayed in Table 1, along with their respective anticipated inaccuracies. The network model is unable to produce more accurate predictions of multivariate water quality indicators and has poor prediction accuracy when working with limited data sets. For the majority of water quality data, the LSTM-COOA, LSTM-CSOA and LSTM-COOA models provide good forecast accuracy. Nevertheless, a notable inaccuracy in parameter prediction exists for NH3-N. When it comes to multiparameter prediction jobs, the SVR model falls short since it is not sensitive to certain characteristic factors and does not capture all the aspects of the water quality data. All four data points show that the LSTM-CSOA, LSTM-COOA and LSTM-CSOA-COOA models produce identical prediction results to the hybrid model. Nonetheless, the hybrid model’s generalizability is diminished due to the increased difficulty in applying and deploying it in practice caused by its more substantial input data needs. As shown in Table 1, they achieved MAPE and RMSE for every water quality indicator and practically flawless data matching rates. Figure 6 displays the NH3-N data comparison results, which involve comparing the prediction outcomes of the hybrid model with the original data one by one. The desired goal is for the RMSE and MAPE values to be smaller as the results approach 1, which is evident. This proves that the residual feedback network design mitigates non-strictly stationary multivariate data systematic mistakes. A hybrid prediction model’s network topology is straightforward, the model’s execution time is minimal, and the model’s statistical parameters may be roughly estimated from the data’s feature. This simplifies the process of theoretical derivation and allows for residual feedback to fix prediction errors, which improves the algorithm’s operational efficiency and generalizability. The model also fully accounts for sequence correlations for improved prediction accuracy and concurrent multivariate data processing.

Table 1 Performance metrics of the variable methods
Fig. 6
figure 6

Prediction of NH3-N in the Vaigai River with LSTM CSOA, LSTM-COOA and LSTM-CSOA-COOA

The best performing model is determined using three assessment metrics: RMSE, MAPE and MSE. These metrics are applied to the anticipated and observed data for 20 weeks’ worth of water quality parameters by the SVR model, LSTM-COOA, LSTM-CSOA and LSTM-COOA. The study’s three techniques for predicting water quality measurements are displayed in Table 1, along with their respective anticipated inaccuracies. The results demonstrate that the LSTM neural network model is unable to produce more accurate predictions of multivariate water quality indicators and has poor prediction accuracy when working with limited data sets. For the majority of water quality data, the LSTM-COOA, LSTM-CSOA and LSTM-COOA models provide good forecast accuracy. Nevertheless, a notable inaccuracy in parameter prediction exists for NH3-N. When it comes to multiparameter prediction jobs, the SVR model falls short since it is not sensitive to certain characteristic factors and does not capture all the aspects of the water quality data. All four data points show that the LSTM-CSOA, LSTM-COOA and LSTM-CSOA-COOA models produce identical prediction results to the hybrid model. Nonetheless, the hybrid model’s generalizability is diminished due to the increased difficulty in applying and deploying it in practice caused by its more substantial input data needs. As shown in Table 1, the hybrid prediction model achieves MAPEs RMSE and MAE for every water quality indicator and practically flawless data matching rates. It should be noted that the model’s performance improves with decreasing RMSE, and vice versa. The prediction error will be less than or equal to 0.01, according to the hybrid prediction model. Table 2 shows the geographically reported study.

Table 2 Globally reported water quality index study

Table 2 shows the geographically reported study. Water quality parameters refer to various physical, chemical and biological characteristics used to assess the condition of water. These parameters are crucial for evaluating the suitability of water for multiple purposes, such as drinking, agriculture, industrial use and aquatic habitat support. Some standard water quality parameters include pH, which measures the acidity or alkalinity of water. It is an important parameter as it affects the solubility of minerals and metals and the survival of aquatic organisms.

Water temperature influences various biological and chemical processes in aquatic ecosystems. It can affect dissolved oxygen levels, metabolic rates of aquatic organisms and the solubility of gases and minerals. Dissolved oxygen (DO): DO is the amount of oxygen dissolved in water, which is essential for the survival of aquatic organisms. It is influenced by temperature, salinity and the presence of organic matter (L. Chen et al. 2023b).

Even though LSTMs are designed to mitigate the vanishing gradient problem compared to vanilla RNNs, they are not immune. The gradients can still diminish during backpropagation, especially with very long sequence. Conversely, gradients can also become excessively large, leading to unstable training and divergence of the model. To prevent exploding gradients, clip the gradients during backpropagation. Use dropout regularization to prevent overfitting. Adjust the learning rate dynamically during training to improve convergence.

Turbidity measures the cloudiness or haziness of water caused by suspended solids, such as silt, clay and plankton. High turbidity can affect light penetration, aquatic plant growth and the health of aquatic ecosystems. Conductivity: Conductivity measures water’s ability to conduct electrical current, which is influenced by the concentration of dissolved ions such as salts and minerals. It assesses the salinity and total dissolved solids (TDSs) in water (Zhao et al. 2021). Environmental agencies, water utilities, researchers and other stakeholders often monitor these parameters to assess water quality, identify pollution sources and implement appropriate management measures (Wan et al. 2022b).

Conclusion

The preservation of river water ecosystems is greatly influenced by water quality, which affects all living things and human endeavours. The data was culled from 300 weeks of monitoring in the Vaigai River, which flows through Madurai, Tamil Nadu, India. This work utilised various AI techniques, including baseline, modelling and hybrid methods. As baseline models, it experimentally evaluated and examined the performance of LSTM, LSTM-CSOA, LSTM-COOA and LSTM-CSOA-COOA hybrid models in predicting river water quality. The prediction results demonstrate that it outperforms the competition and produces findings more in line with real-world indicators. The study found that the algorithm achieved accuracy greater than 94%. The wavelet neural network demonstrated higher prediction precision and stronger learning and generalization abilities compared to the traditional BP neural network and the Elman neural network. The proposed model meets management requirements for intensive freshwater systems. Since water quality is significantly influenced by hydrological and meteorological factors, future research should focus on developing different predictive models for various weather conditions and combining these models to enhance prediction accuracy.