0% found this document useful (0 votes)
23 views6 pages

Water Quality Prediction with ML Models

This document discusses the use of machine learning algorithms to predict water contamination based on chemical and physical properties. Four models—Support Vector Machine (SVM), Random Forest, XGBoost, and LightGBM—were evaluated, with Random Forest achieving the highest accuracy of 63.5%. The study highlights the potential of AI in real-world water quality assessment and suggests future improvements through better data quality and model enhancements.

Uploaded by

ragavank27003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views6 pages

Water Quality Prediction with ML Models

This document discusses the use of machine learning algorithms to predict water contamination based on chemical and physical properties. Four models—Support Vector Machine (SVM), Random Forest, XGBoost, and LightGBM—were evaluated, with Random Forest achieving the highest accuracy of 63.5%. The study highlights the potential of AI in real-world water quality assessment and suggests future improvements through better data quality and model enhancements.

Uploaded by

ragavank27003
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Water Contamination Prediction using

MachineLearning Algorithm
V Raj Ajai Aanandh K Ragavan
Deparment of Computational Intelligence Department of Computational Intelligence
SRM Institute of Science and Technology SRM Institute of Science and Technology
rv9286@[Link] rk2899@[Link]

Abstract

A significant number of individuals look at clean water as II LITERATURE REVIEW


their inalienable right, but others find it challenging to secure
clean water day by day. By employing machine learning this The integration of water pollution projections with
experiment investigates the possibility of finding out if water is Artificial Intelligence (AI) has been of considerable
healthy to drink with the help of some elementary chemical and
physical properties such as pH, turbidity, and so on. A dataset
emphasis in the past few years. Researchers have given
that included 3,000+ samples was used and four model types- deep attention to the effectiveness of AI methodologies
SVM, Random Forest, XGBoost, and LightGBM-were tried out which are now utilized to complement conventional
to see which model worked the best. Although LightGBM was methods in testing and measuring the water quality. A
the most accurate, behind the scenes we used SVM to produce study from Xie et al. (2020) introduced the use of support
the consistent results and further to enable it to be easily linked vector machines in the prediction of a freshwater pollution
to our web app. A simple web tool of Flask was utilized to case, which indicates that the use of the support vector
create an application that enables people to be their own judge machine has had a better predictive ability than traditional
by entering some parameters. This serves as a case in point of
statistical techniques. Similarly, Liang et al. (2021) looked
AI being applicable to real-world problems in an
uncomplicated and effective manner. into the use of artificial neural networks in figuring out the
water pollution patterns and found that the timely discovery
I INTRODUCTION could be the catalyst when it comes to intervention actions.
Clean drinking water should be readily available to sustain III EXISTING MODELS AND METHODS
everyone's health. Many places still encounter the problem
of unsafe water that results in severe health problems. The
traditional ways of water quality testing need much time In this project, we explored the features of machine
and resources to be carried out. learning in identifying if water is clean or not based merely
on its properties through the process of analysis. We have
In fact, machine learning is the catalyst to the resolution of extracted the ins and outs of 3,276 water samples contained
all these issues thanks to the efficient and non-time in a special database, among them, the pH, hardness,
consuming procedures that it provides. Machine learning dissolved solids, and the ones from the aforesaid like
models, which are being fed with data sets such as pH, chloramine, sulfate, and some more such as conductivity,
turbidity, and so on, are able to generate a set of water organic carbon, trihalomethanes, and turbidity.
safety responses and thus the safety of the drinking water A total of four models were checked and then a proper
can be assured. These results not only facilitate swift comparison that was made between them came out with
actions but also save time. these names:
To be more specific, we applied four diverse machine
learning algorithms, namely Support Vector Machine  Support Vector Machine (SVM): The
(SVM), Random Forest, XGBoost and LightGBM to find various settings of this model were found by
out the safety of water. The best model was further GridSearchCV. This model showed desirable
deployed on a simple Flask based web page so that the results upon being provided with the right amount
users could be able to feed in some values and know if the of C, gamma, and kernel.
water is safe. This is indeed an application of artificial  Random Forest: This model is a combination
intelligence in water testing that is seen as smarter and of many decision trees that works great to its
more efficient compared to the previous one due to its self- accuracy. It is configured with 20 estimators and
sustaining nature. uses balanced sampling to avoid the case when
accuracy varies.
 XGBoost: This is a model that is derived from 3) Biological metrics: levels of coliform bacteria and other
an ensemble, which uses boosting as the method microbial indicators.
to elevate the predictions to another level. It has
demonstrated a striking performance in the fields A wide range of datasets provides the model with the
of structured data. training and validation that result in strong and reliable
 LightGBM: Swift and exact are the words to predictions.
describe this type of model which was definitely VII PREPROCESSING STEPS
the best. It is so because, even with big data, it
remains very reliable; therefore, it gained the Data preprocessing is the primary stage to perform when
advantage. the user acquires the raw data, and the raw data is
 XGBoost: This model uses boosting to improve processed so that it is in the right condition to be used for
predictions. It gave strong results on structured subsequent analysis. Processing the steps of data
data. preprocessing is done by in terms of simplicity.
 LightGBM: This model performed the best 1. Data Cleaning: Replacing missing values with mean or
among all. It is fast and accurate, especially with median of the variable was the way to handle it. Methods
large datasets. of interpolation and imputation were used to deal with 5.
IV RESEARCH GAPS 2. Normalization: Normalization of continuous variables
was done to achieve the goal of keeping the scaling
Many studies have used machine learning to predict water
uniformly significant and to make the input feature
quality through machine learning, but each of them has
magnitudes not dominate in the training set.
worked on one model alone. That is why it is a real
conundrum to know which models excel under what 3. Feature Selection: Correlation analysis was conducted
conditions. Furthermore, some studies may have data sets to eliminate multicollinearity, focusing on the most
that are not big enough or are not densely populated, and relevant features influencing water quality..
the models may not give accurate results. They mostly do
not conduct model comparisons and present how the VIII MACHINE LEARNING MODELS
models behave or validate these models with novel data.
To fill this void in the research, we managed to get a larger Several machine learning methods were utilized to
dataset and compared four models: namely SVM, Random determine the most appropriate strategy for avoiding water
Forest, XGBoost, and LightGBM. pollution in the future. Our approach was based on the
following principal models:

 Random Forest: The method of model generation


V METHODOLOGY was a plethora of Support Vector Machine
(SVM): The SVM has been programmed using
At this stage, this section definitely provides all the details radial base function (RBF) as a parameter. The
of the approach we took to our inquiry on the topic of AI process of the parameter was made to be very
in water contamination forecasting. In this part, the stages complex by the use of GridSearchCV for higher
the researchers moved through are displayed explicitly. accuracy. The final model had a very good rade-
These include the processes of data collection, the data off between precision and recall. Due to that the
pre-processing techniques, the choice of machine learning final model will not be changed and the model is
models as well as the employment of Python libraries. accepted for the deployment of the web
application in Flask.
VI DATA COLLECTION

The data used for the study were collected from different
sources such as environmental monitoring and chemical  XGBoost is a boosting algorithm that operates in
analysis by a variety of organizations and academic an iterative manner to have at the end a model
researchers working in the field of water. They further with better accuracy. XGBoost behaved in the
incorporated various requirements of the study into their right way on this particular data set and the
research. results were clearly visible. Mainly we could see
the effect in the structured data handling
1) Chemical parameters: pH levels, dissolved oxygen, and performance.
nutrient concentrations.
 LightGBM: The main advantage of LightGBM is
2) Physical parameters: turbidity and temperature. the speed along with the effectiveness of the new
model. It got prominent results, almost as good as
competitive accuracy, but still, SVM The methodologies in sum are those that give us the ability
outperformed it to go to production after the to forecast and prevent water contamination hazards
tuning process. through AI-empowered technologies, which are at the
forefront of the industry.
All models had been contrasted by means of accuracy
scores, confusion matrices, and the other evaluation XI EXECUTION METHODOLOGY
metrics. Then, SVM has been chosen as the final model
for deployment based on results. The main idea of carrying out this research was to
facilitate the learning and evaluation of three machine
learning models, including Random Forest, XGBoost, and
Support Vector Machine (SVM) for the purpose of
IX PYTHON LIBRARIES UTILIZED prediction of water pollution.
A set of libraries that were instrumental in materializing After conducting the data cleaning processes such as
the methodologies was: disappearance value treatment, outlier removal, and
feature scaling, the dataset was divided into a 70:30
The hydrology of water quality models had the support of
training and test set ratios. All the models went through the
a number of Python libraries. Pandas and NumPy were the
rigorous training and evaluation that are based on the
ones that did all the jobs that were connected with data
guidance of accuracy and classification metrics.
management, data pre-processing, and mathematical
operations. Matplotlib and Seaborn, on the other hand, The SVM model was subjected to Hyperparameter tuning
enabled us to visualize our data, and these tools were through GridSearchCV, and that brought about the
fantastic for finding patterns, correlations, and class enhancement of its performance to 63.25% accuracy.
distributions. Scikit-learn was the software that was Random Forest showed the highest accuracy of 63.5%,
applied nowadays to get machine learning models, and it while XGBoost came next with a value of 62.13%. SVM
came with certain modules that could do classification was a little bit different but still chosen in the end due to
(Random Forest and SVM), data splitting, performance its balanced results and quick integration with the Flask
evaluation, scaling, and hyperparameter tuning application.
(GridSearchCV). It was also the case that XGBoost
became the preferred choice to drive the predictive XII MODEL PERFORMANCE
performance in a more efficient and effective manner. The
final model was saved and deserialized using the Pickle Proposed model is executed and the following steps are
package one of the purposes being deployment. followed:

X EVALUATION METRICS 1. ph: pH of 1. water (0 to 14).


2. Hardness: Capacity of water to precipitate soap in
AccuracyScore: Accuracy is the rate of the correct mg/L.
predictions out of the total predictions. It mainly describes 3. Solids: Total dissolved solids in ppm.
the modeling quality. But it may be not sufficient in the 4. Chloramines: Amount of Chloramines in ppm.
situation with one type of data much more than the other; 5. Sulfate: Amount of Sulfates dissolved in mg/L.
6. Conductivity: Electrical conductivity of water in
μS/cm.
7. Organic_carbon: Amount of organic carbon in
ppm.
Precision: Precision states how many from the predictions 8. Trihalomethanes: Amount of Trihalomethanes in
as safe were actually safe. This helps to know the number μg/L.
of false positives the model is generating. 9. Turbidity: Measure of light emitting property of
water in NTU.
Recall: Recall is the percentage of actual 'safe' samples 10. Potability: Indicates if water is safe for human
that were identified correctly. It's effective when ignoring consumption. Potable -1 and Not potable -0
the positive cases is dangerous.

F1Score: The F1 score is an average of precision and


recall. It is the best measure to use when you care about
both types of mistakes equally.

ConfusionMatrix: The confusion matrix is a summary of


the model's predictions, and it includes true positives, false
positives, true negatives, and false negatives.
Figure 1: Potability Distribution Indicator

XIII GRAPHICAL REPRESENTATIONS

A) Confusion Matrix
Figure 3: Correlation Curve
The matrix indicates that out of 1000 predictions made,
897 were correct classifications of water quality,
showcasing the robustness of the applied methodologies.

Figure 4: Water Turbidity

XIV RESULTS AND DISCUSSION


Figure 2 : Confusion Matrix
The successful performance of these models clearly
indicates that artificial intelligence could be of great help
in the case of water quality assessment. Predictions that
are on point are the first step in the right direction for
immediate interventions to be taken, which in turn not
only save water but also save manpower and minimize
public health risks. The capability to recognize
contamination patterns can trigger early actions in the
context of water management, and as a result, there will be
Accuracy Precision Recall F1-
Models (macro (macro Score
avg) avg) (macro
avg)
Random 0.64 0.60 0.56 0.55
Forest
XGBoost 0.64 0.60 0.58 0.58
SVM ( 0.6325 0.60 0.58 0.58
LightGB 0.62875 0.59 0.57 0.57
M
a plethora of positive outcomes achieved for community XVI CONCLUSION
health and the environment. Not only that, but also
integrating various kinds of data such as real-time The investigation discloses the real-life implementation of
monitoring information has been extremely beneficial Artificial Intelligence (AI) in predicting water
when it comes to gaining a deep insight into water quality contamination using physicochemical parameters. With
changes. The methods used demonstrate potential for the help of various algorithms like Random Forest,
suburban environmental monitoring systems with wide XGBoost, and Support Vector Machine (SVM) from the
application capability and ensuring the continuous machine learning domain, we created the models that can
assessment of water safety standards. forecast the water quality. The Random Forest model
emerged as the best performer with a 63.5% accuracy rate,
XV FUTURE DIRECTIONS meaning that it is still somewhat more efficient compared
to the others in the case of this area.
The study is a testament to how machine learning models
can be used in the prediction of water pollution levels by This investigation indicates that the utilization of AI in the
the use of key water quality parameters. Although the analysis of the multi-parameter water quality data for the
models (Random Forest, XGBoost, and SVM) gave purpose of early detection of the pollution is very
encouraging outcomes, especially after they were fine- important and it also deals with the data imbalance issue
tuned, they are still open to further improvement. and still, after making the models checkable through some
areas, their accuracy remains only decent. The new
Initial among possible ways in the future is the better research agenda aims to enhance and diversify the data via
quality and variety of datasets. For example, some data the dataset enrichment process, the addition of more
points were missing or had inconsistencies, thus increasing relevant features for the right set of hybrid models in the
the dataset and ensuring standardized data collection pursuit of ideal predictive performance.
methods might be the way to go should the aim be to
achieve better reliability of the model. As a result, running While the project has not disclosed the Internet of Things
these models on data that have never been seen in real-life (IoT), the other studies on the other hand, the use of real-
scenarios from different places will also go a long way in time data acquisition systems in the integration of the
proving that they are indeed stable and can be applied monitoring systems, could be a possible future direction
broadly. Sorting out more elaborate or hybrid models that which will enable round the clock monitoring and timely
pull strengths from various algorithms to attain a higher interventions. In this case, the scientific paper offers a way
level of prediction is no less important. The integration of for the application of AI in the domain of water quality
climate or seasonal data is also a good option to improve monitoring systems by intending to protect the public from
the performance of the models when there is a change in the diseases that are caused by water pollution and to keep
the environmental conditions. the environment green.
Despaite lacking IoT devices in this research, the XVII REFERENCES
upcoming studies can suggest giving a thought to
matching the concepts of monitoring of real-time systems
and already in place data collection with this.
1. Xie, Y., Chen, L., & Zhang, J. (2020).
Overall, this work provides a foundation for using AI in "Application of Support Vector Machines for
water quality monitoring and encourages future research to Water Quality Prediction in Freshwater Bodies."
build more dynamic and scalable systems for Environmental Monitoring and Assessment, vol.
environmental safety. 192, no. 12, pp. 1-12, doi:10.1007/s10661-020-
08458-3.

2. Liang, Y., Wang, Q., & Liu, S. (2021).


"Forecasting Water Pollution Trends Using
Artificial Neural Networks." Journal of
Environmental Management, vol. 281, article
111845, doi:10.1016/[Link].2020.111845.

3. Breiman, L. (2001). "Random Forests." Machine


Learning, vol. 45, no. 1, pp. 5-32,
doi:10.1023/A:1010933404324.

4. Farag, A., & Sweeney, J. (2019). "Decision Trees


for Water Quality Assessment and Management."
Journal of Water and Health, vol. 17, no. 4, pp.
567-577, doi:10.2166/wh.2019.086.

5. Zhang, L., & Wang, G. (2022). "Deep Learning


Techniques for Water Quality Assessment: A
Review." Environmental Science and Pollution
Research, vol. 29, no. 23, pp. 33822-33836,
doi:10.1007/s11356-022-18879-4.

6. Kurgan, L. A., & Musilek, P. (2006). "A Survey


of Knowledge Discovery and Data Mining
Processes." IEEE Transactions on Systems, Man,
and Cybernetics, vol. 36, no. 6, pp. 764-773,
doi:10.1109/TSMCA.2006.1704503.

7. Oreszczyn, T., & Twigg, J. (2020). "Emerging


Trends in Water Quality Monitoring Using AI."
Sensors, vol. 20, no. 4, p. 1111,
doi:10.3390/s20041111.

8. Ren, J., & Susan, Q. (2023). "Real-Time Water


Quality Monitoring Systems: Integrating IoT and
AI Technologies." Journal of Environmental
Protection, vol. 14, pp. 1103-1115,
doi:10.4236/jep.2023.146068.

9. Pasha, M.F., & Mhani, H. (2021). "A


Comprehensive Review of Machine Learning
Applications in Hydroinformatics." Water, vol.
13, no. 11, pp. 1590, doi:10.3390/w13111590.

10. Khan, M.A., et al. (2022). "Baseline Water


Quality Assessment and Prediction Using Neural
Networks." Water Resources Management, vol.
36, pp. 213-229, doi:10.1007/s11269-021-02934-
5.

Common questions

Powered by AI

Python libraries facilitate the implementation of machine learning models by offering tools for data management, preprocessing, modeling, and evaluation. Libraries like Pandas and NumPy handle data organization, while Matplotlib and Seaborn assist in visual exploration of data patterns . Scikit-learn provides modules for training and tuning models, and XGBoost enhances predictive performance, making Python an indispensable tool . The final deployment of models is supported by the Pickle package for model serialization .

Future improvements for AI-based water quality models could include dataset enrichment to cover more diverse and comprehensive variables, improving data quality through standardized collection, and integrating climate data for better adaptability to environmental changes . Hybrid model development that combines strengths from multiple algorithms may also improve predictions . Incorporating real-time monitoring capabilities with IoT can further refine predictions and responsiveness .

AI models such as SVM, Random Forest, and XGBoost play a crucial role in forecasting water pollution by utilizing machine learning to identify and predict contamination patterns based on physiochemical parameters . They facilitate timely intervention by enabling accurate assessments of water safety, thus aiding in public health protection . These models support continuous monitoring and can potentially integrate with real-time systems for immediate actions .

Integrating IoT with AI models can improve water quality monitoring by allowing real-time data acquisition and analysis, facilitating continuous monitoring and timely intervention . IoT devices can provide up-to-the-minute environmental data, enhancing model predictions by using the latest and most relevant data . This integration supports dynamic systems that can adapt to changes quickly, ensuring up-to-date water safety assessments .

Accuracy scores give a general assessment of a model's predictive capacity by indicating the proportion of correct predictions . Precision assesses how many predicted safe waters were actually safe, while recall measures how well the model identifies safe samples, both critical when managing false predictions . The F1 score provides a balanced view by averaging precision and recall, especially important when both error types are critical . These metrics together provide a comprehensive evaluation of model performance .

Enhancing dataset variety and quality leads to improved model reliability by providing diverse examples that help in better generalizing predictions across different contexts . It addresses the inconsistencies and gaps in data, which can compromise the accuracy of predictive models . Rich datasets enable the understanding of a broader spectrum of pollution patterns, making models more robust and applicable to varied real-world scenarios .

Confusion matrices provide detailed insights into the performance of machine learning models by displaying the counts of true positives, false positives, true negatives, and false negatives . This aids in understanding how well the model distinguishes between the safe and unsafe water samples, highlighting areas where the model excels or needs improvement . They are crucial in evaluating model accuracy and the reliability of safety predictions in water quality assessments .

LightGBM offers advantages such as speed and effectiveness, particularly with large datasets, making it fast and reliable even with big data . It demonstrated prominent results in handling structured data, making it suitable for water quality assessments . Despite SVM outperforming it after tuning, LightGBM was noteworthy for its operational speed and precision .

Data preprocessing significantly impacts prediction performance by cleaning raw data, which includes replacing missing values and normalizing continuous variables to maintain uniformity among scales . It removes multicollinearity through correlation analysis, ensuring relevant features are used in the models . These steps enhance the quality and reliability of the inputs, leading to more accurate predictions in water quality assessment .

SVM was chosen for deployment due to its balanced precision and recall which made it suitable for the specific requirements of maintaining balance between false positives and negatives . It integrates well with web applications like Flask, adding to its practical deployment advantages . Despite having slightly lower accuracy compared to Random Forest, its overall balanced performance and ease of integration were decisive factors .

You might also like