The Project explores Tree-Based Models and Gradient Boosting for detecting mobile money transaction transaction fraud
# M-Pesa Transaction Fraud Detection Engine
This project simulates the M-Pesa architecture (Send Money, Buy Goods/Till, Paybill) and uses an advanced Stochastic Gradient Boosting model to calculate fraud probability instantly based on user behavior, transaction math anomalies, and temporal patterns.
# Key Features
1. Interactive Streamlit UI: A fully dynamic frontend that mimics the native M-Pesa USSD/App flow with progressive input fields.
2. Real-Time ML Inference: Predicts fraud probability in milliseconds using a serialized scikit-learn pipeline.
3. Advanced Feature Engineering:
* Calculates delta_mismatch to catch simulated database math glitches (where balance deductions don't match sent amounts).
* Temporal cyclical encoding (hour_sin, day_cos) to capture time-based fraud rings.
* Ratio calculations (Transaction Amount vs. Total Wallet Balance).
* Threshold Tuning: Implements custom probability thresholds to prioritize Recall (catching more fraud) over raw accuracy in heavily imbalanced datasets.
* Native Receipt Generation: Simulates standard dual-party (Sender/Receiver) SMS confirmation receipts.
# Machine Learning Architecture
We evaluated multiple ensemble methods including Random Forest, XGBoost, Bagging, AdaBoost, and Voting Classifiers. The champion model deployed in this repository is the Stochastic Gradient Boosting Classifier (HistGradientBoostingClassifier), chosen for its blazing fast inference speed and high F1-Score on imbalanced tabular data.
# Feature Importance Highlights
The model heavily relies on our custom-engineered features rather than just raw amounts. Top predictors include:
* delta_mismatch_abs: Discrepancies in ledger math.
* amount_to_sender_before_ratio: Transactions that drain >90% of a wallet.
* receiver_balance_after: Identification of high-volume "mule" accounts.