Machine learning system that detects electricity theft from smart-meter consumption data to support revenue protection and grid reliability, with a focus on Rwanda's power network.
# ⚡ Electricity Theft Detection System
A machine-learning system that flags suspicious electricity-consumption patterns from smart-meter data, framed as a **grid-reliability** problem — built with Rwanda's power network in mind.
**🔗 Live demo:**
electricity-theft-detection…
---
## The problem
Electricity theft (non-technical loss) is unmetered consumption: power flows from the grid, but the utility never records or bills it. Beyond lost revenue, this is an engineering problem. Unmetered load is **hidden demand** the system operator cannot see, which distorts demand forecasting, overloads transformers and distribution lines, increases technical losses, and — when hidden demand climbs unnoticed — adds stress that can push a strained grid toward instability or load shedding.
This project detects theft early so a utility (such as Rwanda Energy Group and its subsidiaries) can protect revenue **and** improve grid reliability.
## Dataset
The SGCC dataset released by the State Grid Corporation of China: **42,372 customers**, **1,035 days** of daily kWh readings (Jan 2014 – Oct 2016). It is realistically hard — about **8.5%** of customers are thieves (heavy class imbalance) and roughly **25%** of readings are missing.
## Approach
1. **Cleaning** — missing daily readings are reconstructed per customer by interpolation, with any remaining gaps filled with zero.
2. **Feature engineering** — each customer's 1,034 daily readings are compressed into 15 interpretable behavioural features (mean, variability, zero-day ratio, low-usage ratio, coefficient of variation, skew, biggest single-day drop, etc.), each grounded in real power-system reasoning.
3. **Modelling** — a Random Forest baseline exposed the imbalance trap (91% accuracy while catching only 5% of thieves); class weighting alone was insufficient; the final model is **XGBoost with `scale_pos_weight`** to handle the imbalance.
4. **Honest evaluation** — because the …