Predicting drinking-water potability

BE final-year project · KLS Gogte Institute of Technology · 2021–22 · team of 5

Predicting drinking-water potability

Can nine lab measurements tell safe drinking water from unsafe? This page retrains her classifiers live on the 3,276-sample dataset and shows how they compare with simply guessing the majority class.

Pythonscikit-learnGoogle ColabpandasClassificationJavaScript re-run
-water samples, 9 lab measurements each
-labelled potable (so "always not potable" scores -)
-missing values in pH, sulfate and trihalomethanes
-strongest correlation of any feature with potability

Live demo

Every change re-runs the whole pipeline in your browser: split, impute, cap outliers, standardize, train three models and score them on held-out samples.

Selected model

-test accuracy
-train accuracy
-precision, potableof samples called potable
-recall, potableof truly potable samples

All three models, same split

Test a sample

Enter lab readings (leave a box blank to treat it as missing). The selected model returns its prediction.

Results

Computed from the current run. The dashed line is the majority-class baseline for this test split.

Train vs test accuracy

Correlation with potability (all 3,276 rows)

Decision tree: accuracy as the tree grows deeper

Her original notebook results (constants from the Colab notebook)

Held-out accuracy on a 30% test split of 983 samples, where predicting "not potable" for everything scores 61.1% (601 of 983). The random forest predicted no potable samples at all. Decision tree and random forest scored 100% on their own training data, a clear sign of overfitting.

How it works

  1. Loaded the water quality dataset in Google Colab and profiled it: 3,276 samples, 9 numeric measurements and a 0/1 potability label.
  2. Handled missing values in pH (15%), sulfate (24%) and trihalomethanes (5%) by filling them with the column mean.
  3. Checked each feature for outliers with box plots, the IQR rule and 3-sigma bounds, and capped extreme values at the IQR whiskers.
  4. Standardized the features and split the data into training and test sets.
  5. Trained and tuned eight classifiers with scikit-learn (grid search for the decision tree and k-NN) and compared held-out accuracy, confusion matrices and classification reports.
  6. This page re-implements the pipeline in JavaScript (imputation and scaling fitted on the training split only) so the models can be retrained live.

Data

First 10 rows as stored in water.csv. Blank cells are missing values. Potability: 1 = safe to drink, 0 = not safe.