Credit Card Fraud Detection System
A production-ready machine learning system that detects fraudulent credit card transactions in real-time. Combines advanced feature engineering, a six-model ensemble, and a FastAPI service delivering sub-100ms predictions with SHAP-based explainability.
View on GitHubSimulated real-time fraud detection — transactions stream live and model performance metrics are shown below.
0.871
PR-AUC (Ensemble)
primary metric
0.951
ROC-AUC
ensemble model
<100ms
Prediction Speed
per transaction
50+
Features Engineered
behavioral + temporal
Model Comparison
Performance across all 6 algorithms
ROC Curve — Ensemble Model
True Positive Rate vs. False Positive Rate (AUC = 0.951)
All models evaluated on held-out test set. Ensemble achieves best trade-off for deployment.
| Model | PR-AUC | ROC-AUC | Precision@100 | Recall@100 |
|---|---|---|---|---|
| Logistic Regression | 0.742 | 0.891 | 0.23 | 0.45 |
| Random Forest | 0.823 | 0.934 | 0.28 | 0.61 |
| LightGBM | 0.856 | 0.943 | 0.31 | 0.67 |
| XGBoost | 0.841 | 0.938 | 0.29 | 0.64 |
| Autoencoder | 0.623 | 0.789 | 0.18 | 0.34 |
| Ensemble | 0.871 | 0.951 | 0.35 | 0.72 |
Real-Time Prediction API
FastAPI service delivers sub-100ms fraud scores per transaction with single and batch prediction endpoints.
Ensemble ML Models
Six algorithms — Logistic Regression, Random Forest, LightGBM, XGBoost, Autoencoder, and a stacking ensemble — for robust detection.
Advanced Feature Engineering
50+ engineered features covering behavioral velocity, temporal patterns, rolling statistics, and PCA anomaly scores.
Explainable Predictions
SHAP-based feature importance surfaces the top drivers of each fraud score for analyst review and compliance.
Docker & CI/CD
Fully containerized with Docker Compose and an automated GitHub Actions pipeline for testing, linting, and deployment.
Comprehensive Testing
Unit and integration tests with 80%+ coverage target, mock fixtures, and a full pipeline integration test suite.
Six algorithms provide complementary coverage across different fraud patterns, combined in a stacking ensemble.
Logistic Regression
Baseline classifier
Class-weighted logistic regression provides a fast, interpretable baseline with strong recall on imbalanced fraud data.
Random Forest
Ensemble of decision trees
Aggregates hundreds of trees to reduce variance and capture non-linear feature interactions in transaction behavior.
LightGBM
Gradient boosting (best single model)
Leaf-wise boosting with hyperparameter tuning achieves the highest single-model PR-AUC (0.856) with fast inference.
XGBoost
Gradient boosting with early stopping
Regularized boosting with early stopping prevents overfitting while maintaining competitive recall on rare fraud events.
Autoencoder
Unsupervised anomaly detection
Learns a compressed representation of normal transactions; high reconstruction error flags novel fraud patterns unseen in training.
Stacking Ensemble
Meta-learner combination
A meta-learner combines all five base model outputs to achieve PR-AUC 0.871 and ROC-AUC 0.951 — the best overall performance.
Ingest
CSV transaction data (V1–V28 PCA features + Amount + Time) loaded and validated via Pydantic schemas
Engineer
50+ features extracted: velocity, temporal cycles, rolling z-scores, isolation forest anomaly scores, interaction ratios
Predict
Six ML models score each transaction; ensemble meta-learner combines outputs into a single calibrated fraud probability
Explain
SHAP values surface top feature contributions per prediction for analyst review, compliance, and model monitoring