Credit Card Fraud Detection
End-to-end fraud detection MVP on 284,807 transactions with XGBoost, SHAP explainability, and failure mode analysis.
Key Performance Metrics
Executive abstract
Detecting credit card fraud requires navigating extreme class imbalance (only 473 fraud cases across 283,726 deduplicated transactions). This project develops a production-grade XGBoost pipeline, demonstrates why class weighting outperforms SMOTE, and performs structured failure analysis using SHAP values.
Empirical exhibit
PR-AUC & Precision-Recall Benchmark on 56,746 Test Transactions
| Model Architecture | Decision Cutoff | Precision | Recall | F1 Score | PR-AUC |
|---|---|---|---|---|---|
| Logistic Regression (Baseline) | 0.50 | 0.85 | 0.59 | 0.70 | 0.69 |
| XGBoost (Main Model with Scale Weight) | 0.50 | 0.80 | 0.76 | 0.78 | 0.79 |
| FLAML-Tuned XGBoost (AutoML Ceiling) | 0.2222* | 0.96 | 0.77 | 0.85 | 0.82 |
Transactions hovering directly around the 0.5 decision boundary (probabilities between 0.40 and 0.60). These can be controlled interactively in the Streamlit application to favor recall over precision depending on fraud risk tolerance.
Transactions where anonymized PCA components (V1-V28) completely overlap with legitimate spending distributions. Cannot be fixed by threshold tuning alone; requires raw behavioral transaction metadata.
Class Imbalance & Weight Selection over SMOTE
Instead of generating synthetic fraud points with SMOTE (which often invents unrealistic transaction feature combinations in high-dimensional space), the model uses scale_pos_weight. The optimal weight (24) was selected via 5-fold stratified cross-validation on the training set only, achieving a 0.848 CV PR-AUC.
SHAP-Driven Failure Mode Analysis
Analyzing the 18 false alarms and 23 missed frauds revealed two distinct failure types: borderline cases near the 0.5 decision boundary that are easily tuned via threshold sliders, and confident misses where anonymized PCA features overlap entirely with legitimate transactions.
Interactive Streamlit Comparison Application
The deployed Streamlit app allows users to inspect caught frauds, false alarms, and missed transactions side by side between the main XGBoost model and a FLAML-tuned benchmark, with real-time SHAP waterfall attribution plots.
What I would do differently
I would incorporate a custom monetary cost matrix into the objective function so that the decision threshold directly minimizes expected financial loss rather than maximizing generic F1 score.