Access to clean and safe drinking water is one of the most critical public health requirements worldwide. Water quality is determined by multiple physicochemical properties, making manual assessment time-consuming and resource-intensive.
This project leverages Machine Learning techniques to predict whether water is safe for human consumption (Potable) based on various water quality parameters.
The project includes:
- Exploratory Data Analysis (EDA)
- Data Cleaning and Missing Value Handling
- Feature Scaling and Standardization
- Class Imbalance Handling using SMOTE
- Machine Learning Model Training
- Performance Evaluation and Comparison
- Feature Importance Analysis
- Visualization and Insights
The primary objectives of this project are:
- Analyze water quality data and identify important patterns.
- Handle missing values and data inconsistencies.
- Address class imbalance issues using SMOTE.
- Train multiple machine learning models.
- Compare model performance using multiple evaluation metrics.
- Identify the most influential factors affecting water potability.
- Build a reliable predictive system for water quality assessment.
The project uses the Water Potability Dataset containing various water quality measurements.
| Feature | Description |
|---|---|
| pH | pH value of water |
| Hardness | Water hardness level |
| Solids | Total dissolved solids |
| Chloramines | Chloramine concentration |
| Sulfate | Sulfate concentration |
| Conductivity | Electrical conductivity |
| Organic_carbon | Organic carbon concentration |
| Trihalomethanes | THM concentration |
| Turbidity | Water turbidity |
| Potability | Target Variable (0 = Not Potable, 1 = Potable) |
| Value | Meaning |
|---|---|
| 0 | Non-Potable Water |
| 1 | Potable Water |
Several exploratory techniques were applied:
- Dataset structure inspection
- Missing value analysis
- Statistical summary generation
- Distribution visualization
- Correlation analysis
- Boxplot analysis
- Target class distribution analysis
- Feature Distributions
- Correlation Heatmap
- Class Distribution
- Boxplots
- ROC Curves
- Confusion Matrices
- Feature Importance Charts
Missing values were handled using:
df.fillna(df.mean(), inplace=True)Mean imputation was applied to preserve dataset size and avoid unnecessary data loss.
The dataset was standardized using:
StandardScaler()This ensures that all features contribute equally to model training.
The dataset contains class imbalance between potable and non-potable samples.
To address this issue:
SMOTE (Synthetic Minority Oversampling Technique)was applied to generate synthetic samples for the minority class.
A simple yet effective linear classification algorithm used as a baseline model.
Advantages:
- Fast training
- Highly interpretable
- Good baseline performance
An ensemble learning method that combines multiple decision trees.
Advantages:
- Handles nonlinear relationships
- Robust against overfitting
- Provides feature importance
An advanced gradient boosting algorithm known for superior predictive performance.
Advantages:
- High accuracy
- Efficient learning
- Excellent handling of complex datasets
Models were evaluated using:
Measures overall prediction correctness.
Measures the proportion of positive predictions that are actually correct.
Measures the ability to correctly identify potable water samples.
Harmonic mean of Precision and Recall.
Measures model discrimination capability.
The following metrics are compared across all models:
- Accuracy
- Precision
- Recall
- F1-Score
- ROC-AUC
Performance visualizations include:
- Metric Comparison Graphs
- ROC Curves
- Confusion Matrices
Feature importance was extracted from:
- Random Forest
- XGBoost
A combined importance score was computed to identify the most influential water quality parameters.
This helps understand:
- Which features most affect water potability
- How water quality can be monitored more effectively
- Key indicators for water treatment decisions
- Python
- Pandas
- NumPy
- Matplotlib
- Seaborn
- Scikit-Learn
- XGBoost
- Imbalanced-Learn (SMOTE)
- Google Colab
- Jupyter Notebook
Water_Portability_Model/
โ
โโโ Water potability model.ipynb
โโโ water_potability.csv
โโโ Water potability model.py
โโโ README.md
git clone https://github.com/codedbydollys10/Water_Portability_Model.gitpip install pandas numpy matplotlib seaborn scikit-learn xgboost imbalanced-learnOpen:
Water potability model.ipynb
and execute all cells.
This project can be applied in:
Rapid assessment of drinking water quality.
Continuous monitoring and prediction of water safety.
Data-driven analysis of water resources.
Integration into automated water quality monitoring pipelines.
โ Successfully handled missing values
โ Addressed class imbalance using SMOTE
โ Trained multiple machine learning models
โ Compared performance using multiple metrics
โ Identified important water quality parameters
โ Generated actionable insights for water safety assessment
Potential enhancements include:
- Hyperparameter Optimization
- Cross-Validation
- Deep Learning Models
- Deployment as a Web Application
- Real-Time Water Monitoring Integration
- Explainable AI (SHAP/LIME)
Dolly Sharma
GitHub: https://github.com/codedbydollys10
If you found this project useful, consider giving the repository a โญ on GitHub.