Help Tunisian company STEG detect fraud
# STEG Fraud Detection in Electricity and Gas Consumption
This competition is hosted on Zindi, a machine learning platform for data science challenges.
Here is the link to the competition: Fraud Detection in Electricity and Gas Consumption Challenge 🌾 - AI Hack Tunisia
Ranked 6th position (20 continuous hours, only 54 succeed to submit among 191 competitors)!
---
**Competition:** Zindi — Detect fraudulent meter manipulation for Tunisian utility STEG
**Target:** Binary fraud classification (5.6% positive rate)
**Metric:** AUC
**Data:** Client metadata + 15 years of billing history (2005–2019)
## The Problem
STEG lost 200M Tunisian Dinars to fraudulent meter manipulation. Given a client's full billing history (invoices, counter readings, consumption levels), predict which clients are involved in fraud.
The challenge: invoice-level data must be aggregated to client-level features, the fraud rate is heavily imbalanced (5.6%), and categorical variables have inconsistent levels between train/test.
## Architecture
```
00_config.R → Constants, libraries
01_data_loading.R → Load client + invoice CSVs, join, harmonize levels
02_feature_engineering.R → Aggregate invoices → client-level features (consumption, frequency, diffs)
03_encoding_selection.R → Target/WOE/James-Stein encoders + random subset feature selection
04_model_lightgbm.R → 3 LightGBM variants (different seeds/boosters)
05_model_xgboost.R → 4 XGBoost variants (Bayesian-tuned + grid + caret)
06_model_catboost_rf.R → 3 CatBoost + H2O AutoML + Random Forest
07_ensemble.R → Meta-learner blending (elastic net on 14 base predictions)
MAIN.R → Run all steps sequentially
```
## Key Engineering Decisions
### 1. Random Subset Feature Selection (100 × LightGBM)
Instead of traditional forward/backward selection, run 100 iterations where each randomly samples 12–35 features, trains LightGBM, and records AUC. The features appearing in the top-5 performin …