A modular, production-ready Machine Learning system for credit default risk estimation and transaction intelligence on large-scale financial data (458,913 customers, 5.5M transactions), based on the American Express Default Prediction benchmark.
flowchart TD
Raw["Raw Transactions (5.5M rows CSV / Parquet)"] --> Ingestion["1. Streaming Ingestion & Downcasting<br/>(Polars Streaming, -70% RAM)"]
Ingestion --> Features["2. Feature Engineering Pipeline<br/>(Last, Mean, Min, Max, Trends, NUnique)"]
Features --> Store["3. Feature Matrix Store<br/>(1,002 Clean Features in Parquet)"]
Store --> Selector["4. Feature Selection & Ablation<br/>(Group Matching, Importance Pruning)"]
Selector --> Trainer["5. Model Training & Validation Engine<br/>(LightGBM, XGBoost, CatBoost on CUDA)"]
Trainer --> Tracker["6. Experimentation & Metrics Tracker<br/>(AMEX Metric, Gini, Top-4% Recall)"]
Trainer --> Exporter["7. High-Speed ONNX Compiler<br/>(models/onnx_exporter.py)"]
Tracker --> Models["8. Serialized Model Artifacts<br/>(artifacts/models/lightgbm.pkl & .onnx)"]
Exporter --> Models
Models --> API["9. Production Multi-Worker REST API Server<br/>(FastAPI + Gunicorn / Uvicorn: /predict, /predict/batch)"]
Models --> ONNX["10. Ultra-Low Latency ONNX Inference<br/>(0.025 ms per customer)"]
Models --> Predictor["11. Production Batch Inference CLI<br/>(458k customers scored in 20s)"]
Models --> Diagnostics["12. Error Diagnostics & Calibration<br/>(Risk Banding, Confusion Cohort Profiling)"]
| Inference Engine | Single Customer Latency | Throughput Speedup | Use Case |
|---|---|---|---|
| Standard Baseline | Cold start initial call | ||
| Warmed Up LightGBM (C++) | General batch scoring | ||
| ONNX Runtime (C++ Engine) | Real-time card transaction authorization |
The project executed systematic ablation, feature importance profiling, dimensionality reduction, hyperparameter tuning, and multi-seed stability validation:
| Rank | Experiment | Core Innovation | Features | AMEX Metric | Gini | Top-4% Recall | |
|---|---|---|---|---|---|---|---|
| π₯ 1 | EXP-013_seed777 | Multi-seed stability test 3 | 1,002 | 0.794174 | 0.923604 | 0.664745 | |
| π₯ 2 | EXP-012_seed123 | Multi-seed stability test 2 | 1,002 | 0.793783 | 0.924075 | 0.663492 | |
| π₯ 3 | EXP-011_slow_learning | lr=0.03, 1000 trees, leaves=45, reg_L2=2.0 |
1,002 | 0.791023 | 0.923019 | 0.659028 | |
| 4 | EXP-010_deep_regularized | depth=8, leaves=63, L1=0.1, L2=1.0 |
1,002 | 0.790375 | 0.922433 | 0.658317 | |
| 5 | EXP-003_no_ratios | Feature ablation: dropped *_ratio_last_mean
|
1,002 | 0.788848 | 0.921594 | 0.656101 | |
| 6 | EXP-008_top_500 | Top 500 features (56.8% reduction, 2.3x faster) | 500 | 0.788057 | 0.921643 | 0.654470 | |
| 7 | EXP-001_baseline | Full raw feature matrix baseline | 1,158 | 0.787714 | 0.921375 | 0.654052 |
Key Findings:
- Removing noisy ratios (
*_ratio_last_mean): Eliminated division-by-near-zero outliers, yielding$+0.001134$ in AMEX score and accelerating training by 25%.- Top Feature Drivers:
P_2_last(Credit score profile) accounts for 60.28% of total tree gain. Thelaststatement group contributes 81.48% of overall predictive power.- Multi-Seed Stability: Cross-seed mean performance reached
0.792993($\sigma = 0.0017$ ).
The pipeline is trained and evaluated on the American Express - Default Prediction benchmark dataset:
| Dataset Resource | Format | Size | Description | Link |
|---|---|---|---|---|
| Official Kaggle Competition | CSV (Raw) | ~50 GB | Raw multi-month statement transaction event logs and binary default labels. | Kaggle Competition Data |
| Optimized Parquet Mirror (Raddar) | Parquet | ~4 GB | Memory-optimized integer/float typed columns for ultra-fast reading. | Kaggle Parquet Dataset |
-
Customers:
$458,913$ unique customer accounts. -
Transactions:
$\approx 5.5\text{M}$ historical monthly billing statements. -
Features (188 raw):
-
$D_*$ (Delinquency variables: payment delays, delinquencies) -
$S_*$ (Spend variables: statement amounts, revolving spends) -
$P_*$ (Payment variables: payments, profile metrics likeP_2) -
$B_*$ (Balance variables: balance amounts, credit card balances) -
$R_*$ (Risk variables: risk scores, credit indicators)
-
- Target: Binary credit card default event within an 18-month performance window.
# Download official Kaggle competition raw data
python main.py download-data --source competition
# Or download lightweight pre-converted Parquet
python main.py download-data --source dataset --dataset raddar/amex-data-parquet-converterAll tasks are accessible through the root main.py entry point:
# 1. Download & Unpack Dataset (Kaggle or Direct URL)
python main.py download-data --source competition
# 2. Start FastAPI REST Server with Multi-Worker Scaling
python main.py serve --host 0.0.0.0 --port 8000 --workers 4
# 3. Export Model to Ultra-Fast ONNX Graph Format
python main.py export-onnx --model artifacts/models/lightgbm.pkl --output artifacts/models/lightgbm.onnx
# 4. Run Preprocessing & Feature Engineering
python main.py build-features --config configs/data_config.yaml
# 5. Train Model
python main.py train --config configs/training_config.yaml
# 6. Run Tracked Experiment with Feature Selection
python main.py experiment --config configs/training_config.yaml --model lightgbm
# 7. Run Batch Inference
python main.py predict --model artifacts/models/lightgbm.pkl --features data/processed/train_features.parquet --output predictions.parquet
# 8. Compare Completed Experiments
python main.py compare --metric amex_metric
# 9. Audit Feature Matrix Health
python main.py audit-features
# 10. Analyze Feature Importance
python main.py feature-importance --model artifacts/models/lightgbm.pklfintech-transaction-intelligence/
βββ main.py # Universal CLI entry point
βββ Dockerfile # Multi-stage production container with OpenMP
βββ docker-compose.yml # Docker compose orchestration
βββ configs/ # Experiment & training YAML configurations
β βββ experiments/ # Reproducible experiment configs (EXP-001 - EXP-014)
β βββ gunicorn_conf.py # Production Gunicorn master process configuration
β βββ data_config.yaml # Ingestion & preprocessing parameters
β βββ training_config.yaml # Baseline training config (CUDA enabled)
βββ data/ # Raw & processed Parquet feature matrices
βββ artifacts/ # Serialized models (.pkl / .onnx), importance tables
βββ reports/ # Detailed analytical & research reports
βββ scripts/ # Dedicated CLI scripts (see scripts/README.md)
β βββ score_real_customers.py # Live evaluation on real bank customer dataset
β βββ test_api_client.py # API automated verification client
β βββ run_experiment.py # Config-driven experiment runner
β βββ train.py # Model training entrypoint
β βββ compare_experiments.py # Leaderboard comparison tool
β βββ analyze_feature_importance.py # Feature gain & group diagnostics
β βββ analyze_errors.py # Error analysis & cohort profiling
β βββ predict.py # High-throughput batch inference CLI
βββ src/ # Core package source code (see src/README.md)
β βββ api/ # FastAPI serving layer (see src/api/README.md)
β βββ core/ # Foundation types, protocols, exceptions
β βββ data/ # Polars streaming loaders & memory downcasting
β βββ dataset/ # Train/val splitters & data contracts
β βββ diagnostics/ # Error analysis & risk band segmenters
β βββ experiments/ # Experiment tracking & leaderboard engine
β βββ features/ # Aggregators, selectors, RFM, importance analyzer
β βββ inference/ # ONNXPredictor & Predictor with auto feature alignment
β βββ models/ # LightGBM, XGBoost (CUDA), CatBoost, ONNX Exporter
β βββ monitoring/ # Drift detection & PSI metrics
β βββ training/ # Cross-validation orchestrator
βββ tests/ # Comprehensive Pytest test suite (277 passed)
# Run complete test suite
python -m pytest -vAll 277 unit and integration tests verify data contracts, feature extraction idempotence, model wrappers, metrics calculation, ONNX export/inference, API routes, and CLI inference.