Data-Driven Water Contamination Risk Analysis in Morocco
# 💧 Water Contamination Risk Prediction — Morocco
### Multi-Class Classification | SHAP Explainability | Interactive Risk Map
---
## 📌 Problem Statement
Access to safe water is a fundamental public health challenge in Morocco, particularly in rural and arid regions. Water sources, rivers, springs, wells, and shared taps, face varying contamination levels depending on environmental, geographic, and agricultural factors.
This project builds a machine learning system that predicts the **contamination risk level** of water sources from easily measurable features, enabling:
- 🎯 **Prioritized field inspections** - focus resources on highest-risk sources
- 🏥 **Early public health warnings** - alert communities before contamination spreads
- 🌍 **Regional policy decisions** - identify which regions need infrastructure investment
- 📊 **Data-driven resource allocation** - optimize limited testing budgets
> **Dataset:** Moroccan Water Sources - 100 real samples + 400 rule-based synthetic samples = 500 total
> **Domain:** Environmental ML / Public Health
> **Target:** Contamination risk level - 4 classes: `low` / `medium` / `high` / `very_high`
---
## 📊 Results
| Model | CV F1 Macro | Test Accuracy | Test F1 Macro |
|-------|:---:|:---:|:---:|
| Logistic Regression | 0.4449 | 0.51 | 0.4656 |
| XGBoost | 0.5079 | 0.54 | 0.5238 |
| Gradient Boosting | 0.5355 | 0.62 | 0.5777 |
| Random Forest | 0.5513 | 0.60 | 0.5999 |
| **Random Forest (Tuned)** ✅ | **0.5891** | **0.67** | **0.6570** |
**Best model: Random Forest (Tuned) - 67% accuracy, F1 Macro 0.657 on held-out test set**
### Per-Class Performance (Best Model)
| Risk Class | Precision | Recall | F1 |
|---|:---:|:---:|:---:|
| low | 0.72 | 0.59 | 0.65 |
| medium | 0.61 | 0.81 | 0.70 |
| high | 0.70 | 0.61 | 0.66 |
| very_high | 0.83 | 0.50 | 0.62 |
---
## 📈 Visualizations
---
## 🔍 SHAP Explainability - What Drives Contamination Risk?
| Rank | Feature | Mean SHAP | Interpretation |
|------|---------|:--- …