A Production-Grade Credit Risk Prediction System Inspired by HDFC Early Warning Practices
This repository contains a complete, industry-style, end-to-end Credit Card Delinquency Prediction System (DPD Prediction).
The solution has been designed by following the workflows, constraints, and expectations of real-world banking Early Warning Systems (EWS), especially those used in institutions like HDFC Bank.
It combines scalable data engineering, robust ML modeling, explainability, and a real-time inference API, making it suitable for production-grade deployment.
This is not a simple ML model.
This is a full risk-analytics platform with the same components used in fintech and banking ecosystems.
From data ingestion β feature engineering β model training β versioning β API deployment β explainability.
Supports three different data sources:
- Synthetic Indian behavioral dataset (DPD-labelled)
- User-provided Excel dataset (HDFC-style fields)
- AmEx Default Prediction dataset (11M+ rows) using RAM-safe chunk loading and sampling
Models are versioned with timestamps, metadata, reproducibility, and safety checks.
SHAP-based interpretability complies with:
- RBI model governance guidelines
- HDFC internal model validation practices
Chunked sampling from AmEx ensures the system works even on low-RAM machines.
Real-time scoring via FastAPI.
This README reflects the complete rationale, workflow, and business alignment behind the system.
Banks like HDFC must identify customers who are likely to miss payments next month (DPD > 0).
Traditional systems rely on:
- π Utilisation spikes
- π³ Payment behavior deviation
- π΅ Cash withdrawal patterns
- πͺ Merchant category shifts
- β‘ Spend velocity change
- π Transaction anomalies
Our system predicts this risk before delinquency occurs, enabling:
- π Early collection strategies
- π° Credit line adjustments
- π± Personalized nudges
- π‘οΈ Fraud/risk monitoring
- π€ Customer retention
This project directly addresses that need.
Delinquency-Check/
β
βββ data/
β βββ user/ # User Excel dataset (HDFC-style fields)
β βββ synthetic/ # Synthetic Indian credit dataset (DPD-labelled)
β βββ amex/ # AmEx dataset (downloaded via Kaggle API)
β
βββ models/ # Versioned ML models + scalers + metadata
β
βββ src/
β βββ data_prep.py # Multi-dataset ingestion + AmEx chunk sampling
β βββ synthetic_data_prep.py # Synthetic Indian dataset generator
β βββ features.py # Feature engineering & validation
β βββ train.py # Trains LR, RF, LightGBM with model metadata
β βββ evaluate.py # Single-run evaluation using AUC
β βββ evaluate_multiple.py # Multi-run stability testing for AmEx
β βββ explain.py # SHAP explainability engine
β βββ serve_api.py # FastAPI real-time inference service
β βββ utils.py # Path utilities + directory helpers
β
βββ requirements.txt
βββ README.md
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txtmkdir -p data/user data/synthetic data/amex models| Dataset | File Path |
|---|---|
| User Excel | data/user/Credit Card Delinquency Watch.xlsx |
| Synthetic CSV | data/synthetic/synthetic_indian_credit.csv |
| AmEx Kaggle files | data/amex/*.csv |
Generate API token β downloads kaggle.json
Move it to:
mkdir ~/.kaggle
mv kaggle.json ~/.kaggle/
chmod 600 ~/.kaggle/kaggle.jsonDownload AmEx dataset:
kaggle competitions download -c amex-default-prediction -p data/amex
unzip data/amex/amex-default-prediction.zip -d data/amexStart training:
python -m src.trainYou will see:
π Select which dataset to use:
1. Synthetic
2. User Excel
3. AmEx (chunked sample)
- Dataset selection
- Feature engineering & validation
- Train/test split (stratified)
- Train 3 models:
- Logistic Regression (baseline)
- Random Forest
- LightGBM (primary model for AmEx)
- Save outputs with timestamps:
- Model (
modelname_timestamp.pkl) - Scaler
- Metadata JSON
- Model (
Example metadata:
{
"dataset_used": "amex",
"timestamp": "20251210_135007",
"features": [...],
"metrics": {
"lgbm_auc": 0.9337,
"rf_auc": 0.9285
}
}This section demonstrates how we evaluate, validate, and explain the trained credit-risk model β following real banking standards (HDFC/RBI model governance guidelines).
Run a standard evaluation using any dataset (Synthetic, Excel, or AmEx):
python -m src.evaluateExample output:
π Using model: models/lgbm_20251210_135007.pkl
π Evaluation AUC on 'amex': 0.9350
| Metric | Limitation |
|---|---|
| Accuracy | Misleading for imbalanced datasets (e.g., 95% non-defaulters β fake high score) |
| AUC | Measures ranking ability β βDoes the model score defaulters higher?β |
AUC is the industry standard metric used by:
- π΅ HDFC EWS (Early Warning Systems)
- π΅ SBI/ICICI Risk Decision Engines
- π΅ RBI Model Governance teams
- Works on imbalanced datasets
- Reflects real-world credit-risk behavior
- Determines how well the model separates risky vs safe customers
- Used for downstream processes like cutoff setting (e.g., KS/Gini thresholds)
Explainability is mandatory for model governance and internal audit.
Generate SHAP summary:
python -m src.explainThis produces:
shap_summary.png
- Required by Model Validation teams
- Shows feature contribution direction (β increases risk, β decreases risk)
- Ensures transparency for committees (Credit, Risk, Compliance)
- Helps identify bias, drift, and model misuse
Stability is a mandatory requirement in financial risk modeling.
Run multi-sample evaluation:
python -m src.evaluate_multipleThis runs 5 independent evaluations on randomly sampled AmEx chunks (β55k rows each).
Example result:
Run 1: AUC = 0.93344
Run 2: AUC = 0.93389
Run 3: AUC = 0.93354
Run 4: AUC = 0.93586
Run 5: AUC = 0.93431
Mean AUC: 0.93461
Std Dev: 0.00094
Model Stability: VERIFIED
Banks require a model to perform consistently:
- across different customer segments
- across random samples
- across time windows
Low variance means:
β No overfitting
β High generalization
β Predictable performance
β Model is safe for production rollout
This visual shows AUC performance across multiple random samples, proving:
- Extremely low variance
- High robustness
- Consistent predictive power
This is exactly what credit-risk teams expect in production EWS models.
| Component | Why It Matters in Banking |
|---|---|
| AUC-based Evaluation | Industry standard for ranking credit-risk customers |
| SHAP Explainability | Required by RBI, auditors, and risk committees |
| Stability Testing | Ensures robustness, prevents model failures |
| AmEx Chunk Sampling | Handles 11M+ rows safely on any machine |
| Versioned Models | Reproducibility & auditability |
Your model evaluation process now matches real enterprise-grade credit risk modeling practices.
Start server:
uvicorn src.serve_api:app --reload --port 8000Open Swagger UI:
http://127.0.0.1:8000/docs
{
"prob_default_next_month": 0.27
}This enables:
- π Collections dashboards
- π CRM alerts
- π³ Credit-line monitoring
- π― Customer engagement automation
Run:
python -m src.evaluate_multipleThis performs multiple random AmEx chunk loads β evaluates robustness.
Example:
Run 1: AUC = 0.9312
Run 2: AUC = 0.9347
Run 3: AUC = 0.9336
Average AUC = 0.9331
Banks require stability across:
- π² Random samples
- β° Time periods
- π₯ Customer segments
This test satisfies that requirement.
This project goes far beyond simple delinquency prediction.
It captures all the real-world expectations of HDFC's EWS systems:
Utilisation, payment ratio, spend changes, cash withdrawals, merchant mix.
AmEx data changes over time β chunk sampling simulates monthly drift.
Handles datasets from 5,000 rows β 11,000,000 rows.
Transparent, explainable, reproducible.
Can integrate into:
- π Collection teams
- πΌ Credit line committees
- π Risk analytics dashboards
- π― Customer segmentation workflows
FastAPI + Model versioning + Metadata tracking.
This system is production-ready and follows industry best practices from day one. Whether you're building an EWS for a bank, fintech, or NBFC, this architecture provides the foundation you need.
Happy Predicting! π

