# FraudGuard — AI-Powered M-Pesa Fraud Detection System
> A real-time intelligent fraud detection platform designed to protect M-Pesa users from mobile money fraud, built with Python, Flask, and a trained Random Forest machine learning model.
---
## Overview
The system analyses every M-Pesa transaction in real time using a hybrid detection approach that combines machine learning, rule-based logic, and explainable AI to classify transactions as Low, Medium, or High risk — and takes immediate action before fraud occurs.
---
## Key Features
- **Real-time AI fraud scoring** using a trained Random Forest classifier
- **3-tier risk classification** — Low, Medium, and High risk
- **Explainable AI** — every decision comes with a plain-English explanation
- **Email OTP verification** for medium-risk transactions
- **Instant block and email alert** for high-risk transactions
- **Live risk preview** — see the AI working as you type
- **Admin intelligence dashboard** with fraud statistics, charts, and manual override
- **Simulation mode** — one-click demo scenarios for presentations
- **Secure authentication** with hashed PINs and Flask-Login
---
## System Architecture
The system uses a three-layer hybrid detection engine:
**Input** → Flask REST API → **Hybrid Detection Engine** → **Decision Engine** → **Action**
The Hybrid Detection Engine combines three components:
- **ML Scoring Engine** — Random Forest model analyses transaction type, amount, and hour
- **Rule-Based Engine** — Expert banking rules applied on top of the ML score
- **Risk Score** — Combined output classified as LOW, MEDIUM, or HIGH
**Actions taken:**
| Risk Level | Action |
|------------|--------|
| 🟢 LOW | Transaction approved instantly |
| 🟡 MEDIUM | OTP email sent — user must verify |
| 🔴 HIGH | Transaction blocked + security alert email sent |
## Model Performance
The Random Forest model was trained on the PaySim dataset containing 209,715 transactions.
| Metric | Score |
|----------- …