Predictive maintenance for water pump failure detection in Tanzania — RF, XGBoost, LightGBM
# 💧 Pump It Up — Predicting Water Pump Failures in Tanzania
End-to-end machine learning pipeline for the DrivenData "Pump It Up" competition. Multi-class classification to predict the operational status of water pumps across Tanzania — a real-world social impact problem affecting millions of people's access to clean water.
---
## Problem
Predict whether a water pump is **functional**, **needs repair**, or **non-functional** based on ~40 features including location, construction details, water source, and management information. The dataset contains **59,400 water points** across Tanzania.
| Label | Description | Distribution |
|-------|-------------|-------------|
| âś… `functional` | Pump is operational | ~54% |
| ⚠️ `functional needs repair` | Works but needs maintenance | ~7% |
| ❌ `non functional` | Pump is broken | ~39% |
---
## Results
| Model | Accuracy | Macro F1 | Notes |
|-------|----------|----------|-------|
| Random Forest | ~80% | ~0.73 | `n_estimators=100`, `max_depth=20`, `class_weight='balanced'` |
| XGBoost | ~81% | ~0.75 | `n_estimators=200`, `max_depth=8`, early stopping |
| **LightGBM** | **~82%** | **~0.76** | `n_estimators=500`, `learning_rate=0.05`, `num_leaves=63` |
Results on validation set (80/20 stratified split).
---
## Pipeline
```
Raw Data → EDA → Preprocessing → Feature Engineering → Model Training → Evaluation → Prediction
```
### 1. Exploratory Data Analysis
- Target distribution analysis (class imbalance: 7:1 ratio for `needs repair`)
- Categorical variable analysis with cross-tabulation against target
- Numerical variable distributions with box plots by pump status
- Geographical visualization of 59K water points across Tanzania
### 2. Preprocessing
- **Missing values:** Median imputation for numerical, mode for categorical, special handling for zero-encoded missing values (construction_year, gps_height, population)
- **Encoding:** LabelEncoder fitted on combined train+test to ensure consistent mappings
- **Scali …