Real-time credit card fraud detection system using XGBoost. Catches 72% of fraudulent transactions with 50.5% precision.
Fraud Detection API: https://fraud-detection-api-231m.onrender.com
Live Demo: https://fraud-detection-api.streamlit.app
- 72.0% recall - Catches 2,976 out of 4,133 fraud attempts in validation
- 50.5% precision - 2,918 false alarms per 118,108 transactions
- F1 Score: 0.594 - Balanced for production use
- Threshold: 0.5929 - Optimized for precision-recall trade-off
For a typical bank where missed fraud costs 7x more than false positives, this trade-off is acceptable and deployable.
| Metric | Value |
|---|---|
| Recall | 72.0% |
| Precision | 50.5% |
| F1 Score | 0.594 |
| AUC | 0.883 |
| Threshold | 0.5929 |
23 engineered features:
- Frequency encodings (card1, card4, ProductCD, addr1, addr2, card2, card3, email domains)
- Aggregation statistics (mean amount per card1, card2, addr1)
- Transaction amount split (dollars and cents)
- D column count
- Velocity features (time since last transaction)
- Email missing indicators and same domain indicator
339 V columns - Vesta engineered features
- XGBoost for classification
- FastAPI for real-time predictions
- Discord webhooks for alerts
- Streamlit for monitoring dashboard
- Render for deployment
fraud-detection-api/models/ - Trained model files (fraud_detection_final.pkl, product_encoder.pkl, card4_encoder.pkl, feature_columns.pkl, threshold.json)
fraud-detection-api/src/ - FastAPI application
fraud-detection-api/dashboard/ - Streamlit dashboard
fraud-detection-api/tests/ - Unit tests
fraud-detection-api/requirements.txt - Python dependencies
fraud-detection-api/README.md - Documentation
Clone the repository:
git clone https://github.com/YOUR_USERNAME/fraud-detection-api.git
cd fraud-detection-api
Install dependencies:
pip install -r requirements.txt
Run the API:
uvicorn src.app:app --reload
Test the API:
curl -X POST http://localhost:8000/predict -H "Content-Type: application/json" -d '{"TransactionID": 999002, "ProductCD": "C", "card1": 2755, "card4": "discover", "TransactionAmt": 8900.00, "addr1": 476, "addr2": 87, "TransactionDT": 86400}'
Expected response:
{"TransactionID": 999002, "fraud_prediction": 0, "fraud_probability": 0.3192, "threshold": 0.5929, "alert_sent": false}
The model was trained on the IEEE-CIS Fraud Detection dataset with 590,540 transactions, 3.5% fraud rate, and 394 raw columns.
Training steps:
- Exploratory analysis of raw features
- Feature engineering (23 derived features)
- Hyperparameter tuning (max_depth grid search from 3 to 13)
- XGBoost with scale_pos_weight=28 for class imbalance
- Threshold optimization to 0.5929 achieving 72% recall and 50.5% precision
Training notebook available on Kaggle.
- Add SHAP explanations for model interpretability
- Implement human-in-the-loop review queue
- Add A/B testing framework for model comparisons
- Real-time feature store with Redis
- MLflow for experiment tracking
- Add more aggregation features (email domain, address velocity)
Tran Bao Quan - Data Science Graduate (2026)
MIT