┌─────────────────────────────────────────────────────┐
│ Data Layer │
│ ┌──────────┐ ┌─────────────┐ ┌───────────────┐ │
│ │ Raw CSV │→ │ Validator │→ │ Feature Eng. │ │
│ │ (loader) │ │ (schema) │ │ (transform) │ │
│ └──────────┘ └─────────────┘ └───────────────┘ │
└──────────────────────┬──────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────┐
│ Model Layer │
│ ┌──────────┐ ┌──────────┐ ┌──────────────────┐ │
│ │Supervised│ │Unsuperv. │ │ Ensemble │ │
│ │ Models │ │ Models │→ │ (weighted avg) │ │
│ │ (5 algos)│ │(IsoForest│ │ │ │
│ │ │ │ Autoenc) │ │ │ │
│ └────┬─────┘ └────┬─────┘ └────────┬─────────┘ │
│ └──────────────┴─────────────────┘ │
└──────────────────────┬──────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────┐
│ Evaluation & Optimization │
│ ┌──────────────┐ ┌──────────┐ ┌──────────────┐ │
│ │ Cost-Sensitive│ │Threshold │ │ Cross- │ │
│ │ Analysis │ │Optimizer │ │ Validation │ │
│ └──────────────┘ └──────────┘ └──────────────┘ │
└──────────────────────┬──────────────────────────────┘
│
┌──────────────────────▼──────────────────────────────┐
│ Serving & Monitoring │
│ ┌──────────┐ ┌──────────────┐ ┌──────────────┐ │
│ │ FastAPI │ │ Drift │ │ Streamlit │ │
│ │ REST API │ │ Detector │ │ Dashboard │ │
│ └──────────┘ └──────────────┘ └──────────────┘ │
└─────────────────────────────────────────────────────┘
loader.py— Data loading, schema validation, synthetic data generation, temporal train/test splittingfeature_engineering.py— Stateful transformer: temporal features, amount transformations, V-feature aggregates, interaction termsfeature_selection.py— Hybrid feature ranking (mutual information + model importance)augmentation.py— SMOTE, ADASYN, SMOTE-Tomek oversampling for class balance
supervised.py— Logistic Regression, Random Forest, XGBoost, LightGBM, CatBoost training functions with balanced class handlingunsupervised.py— Isolation Forest and Autoencoder anomaly detectorsensemble.py—FraudEnsembleclass: weighted model combination, full pipeline training, prediction explanationpersistence.py— Model serialization (save/load with joblib)network.py— Graph-based fraud network analysis
config.py— Centralized configuration: paths, costs, thresholds, hyperparametersevaluation.py— Metrics computation, confusion matrix, cost analysis, cross-validation, PR/ROC curve data, markdown report generationthreshold.py— Cost-sensitive threshold optimization and threshold analysismonitoring.py—DriftDetectorclass: KS-test, PSI computation, performance drift tracking, prediction loggingexplainability.py— SHAP and LIME explanation wrappers with mock fallbackpipeline.py—FraudDetectionPipelineorchestrator: end-to-end workflow from data loading through evaluation and reporting
main.py— FastAPI application with predict, batch predict, stream, health, feedback, and monitoring endpointsmodels.py— Pydantic request/response schemas
No single algorithm dominates across all fraud patterns. The ensemble combines:
- Logistic Regression: Interpretable baseline, good on linear separable patterns
- Random Forest: Handles feature interactions, robust to noise
- XGBoost/LightGBM/CatBoost: State-of-art gradient boosting for tabular data
- Isolation Forest: Catches novel fraud patterns without labeled examples
Financial transactions have temporal dependencies. Random splitting would leak future information into training, producing optimistically biased metrics. Temporal splitting ensures the model only trains on past data and evaluates on future data, matching real-world deployment conditions.
PR-AUC directly measures a model's ability to rank fraud cases higher than legitimate ones, respecting the severe class imbalance. Models contributing more to fraud identification receive higher ensemble weight, maximizing the combined detector's ability to surface true fraud.