A comprehensive end-to-end fraud detection system using machine learning, featuring 10 models, explainability analysis, and a production-ready API.
fraud_detection/
├── config.py # Configuration settings
├── eda.py # Exploratory Data Analysis
├── preprocessing.py # Feature engineering & splitting
├── train_all.py # Model training pipeline
├── evaluation.py # Comprehensive evaluation
├── explainability.py # SHAP & LIME analysis
├── error_analysis.py # FN/FP & drift analysis
├── ae_model.py # Autoencoder model classes
├── architecture.py # Architecture diagram generator
├── generate_pdf.py # PDF paper generator
├── requirements.txt # Python dependencies
├── api/
│ └── app.py # FastAPI production endpoint
├── models/
│ ├── all_models.joblib # All trained models
│ ├── all_models_with_ae.joblib
│ ├── autoencoder.pt # PyTorch autoencoder weights
│ ├── scaler.joblib # Fitted RobustScaler
│ └── tuning_results.joblib # Optuna best params
├── figures/ # All figures (PNG + PDF, 300 DPI)
│ ├── class_distribution.*
│ ├── amount_analysis.*
│ ├── time_analysis.*
│ ├── correlation_heatmap.*
│ ├── feature_distributions.*
│ ├── roc_curves.*
│ ├── pr_curves.*
│ ├── confusion_matrices.*
│ ├── threshold_analysis.*
│ ├── feature_importance.*
│ ├── shap_summary.*
│ ├── shap_top10.*
│ ├── lime_explanation.*
│ ├── error_analysis.*
│ ├── architecture_diagram.*
│ ├── model_comparison.csv
│ ├── business_impact.csv
│ └── shap_feature_importance.csv
├── paper/
│ ├── fraud_detection_paper.tex # IEEE LaTeX source
│ └── fraud_detection_paper.pdf # Compiled PDF
└── data/
├── creditcard.csv # Raw dataset
├── processed_data.joblib # Preprocessed data
└── evaluation_results.joblib # Evaluation results
1# 1. EDA
2python eda.py
3
4# 2. Preprocessing
5python preprocessing.py
6
7# 3. Training
8python train_all.py
9
10# 4. Evaluation
11python evaluation.py
12
13# 5. Explainability
14python explainability.py
15
16# 6. Error Analysis
17python error_analysis.py
1cd fraud_detection
2uvicorn api.app:app --host 0.0.0.0 --port 8000
1curl -X POST http://localhost:8000/predict \
2 -H "Content-Type: application/json" \
3 -d '{
4 "Time": 406.0,
5 "V1": -2.312, "V2": 1.951, "V3": -1.609, "V4": 3.997,
6 "V5": -0.522, "V6": -1.426, "V7": -2.537, "V8": 1.391,
7 "V9": -2.770, "V10": -2.772, "V11": 3.202, "V12": -2.899,
8 "V13": -0.595, "V14": -4.289, "V15": 0.389, "V16": -1.140,
9 "V17": -2.830, "V18": -0.016, "V19": 0.416, "V20": 0.126,
10 "V21": 0.517, "V22": -0.035, "V23": -0.465, "V24": -0.018,
11 "V25": -0.010, "V26": -0.002, "V27": -0.154, "V28": -0.048,
12 "Amount": 239.93
13 }'
1{
2 "transaction_id": "TXN-1714297654321",
3 "fraud_probability": 0.999943,
4 "decision": "BLOCKED - SUSPECTED FRAUD",
5 "risk_level": "CRITICAL",
6 "top_risk_factors": [...],
7 "response_time_ms": 5.62,
8 "threshold_used": 0.55,
9 "model_used": "XGBoost (Optimized)"
10}
European Cardholder Credit Card Fraud Detection — 284,807 transactions with 492 fraud cases (0.173%).