AI Fraud Detection System

Python

Real-time transaction fraud detection system with ML pipeline, REST API, and Cloudflare Workers deployment

Tech Stack

Python 3.12
FastAPI
Scikit-learn
XGBoost
PostgreSQL
Docker
Cloudflare Workers

Features

Real-time fraud prediction with <100ms latency
Gradient Boosting model with 98%+ accuracy
Feature engineering pipeline
RESTful API with OpenAPI docs
Docker containerization
Comprehensive test suite

Code Sample

predict.py
from fastapi import FastAPI
from pydantic import BaseModel
import joblib

app = FastAPI()
model = joblib.load("models/fraud_model.pkl")

class Transaction(BaseModel):
    amount: float
    merchant_id: str
    merchant_category: str

@app.post("/predict")
async def predict_fraud(tx: Transaction):
    features = extract_features(tx)
    prediction = model.predict_proba([features])
    return {
        "fraud_probability": float(prediction[0][1]),
        "is_fraud": bool(prediction[0][1] > 0.5),
        "risk_level": "high" if prediction[0][1] > 0.8 else "low"
    }
View Source Docker Hub Live Demo