1
AMERICAN INTERNATIONAL UNIVERSITY- BANGLADESH
(AIUB)
Faculty of Science and Technology
Department of Computer Science and Engineering
FINAL TERM PROJECT REPORT
PROGRAMMING IN PYTHON
Project Name: Water Quality Prediction by using
Classification Models.
Submitted to:
Dr. Akinul Islam Jony Semester: Spring 2022-23
Associate Professor
Section: B
Date of Submission: 3/05/2023
Faculty of Science & Technology
Department of CSE
Submitted By
No Name ID
1 Anika Saba Ibte Sum 20-43242-1
2 Oishi Singh 20-43067-1
3 Mehadi Hasan Shojib 20-42713-1
4 Anik Debnath 20-42780-1
2
Table of Contents
Section 1: Project Overview………………………………………………………………………. 3
Section 2: Dataset Overview……………………………………………………………………... 3-4
Section 3: Data Preprocessing and Exploratory Data Analysis……………………………… 4-19
Section 4: Model Development………………………………………………………………… 19-21
Section 5: Discussion and Conclusion……………………………………………………………. 22
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
3
Section 1: Project Overview
Water quality refers to the characteristics of water that determine its suitability for specific uses, such as
drinking, irrigation, industrial processes, and aquatic life. It is determined by the physical, chemical,
biological, and radiological properties of water, and the presence or absence of contaminants, such as
bacteria, viruses, organic and inorganic compounds, and toxic substances. Access to safe drinking-water
is essential to health, a basic human right and a component of effective policy for health protection. This
is important as a health and development issue at a national, regional, and local level. In some regions, it
has been shown that investments in water supply and sanitation can yield a net economic benefit, since
the reductions in adverse health effects and health care costs outweigh the costs of undertaking the
interventions.
Recently, machine learning techniques have been used for predicting water quality, as it is more accurate
than models based on physical principles. To address various problems, varieties of machine learning
algorithms are applied in different fields. In this project, to examine how accurately these models predict
water quality. It is carried out to compare these models so that it can be realized which model works
better. In this project, a set of the most common machine learning techniques are explored to generate
robust water potability model for long periods of time. Moreover, the combinations of all the model
parameters are considered for simulations. The experimental results of the classifiers show which
classifier model gives better classification accuracy. In this project NumPy, pandas, matplotlib, seaborn,
scikit learn libraries are used. Data preprocessing and Exploratory data analysis is presented to justify the
project as a more accurate one. After data analysis unnecessary variables were removed. Then the dataset
is splitted into training and test set. After that a model is built for each model and test our data. Finally, it
is compared to the accuracy score.
Section 2: Dataset Overview
Data Source: This data set is taken from [Link]. The name of the dataset is Water Quality
Prediction. The art of water quality prediction has been a difficult task for many of the researchers and
analysts. It’s very important to predict water for drinking safely. So, we decided to predict water quality
using data set which is downloaded from Kaggle to train our model and evaluate by testing using 10
attributes. We are going to predict 2 types of water potability conditions (potable or not potable). This is a
copy of Water Quality prediction dataset: Water Quality | Kaggle Dataset Link:
url: [Link]
Description of Dataset:
We have used a dataset about weather information from Kaggle to train our model and evaluate by
testing.
Number of Instances: 3276
Number of Attributes: 10 numeric predictive.
Attribute Information:
1. pH value: PH is an important parameter in evaluating the acid–base balance of water. It is also an
indicator of acidic or alkaline condition of water status. WHO has recommended maximum permissible
limit of pH from 6.5 to 8.5. The current investigation ranges were 6.52–6.83 which are in the range of
WHO standards.
2. Hardness: Hardness is mainly caused by calcium and magnesium salts. These salts are dissolved from
geologic deposits through which water travels. The length of time water is in contact with hardness
producing material helps determine how much hardness there is in raw water. Hardness was originally
defined as the capacity of water to precipitate soap caused by Calcium and Magnesium.
4
3. Solids (Total dissolved solids - TDS): Water has the ability to dissolve a wide range of inorganic and
some organic minerals or salts such as potassium, calcium, sodium, bicarbonates, chlorides, magnesium,
sulfates etc. These minerals produced un-wanted taste and diluted color in appearance of water. This is an
important parameter for the use of water. The water with high TDS value indicates that water is highly
mineralized. The desirable limit for TDS is 500 mg/l and maximum limit is 1000 mg/l which prescribed
for drinking purposes.
4. Chloramines: Chlorine and chloramine are the major disinfectants used in public water systems.
Chloramines are most commonly formed when ammonia is added to chlorine to treat drinking water.
Chlorine levels up to 4 milligrams per liter (mg/L or 4 parts per million (ppm)) are considered safe in
drinking water.
5. Sulfate: Sulfates are naturally occurring substances that are found in minerals, soil, and rocks. They
are present in ambient air, groundwater, plants, and food. The principal commercial use of sulfate is in the
chemical industry. Sulfate concentration in seawater is about 2,700 milligrams per liter (mg/L). It ranges
from 3 to 30 mg/L in most freshwater supplies, although much higher concentrations (1000 mg/L) are
found in some geographic locations.
6. Conductivity: Pure water is not a good conductor of electric current rather’s a good insulator. Increase
in ions concentration enhances the electrical conductivity of water. Generally, the number of dissolved
solids in water determines the electrical conductivity. Electrical conductivity (EC) actually measures the
ionic process of a solution that enables it to transmit current. According to WHO standards, EC value
should not exceed 400 μS/cm.
7. Organic_carbon: Total Organic Carbon (TOC) in source waters comes from decaying natural organic
matter (NOM) as well as synthetic sources. TOC is a measure of the total amount of carbon in organic
compounds in pure water. According to US EPA < 2 mg/L as TOC in treated / drinking water, and < 4
mg/Lit in source water which is use for treatment.
8. Trihalomethanes: THMs are chemicals which may be found in water treated with chlorine. The
concentration of THMs in drinking water varies according to the level of organic material in the water,
the amount of chlorine required to treat the water, and the temperature of the water that is being treated.
THM levels up to 80 ppm are considered safe in drinking water.
9. Turbidity: The turbidity of water depends on the quantity of solid matter present in the suspended
state. It is a measure of light emitting properties of water and the test is used to indicate the quality of
waste discharge with respect to colloidal matter. The mean turbidity value obtained for Wondo Genet
Campus (0.98 NTU) is lower than the WHO recommended value of 5.00 NTU.
10. Potability: Indicates if water is safe for human consumption where 1 means Potable and 0 means Not
potable.
Section 3: Data Preprocessing and Exploratory Data Analysis
Load dataset:
We upload the dataset into google colab and then we load the dataset from the local drive.
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
5
We check the over all information like how many rows and columns, data type, memory usage and so on.
Data Preprocessing:
Here, we can see that data is missing. For column ph, sulfate and trihalomethanes, they hold missing
values.
6
We are calculating mean values for ph, sulfate, trhalomethanes.
We are replaceing the null values by using the mean values for three columns.
After replacing the missing values, we check again that thre is any null values are here.
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
7
Then, we describe the full dataset where shows that the count, mean, standard deviation, minimum,
quartile values and maximum values.
Data type conversion which is numeric value convert into the catagorical value.
8
Exploratory Data Analysis:
Here we count the value of target attributes which is portability. We can see that most of the value is not
potable value above 1500.
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
9
Here the explanation for the relation between pH and Solids is that higher levels of solids in the water
may affect the pH level. Solids in water can include dissolved minerals and organic matter, and can
impact the water's pH level by affecting the buffering capacity of the water. Therefore, it is possible that
higher levels of solids in the water may lead to higher or lower pH levels.
Here we can see that Sulfate and Hardness is that both attributes may be influenced by the geological
characteristics of the water source. Hardness is a measure of the concentration of dissolved minerals in
the water, particularly calcium and magnesium. Sulfate is also a dissolved mineral that can be present in
water sources, and its concentration can be affected by the same geological factors that influence water
hardness.
10
Here, Sulfate and Chloramines is that the levels of these two chemicals are related to the source of the
water. Both sulfate and chloramines can occur naturally in water sources, and the concentrations of these
chemicals can be influenced by a range of factors, such as the geology of the area, the level of
urbanization, and the sources of pollution.
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
11
12
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
13
14
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
15
From the catplot we can identify how much potability changes for a particular feature of the dataset.
16
From the scatter plot we can identify how much water potability prediction changes for a particular
feature of the dataset.
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
17
18
To predict water potability, it is important to select appropriate features that have a strong relationship
with the target variable and can help the machine learning model make accurate predictions. Based on the
correlation matrix for the water potability dataset, there are no correlated columns in the data.
Create Features Matrix & Target Variable
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
19
Split the dataset.
We have split our data set. We take 20% of data for test dataset and 80% of data for training dataset.
Section 4: Model Development
1. Gaussian Naive Bayes (NB)
20
2. K Nearest Neighbors (KNN)
3. Decision Tree
4. Logistic Regression (LR)
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)
21
5. Support Vector Machine (SVM)
Compare Accuracy Score of Different Models
22
Section 5: Discussion and Conclusion
In this report, we did an analysis of a data set known as the “Water Potability Prediction”. Here, we
developed 5 different classifier models which are Gaussian Naive Bayes, K Nearest Neighbors (KNN),
Decision Tree, Logistic Regression and Support Vector Machine. We can see that the lowest accuracy
model is which accuracy is 0.5518 and the highest accuracy is 0.6021 and 0.6006. The Decision Tree
(DT) and Gaussian Naive Bayes (NB) model gives us the maximum accuracy and K Nearest Neighbors
(KNN) model gives us the lowest accuracy. Logistic Regression (LR) and Support Vector Machine
(SVM) models are given the same accuracy which are 0.5686. As a result, we can say that the Decision
Tree (DT) and Gaussian Naive Bayes (NB) classifier are the best use for this dataset model. The Decision
Tree (DT) and Gaussian Naive Bayes classifier model's accuracy is below 70% because of the dataset. It
might perform better if we can train this model on a larger dataset.
So, in our opinion, depending on this dataset, the Decision Tree (DT) and Gaussian Naive Bayes
classifier is much better for predicting the water potability. Although, for a larger dataset other models
may perform better.
© Dept. of CSE AMERICAN INTERNATIONAL UNIVERSITY-BANGLADESH (AIUB)