Skip to content

Repository files navigation

Water Potability Prediction - ML Classification Pipeline

Predicts whether a water sample is safe for drinking using supervised machine learning, comparing a baseline Logistic Regression model against a tuned Random Forest classifier across 9 physicochemical water quality indicators.

Business Context

Safe drinking water classification is a high-stakes decision problem — false negatives (labeling unsafe water as drinkable) carry serious public health consequences. This project mirrors real-world predictive modeling challenges: class imbalance, missing data, and the tradeoff between precision and recall.

Dataset

  • Source: Kaggle — Water Potability
  • 3,276 rows | 9 features | Binary target (Potability: 0 = not drinkable, 1 = drinkable)
  • Features: pH, Hardness, Solids, Chloramines, Sulfate, Conductivity, Organic Carbon, Trihalomethanes, Turbidity

Pipeline

1. EDA & Data Preparation

  • Explored distributions, correlations, and class balance
  • Imputed missing values (ph: 491, Sulfate: 781, Trihalomethanes: 162) using median — chosen over mean due to outlier sensitivity
  • Stratified 80/20 train-test split
  • Standardized features using StandardScaler

2. Baseline Model — Logistic Regression

  • Established performance floor for classification benchmarking

3. Strong Classifier — Random Forest

  • 100 estimators, evaluated against baseline
  • Demonstrated ensemble advantage over logistic regression

4. Hyperparameter Tuning — GridSearchCV

  • Parameters tuned: n_estimators=500, max_depth=10, min_samples_split=[5,10], class_weight='balanced'
  • 5-fold cross-validation, scored on F1

Results

Model Accuracy F1 Score ROC-AUC
Logistic Regression ~60% baseline baseline
Random Forest (base) ~66% +↑ +↑
Tuned Random Forest ~67% best best

(Update with your actual output numbers before sharing)

Evaluation Metrics

  • Accuracy, Precision, Recall, F1 Score, ROC-AUC
  • ROC curves and confusion matrices for all 3 models
  • Bar + line graph comparison across all three models

Tech Stack

  • Python, Pandas, NumPy, Scikit-learn
  • Matplotlib, Seaborn
  • Google Colab / Jupyter Notebook

Files

File Description
BSAN_734_Final_Project_HA.ipynb Full pipeline: EDA → modeling → evaluation
water_potability.csv Source dataset

About

ML classification pipeline predicting drinking water safety across 3,276 samples - compares Logistic Regression, Random Forest, and tuned RF (GridSearchCV) on 9 physicochemical features with class imbalance handling and missing value imputation.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages