Abstract
Water is essential for life, as it supports bodily functions, nourishes crops, and maintains ecosystems. Drinking water is crucial for maintaining good health and can also contribute to economic development by reducing healthcare costs and improving productivity. In this study, we employed five different machine learning algorithms – logistic regression (LR), decision tree classifier (DTC), extreme gradient boosting (XGB), random forest (RF), and K-nearest neighbors (KNN) – to analyze the dataset, and their prediction performance were evaluated using four metrics: accuracy, precision, recall, and F1 score. Physiochemical parameters of 30 groundwater samples were analyzed to determine the Water Quality Index (WQI) of Pano Aqil city, Pakistan. The samples were categorized into the following four classes based on their WQI values: excellent water, good water, poor water, and unfit for drinking. The WQI scores showed that only 43.33% of the samples were deemed acceptable for drinking, indicating that the majority (56.67%) were unsuitable. The findings suggest that the DTC and XGB algorithms outperform all other algorithms, achieving overall accuracies of 100% each. In contrast, RF, KNN, and LR exhibit overall accuracies of 88, 75, and 50%, respectively. Researchers seeking to enhance water quality using machine learning can benefit from the models described in this study for water quality prediction.
HIGHLIGHTS
Groundwater quality is evaluated using the Water Quality Index method.
Machine learning algorithms are used for forecasting groundwater quality.
The predictive capabilities of decision tree classifier, extreme gradient boosting, logistic regression, random forest, and K-nearest neighbors models have been evaluated and compared.
LIST OF ABBREVIATIONS
- dS/m
deci Siemens per meter
- DTC
decision tree classifier
- EC
electrical conductivity
- GIS
geographic information system
- KNN
K-nearest neighbors
- LR
logistic regression
- Mg
magnesium
- mg/l
milligrams per liter
- pH
power of hydrogen
- RF
random forest
- TDS
total dissolved solids
- TH
total hardness
- UC
Union Council
- WHO
World Health Organization
- WQI
Water Quality Index
- XGB
extreme gradient boosting
INTRODUCTION
Water consumption helps to sustain bodily processes and avoids dehydration, making it crucial for human existence. In many areas, groundwater is a significant supply of drinking water, but it must be managed properly to avoid pollution. Drinking water can include dangerous bacteria, viruses, and chemicals that, if not adequately handled, can cause waterborne diseases and other health issues. Both natural and man-made influences, which alter the physical and chemical properties of groundwater, have a significant impact on the degradation of groundwater quality (Nordin et al. 2021). Nations rely on clean drinking water for social stability, economic growth, and public health. A healthy and thriving society and the achievement of sustainable development goals both depend on having access to clean water. Many people still need a basic supply of drinking water (Anigrou et al. 2022). Groundwater quality is a significant aspect and a basic need of many countries, including Pakistan (Panhwar et al. 2022; Solangi et al. 2022). It is estimated that ∼33% of the global population uses groundwater for drinking, irrigation, agriculture, and industrial purposes due to the ease with which less contaminated groundwater is obtained compared to surface water (Solangi et al. 2017, 2018; Jamali et al. 2023). However, once groundwater is contaminated, it is quite difficult to restore its previous purity or quality (Arulbalaji & Gurugnanam 2017). With expanded research regarding the importance of drinking water quality to people and raw water quality to amphibian life, there is an urgent need to assess groundwater quality (Ouyang 2005). It is critical that the global availability of groundwater resources be fully considered (Subramani et al. 2010).
The type of soil and chemical composition plays a significant role in groundwater quality (Abbasnia et al. 2018). Synthetic organic compounds such as pharmaceuticals and personal care products, pesticides and herbicides, and industrial chemicals, and heavy metals such as iron (Fe), zinc (Zn), copper (Cu), nickel (Ni), chromium (Cr), cadmium (Cd), mercury (Hg), lead (Pb), and arsenic (As) are among the anthropogenic components that have the greatest impact on the quality and accessibility of safe drinking water (Ali et al. 2023). Water quality is currently a major research focus for a number of scientists all around the world. As a result of these developments and analyses, a number of numerical and factual models have been developed and used to assess the quality of both surface and groundwater in various parts of the world. Pollution Index of Groundwater (PIG), Synthetic Pollution Index, Integrated Water Quality Index, Overall Index of Pollution, hierarchical cluster analysis, and Aquatic Life Water Index are some of the methodologies that are now being used in water quality evaluations. The Water Quality Index (WQI) is frequently used to determine the impact of water pollutants on the quality of water. It defines whether water is suitable for drinking or not (Solangi et al. 2019a). Various researchers such as Dede et al. (2013), Shabbir & Ahmed (2015), Sener et al. (2017), Solangi et al. (2019a), and Jamali et al. (2023) with some statistical variations of various physicochemical parameters have applied WQIs across the globe. To manage water resources and create spatial databases for the distribution of groundwater quality throughout the world, researchers around the globe also apply the geographical information system (GIS) (Sener et al. 2017; Jamali et al. 2023).
Also, environmental engineering uses machine learning (ML) in a variety of ways, including examining massive data to spot patterns and trends and leveraging more recent developments in ML techniques to create models that can forecast future environmental conditions (Tahmasebi et al. 2020). The ML is a useful tool widely used nowadays for predicting the groundwater quality. It is ability to handle complex hydrological data makes it popular (Nordin et al. 2021). Selecting appropriate input parameters can enhance its efficiency. Haghiabi et al. (2018) have used several ML models, including support vector regression (SVR), artificial neural network (ANN), and decision tree (DT). They observed that the SVR model outperformed the other models in predicting water quality parameters. El Bilali et al. (2021) utilized four ML models: ANN, DT, random forest (RF), and SVR and found the RF as the most accurate model for groundwater quality forecasting. The integration of ML, GIS, and WQI yields significant information about the quality of water (Solangi et al. 2019b; Jamali et al. 2023).
Thus, in the present study, ML models such as decision tree classifier (DTC), extreme gradient boosting (XGB), K-nearest neighbors (KNN), RF, and logistic regression (LR) using Python programming have been used, and compared the performance of all models in terms of making predictions about the physicochemical properties of groundwater in a troubled area and to assess its suitability for drinking purposes. Also, a widely applied WQI and GIS have been used to assess and map the overall quality of groundwater of Pano Aqil city, Sindh, Pakistan. This investigation also took advantage of ML in terms of predicting and monitoring the groundwater quality of the study area so that the possibility of contamination, which could affect the water quality, can be reduced.
MATERIALS AND METHODS
Study area description
Data set and sample analysis
Calculating the WQI
Wi is the relative weight of a water quality parameter, wi is the weight to the ith parameter, and n stands for the total number of parameters, qi is the water quality rating, Ci is the observed concentration for each water quality parameter, and Si is the permissible level proposed by WHO for drinking water purposes.
In the present study, water quality parameters were assigned a weight (wi) from 1 to 5 depending upon their significance in water quality evaluation for human health (Shabbir & Ahmed 2015; Sener et al. 2017; Solangi et al. 2019b, 2019c; Jamali et al. 2023). However, respective relative weights were calculated by dividing the assigned weight with the overall sum of assigned weights of all parameters (Shabbir & Ahmed 2015; Sener et al. 2017; Solangi et al. 2019b, 2019c) (Tables 1 and 2).
ML prediction models
ML is a powerful tool for monitoring and predicting water quality in specific areas. Groundwater contamination can be costly to remediate, but ML can help by alerting authorities of changes in water quality. In this study, various ML models were utilized to predict water quality.
DTC
XGB
XGB is a popular ensemble learning technique that uses DTs as predictors, built sequentially with each tree learning from the residuals of the previous ones. This boosting process reduces errors gradually, leading to a more accurate and robust model. XGB is known for its high accuracy and efficiency in handling large datasets (Jing et al. 2020).
The specific loss function can be represented as L(y, F(x)), where y is the true target, and F(x) is the prediction of the XGB model for input x.
Here, λ and α are hyperparameters that control the strength of L2 and L1 regularization, respectively. The wi terms represent the weights of individual trees in the ensemble.
KNN
KNN is a non-parametric ML algorithm that works by finding the k-nearest data points to a given input point in the feature space. Here, k refers to the number of nearest neighbors to consider, which is a hyperparameter that can be adjusted by the user. The algorithm is slow when working with large datasets. However, it is still a useful algorithm for various ML tasks (Bramer 2007).
RF
RF is a powerful ML algorithm that uses an ensemble of classification and regression trees to make accurate predictions. The algorithm works by building multiple DTs, each using a different bootstrap sample from the original dataset (Voyant et al. 2017).
In a RF, the ultimate categorization choice is usually decided by majority vote. Each DT in the ensemble makes a prediction, and the class with the most votes from all trees is the final forecasted class.
The ‘Mode’ method returns the class prediction that appears the most frequently in the individual trees.
LR
The goal of LR is to find the best hyperplane that minimizes the distance between the predicted values and the actual values of the dependent variable for each data point, LR uses a method called least squares, which involves minimizing the sum of the squared differences between the predicted and actual values of the dependent variable (Khademi et al. 2016).
WQI range . | Water classification . |
---|---|
< 50 | Excellent water |
50–100 | Good water |
> 100–200 | Poor water |
> 200–300 | Very poor water |
> 300 | Unfit for drinking |
WQI range . | Water classification . |
---|---|
< 50 | Excellent water |
50–100 | Good water |
> 100–200 | Poor water |
> 200–300 | Very poor water |
> 300 | Unfit for drinking |
Parameter . | WHO standard . | Weight (wi) . | Relative weight (Wi) . |
---|---|---|---|
pH | 8.6 | 3 | 0.10 |
Chloride | 250 (mg/l) | 4 | 0.13 |
Nitrates | 10 (mg/l) | 5 | 0.16 |
Nitrites | 0.02 (mg/l) | 2 | 0.06 |
Calcium | 50 (mg/l) | 2 | 0.06 |
Sulfates | 400 (mg/l) | 2 | 0.06 |
TDS | 500 (mg/l) | 4 | 0.13 |
TH | 500 (mg/l) | 3 | 0.10 |
EC | 0.7 (ds/m) | 4 | 0.13 |
Mg | 75 (mg/l) | 2 | 0.06 |
∑wi | 31 |
Parameter . | WHO standard . | Weight (wi) . | Relative weight (Wi) . |
---|---|---|---|
pH | 8.6 | 3 | 0.10 |
Chloride | 250 (mg/l) | 4 | 0.13 |
Nitrates | 10 (mg/l) | 5 | 0.16 |
Nitrites | 0.02 (mg/l) | 2 | 0.06 |
Calcium | 50 (mg/l) | 2 | 0.06 |
Sulfates | 400 (mg/l) | 2 | 0.06 |
TDS | 500 (mg/l) | 4 | 0.13 |
TH | 500 (mg/l) | 3 | 0.10 |
EC | 0.7 (ds/m) | 4 | 0.13 |
Mg | 75 (mg/l) | 2 | 0.06 |
∑wi | 31 |
Correlation analysis
Correlation analysis is a statistical technique that measures the strength and direction of the relationship between two variables. In the present study, the significance of the values of the correlation coefficients has been assessed on the Pearson p-value. Values closer to 1 indicate a positive correlation, values closer to −1 indicate a negative correlation, and values closer to 0 indicate no correlation. Correlation analysis can be used to identify which variables are strongly related to the target variable. This can help us to understand the underlying patterns in the data and make more accurate predictions.
The WQI is our target variable, and Table 3 shows the correlation coefficients between the WQI and other water quality parameters. We can observe that the WQI has a higher positive correlation with nitrites (0.953), TDS (0.425), EC (0.388), TH (0.353), magnesium (0.345), pH (0.327), and sulfates (0.310). This indicates that as these variables increase, the water quality tends to worsen, and vice versa.
WQI has a negative correlation indicating that as the level of nitrates in water increases, the water quality tends to worsen, and vice versa. The other variables have weaker correlations with WQI, with correlation coefficients ranging from 0.074 (nitrates) to 0.327 (pH).
The other variables have weaker correlations with the WQI, with correlation coefficients ranging from 0.074 (nitrates) to 0.229 (lime calcium).
Parameters . | Ph . | Chloride . | Nitrates . | Nitrites . | Lime calcium . | Sulfates . | TDS . | TH . | EC . | Mg . | WQI . |
---|---|---|---|---|---|---|---|---|---|---|---|
pH | 1.000 | ||||||||||
Chloride | 0.418 | 1.000 | |||||||||
Nitrates | −0.150 | 0.129 | 1.000 | ||||||||
Nitrites | 0.165 | −0.028 | 0.030 | 1.000 | |||||||
Lime calcium | 0.277 | 0.066 | −0.011 | 0.013 | 1.000 | ||||||
Sulfates | 0.571 | 0.309 | 0.065 | 0.043 | 0.680 | 1.000 | |||||
TDS | 0.615 | 0.362 | 0.063 | 0.151 | 0.697 | 0.894 | 1.000 | ||||
TH | 0.517 | 0.355 | 0.030 | 0.068 | 0.740 | 0.887 | 0.887 | 1.000 | |||
EC | 0.513 | 0.365 | 0.042 | 0.103 | 0.725 | 0.867 | 0.911 | 0.962 | 1.000 | ||
Mg | 0.498 | 0.338 | 0.038 | 0.059 | 0.747 | 0.882 | 0.880 | 0.994 | 0.968 | 1.000 | |
WQI | 0.326 | 0.139 | 0.074 | 0.953 | 0.229 | 0.310 | 0.425 | 0.353 | 0.388 | 0.344 | 1.000 |
Parameters . | Ph . | Chloride . | Nitrates . | Nitrites . | Lime calcium . | Sulfates . | TDS . | TH . | EC . | Mg . | WQI . |
---|---|---|---|---|---|---|---|---|---|---|---|
pH | 1.000 | ||||||||||
Chloride | 0.418 | 1.000 | |||||||||
Nitrates | −0.150 | 0.129 | 1.000 | ||||||||
Nitrites | 0.165 | −0.028 | 0.030 | 1.000 | |||||||
Lime calcium | 0.277 | 0.066 | −0.011 | 0.013 | 1.000 | ||||||
Sulfates | 0.571 | 0.309 | 0.065 | 0.043 | 0.680 | 1.000 | |||||
TDS | 0.615 | 0.362 | 0.063 | 0.151 | 0.697 | 0.894 | 1.000 | ||||
TH | 0.517 | 0.355 | 0.030 | 0.068 | 0.740 | 0.887 | 0.887 | 1.000 | |||
EC | 0.513 | 0.365 | 0.042 | 0.103 | 0.725 | 0.867 | 0.911 | 0.962 | 1.000 | ||
Mg | 0.498 | 0.338 | 0.038 | 0.059 | 0.747 | 0.882 | 0.880 | 0.994 | 0.968 | 1.000 | |
WQI | 0.326 | 0.139 | 0.074 | 0.953 | 0.229 | 0.310 | 0.425 | 0.353 | 0.388 | 0.344 | 1.000 |
Model construction process
Python programming was used to create, construct, and train the models. The process of constructing a model typically involves three stages: training, validation, and testing. During the training stage, the model is exposed to a set of input–output patterns. In the validation stage, the model's performance is evaluated on patterns it has not seen before. Finally, during the testing stage, the model's performance is evaluated on unknown patterns that it has not been trained on or validated with (Ahmed et al. 2019). For the current study, the majority of the data is used for training the model, while smaller portions are set aside for testing and validation. In this specific case, the training dataset consists of 55% of the original data, while the testing dataset is 25% and the validation dataset is 20%.
RESULTS AND DISCUSSION
Groundwater quality statistical analysis
The statistical summary of the physicochemical analysis of groundwater of the study area in terms of permissible limit, minimum, maximum, average value, and standard deviation is described in Table 4.
Parameters . | Permissible limit . | Minimum . | Maximum . | Average value . | Standard deviation . |
---|---|---|---|---|---|
Ph | 8.5 | 7.30 | 8.90 | 7.85 | 0.37 |
Chlorides | 250 mg/l | 34 | 2,220 | 331.23 | 560.51 |
Nitrates | 10 mg/l | 0 | 20 | 4.60 | 6.90 |
Nitrites | 0.02 mg/l | 0 | 5 | 0.59 | 1.32 |
Lime calcium | 75 mg/l | 15 | 590 | 81.93 | 93.82 |
Sulfates | 400 mg/l | 100 | 1,700 | 390.67 | 459.27 |
TDS | 1,000 mg/l | 180 | 5,100 | 954.33 | 1,199.13 |
TH | 500 mg/l | 40 | 2,050 | 383.50 | 446.08 |
EC | 0.7 dS/m | 0.24 | 8.03 | 1.55 | 1.86 |
Mg | 50 mg/l | 39 | 1,730 | 305.90 | 380.27 |
Parameters . | Permissible limit . | Minimum . | Maximum . | Average value . | Standard deviation . |
---|---|---|---|---|---|
Ph | 8.5 | 7.30 | 8.90 | 7.85 | 0.37 |
Chlorides | 250 mg/l | 34 | 2,220 | 331.23 | 560.51 |
Nitrates | 10 mg/l | 0 | 20 | 4.60 | 6.90 |
Nitrites | 0.02 mg/l | 0 | 5 | 0.59 | 1.32 |
Lime calcium | 75 mg/l | 15 | 590 | 81.93 | 93.82 |
Sulfates | 400 mg/l | 100 | 1,700 | 390.67 | 459.27 |
TDS | 1,000 mg/l | 180 | 5,100 | 954.33 | 1,199.13 |
TH | 500 mg/l | 40 | 2,050 | 383.50 | 446.08 |
EC | 0.7 dS/m | 0.24 | 8.03 | 1.55 | 1.86 |
Mg | 50 mg/l | 39 | 1,730 | 305.90 | 380.27 |
pH
The pH of water determines whether it is acidic or basic, pH is also an indicator of the corrosivity of water (lower the pH higher is the chances of corrosion in water). The pH limit of drinking water should be between 7.0 and 8.5 and between 6.5 and 8.5, respectively (WHO 2004). Human health is affected by the pH of water if it is beyond the allowable range, it may damage the mucous membrane and water supply system (Shakoor et al. 2022). In the present study, the pH in the groundwater samples ranged between 7.3 and 8.9 with a mean value of 7.85. The results of pH in the groundwater of the study area are like those reported by Shakoor et al. (2022) for the groundwater of Piryaloi Union Council (UC), Sindh, Pakistan.
EC
The EC determination aids us in immediately determining and analyzing mineralization, natural water changes, and wastewater, as well as the determination of chemical reagents to be mixed in a water sample (Panhwar et al. 2022). Greater EC shows the higher concentration of salts and indicates more saline nature of water. Also, the EC of water varies with temperature, with the increase in temperature EC is also increased. Solangi et al. (2019b) reported that the EC in drinking water should be less than 0.7 ds/m. Higher the concentration of dissolved ions in water, the higher will be the EC (Mohsin et al. 2013; Ali et al. 2023). It was found that the EC in the analyzed groundwater ranged from 0.24 to 8.03 dS/m, and the mean value was 1.55 dS/m (Table 4). A similar trend of EC values for groundwater of the Sukkur city in Sindh, Pakistan was reported by Ansari et al. (2021).
TDS
TDS is a main parameter that evaluates the suitability of water for domestic, industrial, and irrigation purposes (Solangi et al. 2019a). The mixture of dissolved inorganic and organic salts present in water is termed as TDS. TDS is highly dependent on the EC of water as the rise in EC increases the solubility of water which in turn increases the amount of dissolved solids in water. TDS in water can come from a variety of natural sources, including sewage, soil nature, and industrial waste. The weight of the substance on the water evaporation to dryness estimated by heating for 1 h at 180° gives the amount of dissolved stuff. In the study area, we found that the TDS values ranged between 180 and 5,100 mg/l, with a mean value of 954.33 mg/l. When TDS concentration in water is beyond 1,000 mg/l then the water is to be considered as unsuitable for drinking and causes gastrointestinal irritation to consumers. However, the desirable limit of TDS in drinking water is 500 mg/l. The observed values of TDS in the groundwater of the study area are higher than the values prescribed by WHO. A similar trend of TDS values for groundwater of the Sukkur city, Sindh, Pakistan (a neighboring city of the present study area), and Larkana taluka, Sindh, Pakistan were reported by Ansari et al. (2021) and Jamali et al. (2023), respectively.
Magnesium
The association of calcium and magnesium ions is responsible for water hardness (Solangi et al. 2019b). It was reported that a lack of magnesium content in the human body may cause various diseases. However, excessive magnesium content, i.e., higher than 125 mg/l is dangerous for human health and may give birth to laxative effects in human beings. The cations and anions of magnesium, calcium, carbonate, sulfate, chlorides, and bicarbonate are the main causes of temporary hardness in water. The allowable limit of Mg in drinking water according to the WHO (2006) is 50 mg/l. Rosanoff (2013) has described that universal drinking water and beverages containing moderate-to-high Mg amount can prevent more than 4 million heart diseases and deaths due to stroke annually. The Mg amount in the groundwater of the study area ranged between 39 and 1,730 mg/l and the mean value obtained is 305.90 mg/l. Ansari et al. (2021) have reported a similar trend of Mg concentration in the groundwater of Sukkur city, Sindh, Pakistan.
Nitrates and nitrites
Nitrites and nitrates are salts that can be found naturally or chemically and artificially in groundwater. Nitrites are mostly found in fertilizers, runoff water, mineral deposits, and sewage. In our study, we found that nitrites amount in the groundwater ranges from 0 to 5 mg/l and a mean value which we obtained is 0.59 mg/l. However, nitrates amount in the groundwater ranges from 0 to 20 mg/l and the mean value which we obtained is 4.60 mg/l. A similar trend of nitrates and nitrites concentration in the groundwater of Sukkur city was reported by Ansari et al. (2021).
Lime calcium
The lime calcium amount ranged from 15 to 590 mg/l and the mean value which we obtained is 81.93 mg/l. WHO (2006) has suggested the desirable value which is 75 mg/l. According to some evidence, taking calcium supplements may help to prevent heart diseases (Li et al. 2018). A similar trend of lime calcium concentration in the groundwater of Piryaloi UC was reported by Shakoor et al. (2022).
Chloride
Chloride is a mixture of chlorine gas, metal, and some small earth crust materials, although it is one of the principals dissolved minerals in most of the natural waters. The WHO guideline of chloride content in potable water is 250 mg/l. Its excessive concentration in water causes high blood pressure and gives birth to kidneys and heart diseases. Chloride can harm freshwater and lakes because it dissolves in water from a variety of sources, including heavy industrial waste and waste from treatment plants. In this study area, the chloride content ranges from 34 to 2,220 mg/l and the mean value which we obtained is 331.23 mg/l. A similar trend of chloride concentration in the groundwater was reported by Ansari et al. (2021) and Jamali et al. (2023) for groundwater of Sukkur city, and Larkana taluka, respectively.
Total hardness
The percentage of calcium and magnesium in the water is referred to as TH. In general, surface water is softer than groundwater. The WHO recommended a hardness limit of 500 mg/l. In the study area, the hardness value ranges from 40 to 2,050 mg/l and the mean value which we obtained is 383.50 mg/l. A similar trend of TH concentration in the groundwater of Larkana taluka and Sukkur city were reported by Jamali et al. (2022) and Ansari et al. (2021), respectively.
Sulfate
Sulfate can be either natural or man-made; naturally, it comes from rocks or soil, while man-made sulfate comes from fertilized land runoff. One of the most critical nutrients for plants is sulfur. The WHO recommends a sulfate limit of 400 mg/l. In this study, the sulfate ranged from 100 to 1,700 mg/l and the mean value which we obtained is 390.67 mg/l. Ansari et al. (2021) reported similar trends of sulfates in the groundwater of the Sukkar city of Sindh province of Pakistan.
Spatial distribution of category of water
Performance metrics and measures of accuracy
To evaluate how effectively an ML model performs on classification tasks, a confusion matrix is typically utilized. It shows how many of the model's predictions were correct and incorrect when compared to the actual outcomes. To develop a confusion matrix to test model accuracies, a popular ML toolkit in Python called ‘Scikit-learn’ was utilized.
In a four-class classification scenario (Table 5), the diagonal elements in the matrix show the number of correct predictions for each class, while the off-diagonal elements represent the number of misclassifications. The letter codes TN, TPJ, TPK, and TPL denote the number of true negatives for class 0 and the number of true positives for classes 1, 2, and 3, respectively. The codes FPI, FPII, FPIII, FJII, FJIII, FKIII, FJ, FK, FKII, FL, FLII, and FLIII indicate the misclassifications between predicted and actual classes, which could arise due to either false positives or false negatives.
. | . | Predicted class . | |||
---|---|---|---|---|---|
. | . | Class 0 . | Class 1 . | Class 2 . | Class 3 . |
Actual class | Class 0 | TN | FPI | FPII | FPIII |
Class 1 | FJ | TPJ | FJII | FJIII | |
Class 2 | FK | FKII | TPK | FKIII | |
Class 3 | FL | FLII | FLIII | TPL |
. | . | Predicted class . | |||
---|---|---|---|---|---|
. | . | Class 0 . | Class 1 . | Class 2 . | Class 3 . |
Actual class | Class 0 | TN | FPI | FPII | FPIII |
Class 1 | FJ | TPJ | FJII | FJIII | |
Class 2 | FK | FKII | TPK | FKIII | |
Class 3 | FL | FLII | FLIII | TPL |
The confusion matrix used for multi-class classification can be transformed into a series of binary-class confusion matrix. This transformation allows the computation of metrics such as precision, recall, accuracy, and F1 score for each class. The following binary-class confusion matrix (Table 6) is used for each class.
. | . | Predicted class . | |
---|---|---|---|
0 | 1 | ||
Actual class | 0 | TN | FP |
1 | FN | TP |
. | . | Predicted class . | |
---|---|---|---|
0 | 1 | ||
Actual class | 0 | TN | FP |
1 | FN | TP |
True Positive (TP) indicates the number of correctly predicted positive instances; False Positive (FP) indicates the number of incorrectly predicted positive instances; True Negative (TN) indicates the number of correctly predicted negative instances; False Negative (FN) indicates the number of incorrectly predicted negative instances.
Accuracy, precision, recall, and F1 score are measures used in ML to assess a model's performance.
Accuracy
Precision
Recall
F1 score
The labels in this study are divided into four classes: 0 = excellent water, 1 = good water, 2 = poor water, and 3 = unfit for drinking. The overall accuracies are 100, 100, 88, 75, and 50% for DTC, XGB, RF, KNN, and LR, respectively.
Algorithms results
F1 score, recall, and precision are useful for forecasting water quality, especially in the context of classification tasks when we are attempting to categorize water samples into different quality classes (e.g., excellent water to unsuitable for drinking). These indicators aid in evaluating the efficacy of our prediction model. When their scores are high, it suggests that our model is doing well in predicting water quality. The LR model achieved perfect precision for class 0, but low recall, indicating that it correctly identified all positive instances in that class but missed many others. For class 1, the model has a low precision, indicating that many negative instances were misclassified as positives, but relatively high recall, indicating that many of the positive instances were correctly identified. Class 2 achieved the highest performance, with a relatively high precision, recall, and F1 score. The model completely failed to identify any positive instances in class 3. Overall, the model's accuracy was 50%, suggesting that the model's performance is not very good. The KNN model has performed well with high precision, recall, and F1 score for most of the classes, except for class 1, where it achieved a moderate performance. All classes have a perfect F1 score except for class 2, which has an F1 score of 0.50. The DTC and XGB models have performed perfectly, achieving a precision, recall, and F1 score of 1.00 for all classes. The RF model has high precision, recall, and F1 score for classes 0, 1, and 2, but the recall and F1 score for class 3 is 0, indicating poor performance for that class as shown in Figure 5.
Weighted average accuracy is a statistic that accounts for a model's performance in predicting distinct classes of water quality while taking the class distribution into account. It computes the average accuracy for each class and then weights these accuracies depending on the proportions of the classes.
The weighted average accuracy of LR is quite low, indicating that the model's performance is poor. It implies that the model is making some incorrect classifications across four water quality classes. This low accuracy might be attributed to factors such as inadequate model selection or insufficient training data.
CONCLUSION
Analysis of groundwater based on the physicochemical parameters revealed that the EC ranged between 0.24 and 8.03 dS/m, with an average of 1.55 dS/m. The TDS ranged between 180 and 5,100 mg/l with a mean value of 954.33 mg/l. The Mg concentrations varied from 39 to 1,730 mg/l with its mean value of 305.90 mg/l. The lime calcium ranged between 15 and 590 mg/l with its mean value of 81.93 mg/l. The chloride concentration varied from 34 to 2,220 mg/l with its mean of 331.23 mg/l. The hardness varied from 40 to 2,050 mg/l with a mean of 383.5 mg/l. However, most of the samples (∼53%) possessed EC, TDS, calcium, magnesium, hardness, and chloride concentrations beyond the WHO drinking water quality guidelines. Also, the analysis based the WQI estimations, 43.33% of the samples were found suitable for drinking, while a majority (56.67%) of the samples were found unsuitable for drinking purposes. Moreover, analysis based on the ML algorithms to forecast the groundwater quality index, and comparison of model results indicated that the models' accuracy levels in predicting water quality follow the order of DTC and XGB being the most accurate, followed by RF and KNN, with LR being the least accurate. The precision, recall, and F1 scores for different classes were also measured using weighted averages, and it was found that DTC and XGB models had the highest weighted averages, while LR had the lowest weighted average. Further analysis based on the additional water quality parameters would be beneficial, as currently every attribute has 30 values, thus, it may be difficult to train ML algorithms. Overall, the analysis revealed that, in most of the areas of the Pano Aqil city, groundwater is unsuitable for drinking, thus, it should be treated well prior to its use for drinking.
DATA AVAILABILITY STATEMENT
All relevant data are included in the paper or its Supplementary Information.
CONFLICT OF INTEREST
The authors declare there is no conflict.