# A Machine Learning Predictive Model to Detect Water Quality and Pollution
## 4 Methodologies
### Machine Learning Model Developing  
The choice of the machine learning algorithm enables this study to obtain the water quality and pollution situation of a certain place in a timely and accurate manner, and the rapid and accurate prediction of water quality is helpful to water quality regulation to a large extent. In addition, this study uses the data imputation method in combination with the machine learning algorithm to tack the typical data scarcity issue with water sediment datasets, so that our model would assist in precisely assessing water quality based on potentially incomplete real-world data.  
The machine learning models we adopted in this research are Logistic Regression, Naive Bayes, Decision Tree, KNN, SVC, and MLPClassifier. Logistic regression is a linear regression plus a sigmoid function that can convert numeric prediction into categorical outcomes. The Naive Bayes classifier is a classification technique that uses Bayes' Theorem as its underlying theory. It assumes that all the predictors are independent; that is to say, all features are unrelated and do not have any correlation. KNN is the k-nearest neighbour classifier. It calculates the distances between the data entry to be predicted and other data entries, then votes for the most frequent label among k closest number of data entries to predict the label of the target entry (\(k\) is a hyperparameter that needs to be tuned during model training). SVC stands for support vector classifier. There is no required assumption on the shape of features, and no parameters need to be tuned. It generates the 'best fit' hyperplane that divides or categorizes the samples. MLPClassifier is a multi-layer perceptron (MLP) that trains a neural network using a backpropagation algorithm.  
In addition to MLPClassifier, we build a fully connected deep neural network (DNN) and tune the hyperparameters to find a DNN model with the highest predicting accuracy. DNN is an artificial neural network with many hidden layers between its input and output layers. The number of neurons in the input and output layer is the same as the number of data entries and different labels in the dataset. A weighted sum plus a bias is applied toall the neurons in the previous layer. A non-linear function is used to change its linearity. Then the calculated value works as the input value of neurons in the next layer. The weight of each neuron will not be updated through the backpropagation algorithm until the loss function is minimized. Then the latest weight, together with other parameters, form the architecture of the DNN model. Table 1 provides a brief summary of each machine learning models.  
Parameter tuning is the most crucial task during DNN model development. In this project, we use predicting accuracy to examine the efficiency of different parameters. Typical parameters include the number of hidden layers, the number of neurons in each layer, the activation function, the dropout rate, the batch normalization, the epoch, and the gradient descent method. We first tune the number of hidden layers and then use the best number of hidden layers to tune the number of neurons in each layer. Then, we tune the dropout rate and evaluate batch normalization's effectiveness.  
Logistic regression is one of the straightforward and easy-to-interpret algorithms in machine learning, so it is used as the benchmark model in our comparison. Prediction accuracy and F1-score will be compared between those models. Details of machine learning model accuracy evaluation methods will be discussed in the subsequent section.