ZeniTsuIsSimP/Water-Contamination-Detection
0
๐ง Smart Water Contamination Detection
AI-powered water quality monitoring system using IoT sensor data, Machine Learning, Docker, and CI/CD โ built with a professional MLOps pipeline.
๐ Live Project
- Hugging Face Spaces: https://huggingface.co/spaces/ZeniTsuisSimp/Water-Contamination-Detection
๐๏ธ Project Structure
โโโ app/ # Streamlit web application
โ โโโ main.py
โโโ src/ # ML pipeline source code
โ โโโ data_preprocessing.py # Data loading, imputation, splitting
โ โโโ train.py # Model training + MLflow logging
โ โโโ evaluate.py # Evaluation + report generation
โ โโโ predict.py # Prediction + anomaly detection
โโโ data/
โ โโโ raw/ # Original, unprocessed CSVs
โ โโโ processed/ # Classified & cleaned datasets
โโโ notebooks/
โ โโโ model_training.ipynb # Exploratory notebook (EDA + training)
โโโ tests/
โ โโโ validate_model.py # CI model validation test
โโโ reports/ # Auto-generated metrics, plots
โโโ mlruns/ # MLflow experiment tracking data
โโโ params.yaml # Centralized hyperparameters & config
โโโ dvc.yaml # DVC pipeline definition
โโโ Dockerfile # Docker containerization
โโโ docker-compose.yml # Docker Compose for local dev
โโโ requirements.txt # Python dependencies
โโโ .github/workflows/
โโโ ci-cd.yml # GitHub Actions CI/CD pipeline๐ Quick Start
1. Setup
# Clone the repository
git clone <repo-url>
cd Water-Contamination-Detection
# Create virtual environment
python -m venv venv
venv\Scripts\activate # Windows
# source venv/bin/activate # Linux/Mac
# Install dependencies
pip install -r requirements.txt2. Train the Model
python -m src.trainThis trains the model, logs to MLflow, and saves water_model.pkl.
3. Evaluate
python -m src.evaluateGenerates classification reports and confusion matrix plots in reports/.
4. Run the App
streamlit run app/main.pyOpen http://localhost:8501 in your browser.
5. Run with Docker
docker-compose up --build๐ฌ ML Pipeline
DVC Pipeline
dvc repro # Run full pipeline
dvc status # Check if pipeline is up-to-date
dvc dag # Visualize pipeline DAGMLflow
mlflow ui # Open experiment tracker at http://localhost:5000๐ง Configuration
All hyperparameters and thresholds are in `params.yaml`:
- Data paths โ raw/processed data locations
- Feature names โ pH, Solids (TDS)
- Model hyperparameters โ RF trees
- Anomaly thresholds โ critical pH/TDS limits
๐ง Hybrid Prediction Logic
- Rule-Based Safety Check โ Catches critical anomalies (pH < 4 or > 10, TDS > 3000)
- ML Model โ Random Forest predicts potability for non-critical inputs
- Confidence Smoothing โ Prevents unrealistic 100%/0% probabilities
๐ข CI/CD Pipeline
๐ Tech Stack
- ML: scikit-learn (Random Forest)
- App: Streamlit + Altair charts
- Experiment Tracking: MLflow
- Data Versioning: DVC
- Containerization: Docker
- CI/CD: GitHub Actions โ Hugging Face Spaces
