{'fraction_non_alphanumeric': 0.027493515680264088, 'fraction_numerical': 0.009761848620608348, 'mean_word_length': 4.829026937877955, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Implementation of Machine Learning Methods for Monitoring and Predicting Water Quality Parameters

The importance of good water quality for human use and consumption can never be underestimated, and its quality is determined through effective monitoring of the water quality index. Different approaches have been employed in the treatment and monitoring of water quality parameters (WQP). Presently, water quality is carried out through laboratory experiments, which requires costly reagents, skilled labor, and consumes time. Thereby making it necessary to search for an alternative method. Recently, machine learning tools have been successfully implemented in the monitoring, estimation, and predictions of river water quality index to provide an alternative solution to the limitations of laboratory analytical methods. In this study, the potentials of one of the machine learning tools (artificial neural network) were explored in the predictions and estimation of the Kelantan River basin. Water quality data collected from the 14 stations of the River basin was used for modeling and predicting (WQP). As for WQP analysis, the results obtained from this study show that the best prediction was obtained from the prediction of pH. The low kurtosis values of pH indicate that the appearance of outliers give a negative impact on the performance. As for WQP analysis for each station, we found that the WQP prediction in station 1, 2, and 3 give the good results. This is related to the available data of those stations that are more than the available data in other stations, except station 8.


Introduction
Globally, river water at an initial state is believed to be free from contaminations and the safest water source for human consumption and applications. However, a high rate of industrialization, population growth, and urban development has led to the deterioration of their sustainability [1]. The effective approach of river clean up involves the detection and measurement of both natural and anthropogenic influences and an increased understanding of the sources of pollutants, which are important factors in planning, prevention, and cleaning processes [2]. Moreover, water quality from rivers has significant importance in a number of areas such as agriculture, hydropower plants, domestic and residential water supplies, recreation, tourism, and transportation [3]. Water quality is currently estimated through a series of experimental and statistical analysis, that requires costly reagents, time, and skilled labor [4]. Consequently, the disastrous effects of water pollution require a cheaper and more efficient alternative. Furthermore, ongoing urban river pollution issues in Malaysia have called for more studies to be carried out in order to gain insight into new approaches to technologies, particularly in the river water treatment plant (RWTP) [2].
Several research works have been conducted in the field of water resource management with the sole aim of improving the water quality of rivers. The application of artificial intelligence (AI) that provides a given system with the ability to automatically learn and improve from experience without being explicitly programmed is known as Machine learning (ML) [5]. However, computing tasks where designing and programming algorithms with good performance is difficult or infeasible were successfully achieved through the application of ML [5]. The procedures involved in ML necessitates scrutiny through data to look for patterns and to adjust program action accordingly. By using these techniques, model accuracy can be enhanced [6]. Machine learning models can suitably present conceptions of the hydrological process but requires a large set of data. Although in these techniques, outputs are obtained without in-depth observation of the physical details of the water resource being investigated [7]. For instance, Nouranin et al. [8] applied artificial intelligence based on non-linear models (feed-forward neural network (FFNN), adaptive neuro-fuzzy inference system (ANFIS), support vector machine (SVM), and classical multi-linear regression (MLR) method) for prediction of water quality indicators (biochemical oxygen demand (BOD), chemical oxygen demand (COD) and nitrogen (TN) of Nicosa wastewater treatment plant (NWWTP). Also, genetic programming (GP) technique was used to forecast the rainfall runoff in Sungai Sayong, Johor [4]. Furthermore, in order to improve river suspended sediment predictions, [7] combined the application of the Artificial Intelligence Model with Metaheuristic Algorithms by applying adaptive neuro-fuzzy system (ANFIS) and multilayer feed-forward neural network (MFNN) by the bat algorithm (BA) and weed algorithm (WA). However, human activities in the Kelantan river basin have great importance for socio-economic life in the north-eastern state of peninsular Malaysia, covering about 4.4% of Malaysia with a total area of 15,099 km 2 [9]. The aforementioned human activities have a vital impact on the geographical environment, specifically the quality of the water resources. Therefore, this research is carried out on the dataset collected from 14 stations of Kelantan River, located in Malaysia. Machine learning techniques were applied on the collected dataset for the water quality parameters such as (dissolved oxygen (DO), biological oxygen demand (BOD), chemical oxygen demand (COD), pH, ammonia nitrogen (NH3-NL), suspended solids (SS).

Study area and data collection.
Kelantan River catchment and its tributaries are occupying about 80% of Kelantan state's surface area with a total catchment area of 11,900 km 2 , forming the Kelantan River Basin, which is one of the major basins in Malaysia [9]. The 248 km long Kelantan River originates in the Tahan mountain range and flows northward into the South China Sea. It is a common tropical basin that receives precipitation throughout the year [10]. Seven major subcatchments such as Nenggri, Gullimard, Pergau, Kuala Krai, Galas, Lebir, and Kota Bahru forming the main rivers which cover about 13170 km 2 of drainage area [11]. The estimated average annual precipitation of the Kelantan River Basin is about 2500mm, and the maximum annual rainfall (1750 mm) occurs during the northeast monsoon season between mid-October and mid-January [12,13]. About 0.5 million of the population are able to sustain as the main river in Kelantan state is adequate to supply most of the water for drinking, agricultural activities, plantation irrigation, small scale fishing industries, sand mining activities, and also contributing a way of transportation and channel of receiving wastewater treatment effluents [14].
According to Yen and Rohasliney, [15] the sand mining activities on the Kelantan River, physicochemical parameters such as total suspended solids (TSS), turbidity, and nitrate concentration had increased to incredibly significant levels that exceed the standards of the Malaysian Interim National Water Quality Standard (INWQS). The Kelantan River Basin is frequently affected by monsoon floods with the occurrences of an increase in flooding from once in 50 years to once in 15 years [16]. Rahman et al. [9] mentioned that after a severe flood in 2014, chemical contaminants such as heavy metals and carcinogens were found in floodwater, and exposure to pathogen or toxicants can lead to a long-term negative environmental impact. Meanwhile, in a recent study [14], the Kelantan River is found to fall under Class I according to the Malaysian National Water Quality Standard (NWQS) in terms of anthropogenic metals. Unfortunately, in terms of heavy metals, total suspended solids (TSS) pollution is up to 291 mg/L, which was considered somewhat polluted under the Malaysian Department of Environment-Water Quality Index (DOE-WQI).

Dataset.
In this study, the dataset used is the time series data of six water quality parameters (WQP), i.e., dissolved oxygen (DO), biological oxygen demand (BOD), chemical oxygen demand (COD), pH, ammonia nitrogen (NH3-NL), and suspended solids (SS) that were collected from 14 stations in Kelantan River. The data size for each station is different depending on the availability of the data. The number of data collected in 4 stations (out of the total 14 stations), i.e station number 1, 2, 3 and 8, is 250 monthly data, which is comprised of the monthly WQP from February 1997 to December 2017. Meanwhile, the number of data collected in the remaining other 10 stations, i.e. station number 4, 5, 6, 7, 9, 10, 11, 12, 13 and 14, is 148 monthly data, which is comprised of the monthly WQP from September 2005 to December 2017. The distribution of data size for each station is presented in Figure 1. The missing value found in the data was treated by using the interpolation method. By using this method, the missing value at a certain time was determined by considering the value before and after the time.
The statistical properties of WQP in station 1 are provided in Table 1, while the properties of the parameters in the rest stations are provided in Supporting Information. Here, the variability of the WQP was described by the value of minimum, maximum, mean, standard deviation, skewness, and kurtosis. We found that the skewness of DO and pH in station 1 have a low skewness coefficient. Meanwhile, the rest of the parameters have a large skewness coefficient, indicates the large difference of mean and median in those parameters. Also, we found that COD, NH3-NL, and SS have a large kurtosis coefficient that indicates the appearance of the outliers. For the overall evaluation, the average statistical properties of WQP of all stations are presented in Table 2. Similar to the statistical properties of station 1, we found that only DO and pH parameters have a low skewness coefficient. This indicates that, in the case of skewness, the characteristic of data for each station is quite similar. We also found that the value of the kurtosis coefficient of NH3-NL and SS is significantly larger than the coefficient of other parameters. This indicates that the appearance probability of outlier in both parameters is higher, and thus the prediction of both parameters will be more difficult. From the total number of data for each station, we split the data before training, validation, and test data in the ratio of 3:1:1. The trained data was used to develop the model, while the validation data was used to adjust the value of the model parameter. The test set is used as the external data to verify the acceptability of the model.

Artificial neural network.
An artificial neural network (ANN) is a method inspired by the work of the nervous system in the human body. The architecture of ANN is comprised of an input layer, a hidden layer, and an output layer. In the process of ANN, the hidden node will process the value fed in the input layer and transmit the prediction to the output layer. From several architectures of ANN, the three-layer feed-forward backpropagation network is the ANN architecture that is very commonly used [17]. This architecture comprises of one hidden layer with nonlinear transfer functions and one output layer with linear transfer functions. The architecture of ANN can be adapted for time series analysis by using the previous values as the input to predict the following values. A schematic diagram of the ANN network for the time series analysis is provided in Figure 2, where represents the value of variable at time . The training of the ANN network was performed by adjusting the weight values to obtain the output with the lowest error. After the training process, the performance of the ANN must be validated after using the external dataset. The adjustment of the weight values was performed by using a backpropagation algorithm with the steepest descent direction as the reference. From the viewpoint of the optimization process, the ANN training process is equivalent to the process of minimizing a multivariable error function as a function of the network weights [17]. The backpropagation algorithm adjusts the weight values by evaluating the gradient of the error function in relation to the weight values at each iteration by using Equation 1.
Where , , and ( ) represent weight at time , learning rate, and gradient of error. The learning rate determines how fast the algorithm will learn to obtain the correct output. This parameter gives a contribution to the performance of the learning algorithm. There are several algorithms used in gradient descent optimization, such as RMSProp and Adam.
In this study, we utilized three-layer ANN architecture in which the number of hidden nodes is equal to the number of input. The activation function in the hidden and output layer ReLU and Linear function, respectively. Adam optimizer was used to adjust the weight values in the backpropagation algorithm. The default epochs number used to train the model is 500. However, we optimized the epochs number for each model by implementing an early stopping algorithm with the patience value of 10. Therefore, the iteration will be stopped if the loss value of the validation set does not improve after 10 epochs. Regarding the time series analysis, the value of look back is very important and gives a contribution to accuracy. This value indicated the number of previous data that was used to predict the following data. The too-large value of look back will lead to overfitting, while the too small value of look back will lead to underfitting. To obtain a more suitable number of look back, we performed a tuning procedure by considering the lookback value range from 3 to 10. The detail of the ANN parameter used in this study is provided in Table 3. The values of the dataset were normalized to a range of 0 to 1 to speed up the learning process and lead to a faster convergence state.

Model validation.
The performance of the ANN model was validated by using three validation parameters, i.e., root mean square of error (RMSE), the mean absolute percentage error (MAPE), and Pearson correlation coefficient (PCC). Those parameters were used to determine the ability of the ANN model to predict the water quality parameters (WQP) in each station. RMSE and MAPE, which represent the degree of error obtained from the prediction, were calculated by using Equations 2 and 3, respectively.
Where and represent the actual and predicted monthly WQP values, respectively, and represents the number of data. Since the RMSE values depend on the values range, the parameter was calculated by using the scaled dataset to allow the comparison of the values amongst the WQP. The third validation parameter is PCC, that represents a linear correlation between actual and predicted values. The range values of this parameter are from -1 to +1, where the PCC values of +1, 0, and -1 represent positive linear correlation, no correlation, and negative linear correlation, respectively. PCC was calculated by using Equation 4. We consider the PCC of the test set as an overall parameter to determine the performance of the models.

Results and Discussion
The result of optimized values of look back and epochs number for each parameter and station was provided in Table 4. We found the variation of those values that indicate the different tendencies of water quality parameters (WQP) in each station. The high values of look back indicate that the model required more input values to give a good prediction, while the low values of look back indicate that the few data is enough for the model to make a good prediction. This corresponds to the relation between the previous and the following data. We also found the variation of epoch numbers for each parameter and station. The variation corresponds to the epoch number required by the model to obtain satisfied loss value of validation data. The learning curve of the ANN training process of WQP in station 1 is presented in Figure 3. The curve represents the performance of the training process and can be used as an indicator of whether the model is a good fit, underfit, or overfit. The underfit condition is indicated by the large gap between train and validation loss. Meanwhile, the overfit condition is indicated by the increase of validation loss and the decrease of train loss at the end of the training process. According to Figure 3, we found that the training was stopped after both of the train and validation loss coincidentally decrease. Besides, the losses values are found to be quite stable for several epochs before the training process finishes. We also found that the gap between train and validation loss is not too large. Those conditions indicate that the models are a good fit. However, we found that several models in other stations need to improve because of the indication of underfitting or overfitting. Hyperparameter tuning can be performed to overcome these problems.
To verify the model prediction, the time series data of the WQP was predicted by using the model. The comparison of the actual values with the predicted values of the WQP in station 1 is provided in Figure 4, while the comparison of those values in the rest stations are provided in Supporting Information. We found that the predicted values for the parameters in station 1 are very close to the actual one. The small deviation of the predicted values of the test set specifies the ability of the model to predict the external dataset. The linear correlation of the actual and predicted values of the parameters in station 1 is presented in Figure 5. We found that the majority of data points are gathered around the straight line, while few data points have a small deviation from the line. The deviation indicates the degree of error of the predicted values compared to the actual one. The results show the ability of the model to recognize the pattern of the time series data.  The validation parameter, i.e., RMSE, MAPE, and PCC is represented in Table 5. To obtain the general insight, we calculate the average values of the validation parameter of each WQP and each station as provided in Tables 5 and 6, respectively. In the case of WQP, we found that the COD parameter presents the lowest RMSE values for the train, and test set, while the SS parameter presents the lowers RMSE values for the validation set. According to MAPE calculation, we found that the pH parameter presents the lowest MAPE values for train, validation, and test set. From PCC analysis, we found that the parameter with the highest PCC values for the train set is COD, while the highest values for validation and test set is pH. By considering the PCC of the test set as the overall performance, we found that the best results were obtained from the prediction of pH. This is related to the statistical properties of the pH that has the smallest value of kurtosis. This indicates that the small appearance of outliers in the pH dataset leads to good performance. We also found that the average value of PCC for all parameters is more than 0.60, which indicates the validity of the ANN models. In the case of the validation parameter for each station, we found the lowest RMSE of WQP for train, validation, and test set are found in the prediction of WQP in stations 2, 3, and 10, respectively. As for MAPE analysis, we found that the prediction of WQP in station 6 gives the lowest value of MAPE for a train set, while the prediction of WQP in station 1 gives the lowest MAPE for validation and test set. As for PCC, the highest value of PCC for train, validation, and test set found in the prediction of WQP in stations 2, 3, and 1, respectively. The PCC values of the test set pointed out that the best prediction of WQP was obtained from the prediction of WQP in station 1. However, the prediction of WQP in station 2 and 3 also gave a satisfying result. This relates to the number of data available for those stations that are more than the available data in the other station, except station 8. This indicates that the number of data used in the development of the model gave a contribution to the performance of the model.

Conclusions
An artificial neural network (ANN) with three hidden layers was used to predict time series data of water quality parameters (WQP), i.e., dissolved oxygen (DO), biological oxygen demand (BOD), chemical oxygen demand (COD), pH, ammonia nitrogen (NH3-NL), suspended solids (SS). The WQP were collected from 14 stations in the Kelantan River, Malaysia. The ANN model was trained by using the optimized value of look back and epochs number. The validation was performed by calculating the root mean square of error (RMSE), mean absolute percentage of error (MAPE), and Pearson correlation coefficient (PCC). As for WQP analysis, we found that the best results were obtained from the prediction of pH parameter. The lowest kurtosis values of pH indicated that the appearance of outliers had an impact on the model. As for WQP for each station, we found that the good prediction was obtained from the prediction of WQP in stations 1, 2, and 3. The more available data in those stations indicated that the number of data is important in the prediction of time series data.