https://github.com/tirthpatel1020/loan-default-risk-prediction
Explainable ML system for loan default prediction integrating cybersecurity-inspired behavioral features. 99.43% ROC-AUC. Master's thesis project.
https://github.com/tirthpatel1020/loan-default-risk-prediction
credit-risk cybersecurity data-science loan-default machine-learning shap streamlit xgboost
Last synced: about 1 month ago
JSON representation
Explainable ML system for loan default prediction integrating cybersecurity-inspired behavioral features. 99.43% ROC-AUC. Master's thesis project.
- Host: GitHub
- URL: https://github.com/tirthpatel1020/loan-default-risk-prediction
- Owner: tirthpatel1020
- License: mit
- Created: 2025-11-17T04:34:43.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-17T05:08:42.000Z (8 months ago)
- Last Synced: 2025-11-17T07:17:53.419Z (8 months ago)
- Topics: credit-risk, cybersecurity, data-science, loan-default, machine-learning, shap, streamlit, xgboost
- Language: Python
- Homepage:
- Size: 28.4 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ฐ Loan Default Risk Assessment with Cybersecurity Features
[](https://www.python.org/downloads/)
[](https://streamlit.io)
[](LICENSE)
[]()
**Master's Thesis Project** | Toronto Metropolitan University | 2025
An explainable machine learning system for predicting loan default risk by integrating **cybersecurity-inspired behavioral features** with traditional financial indicators.
---
## ๐ฏ Key Highlights
- ๐ **99.43% ROC-AUC** - 36% improvement over baseline
- ๐ **71% importance** from cybersecurity features
- ๐ **5 ML models** - Logistic Regression, Random Forest, XGBoost, Neural Network
- ๐จ **Interactive Web App** - Real-time predictions with Streamlit
- ๐ก **Full Explainability** - SHAP analysis for transparent decisions
- ๐ฐ **Business Impact** - $4-7M estimated annual savings per $100M portfolio
---
## ๐ฌ Research Innovation
### The Problem
Traditional loan risk models rely solely on financial data (credit score, income, DTI). This misses crucial signals from **applicant behavior** during the loan application process.
### Our Solution
We introduce **cybersecurity-inspired behavioral features** that capture risk signals such as:
- ๐ **Application editing patterns** - Excessive edits indicate uncertainty/deception
- ๐ **Information consistency** - Contradictory data detection
- โฐ **Timing anomalies** - Off-hours or rushed applications
- ๐ฅ๏ธ **Device signals** - VPN/proxy usage, device fingerprinting
- ๐ฉ **Behavioral risk scoring** - Composite indicators
### Results
Cybersecurity features **dominate** model decisions:
- ๐ฅ **info_consistency_score**: 44% importance
- ๐ฅ **app_edit_score**: 23% importance
- ๐ฅ **behavioral_risk_composite**: 10% importance
**Top 3 features are ALL cybersecurity! ๐ฅ**
---
## ๐ Project Structure
```
loan_default_risk_project/
โ
โโโ ๐ฑ app.py # Streamlit web application
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ README.md # This file
โโโ ๐ซ .gitignore # Git ignore rules
โ
โโโ ๐ notebooks/ # Jupyter/Python notebooks
โ โโโ 01_data_exploration_eda.py
โ โโโ 02_preprocessing_feature_engineering.py
โ โโโ 03_model_development.py
โ โโโ 04_explainability_analysis.py
โ
โโโ ๐ค models/ # Trained ML models (*.pkl)
โ โโโ logistic_regression_baseline.pkl
โ โโโ logistic_regression_enhanced.pkl
โ โโโ random_forest.pkl
โ โโโ xgboost.pkl
โ โโโ neural_network.pkl
โ
โโโ ๐พ data/ # Processed data files
โ โโโ feature_info.csv
โ โโโ model_comparison.csv
โ โโโ scaler.pkl
โ
โโโ ๐ results/ # Visualizations & reports
โ โโโ *.png (32 visualization files)
โ โโโ model_comparison.csv
โ โโโ cybersecurity_impact.csv
โ
โโโ ๐ docs/ # Documentation
โโโ module1_summary.txt
โโโ module2_summary.txt
โโโ module3_summary.txt
โโโ module4_summary.txt
โโโ deployment_recommendations.txt
```
---
## ๐ Quick Start
### 1๏ธโฃ Clone the Repository
```bash
git clone https://github.com/YOUR_USERNAME/loan-default-risk-prediction.git
cd loan-default-risk-prediction
```
### 2๏ธโฃ Install Dependencies
```bash
pip install -r requirements.txt
```
**Requirements:**
- Python 3.11+
- Streamlit
- scikit-learn
- XGBoost
- SHAP
- Plotly
- pandas, numpy, matplotlib
### 3๏ธโฃ Run the Web Application
```bash
streamlit run app.py
```
The app will open at `http://localhost:8501` ๐
---
## ๐ป Usage Examples
### ๐ฎ Single Prediction
1. Navigate to "Predict Default" page
2. Enter loan details:
- Financial: Loan amount, interest rate, income
- Credit: Grade, employment, delinquencies
- **Behavioral**: Application edits, consistency score, device anomalies
3. Get instant prediction with explanations
**Example:**
```
Input:
- Loan: $15,000 at 12% interest
- Income: $75,000, DTI: 18%
- Grade: B
- App Edits: 2, Consistency: 85
Output:
โ
APPROVED
Default Probability: 15.3%
Risk: Low
```
### ๐ Batch Prediction
Upload CSV โ Get bulk predictions โ Download results
### ๐ Model Comparison
Compare all 5 models side-by-side with interactive charts
---
## ๐ฌ Methodology
### Dataset
- **Source**: LendingClub (Kaggle)
- **Period**: 2007-2018 Q4
- **Samples**: 87,892 loans
- **Features**: 39 (31 traditional + 8 cybersecurity)
### Models Implemented
1. **Logistic Regression** (Baseline & Enhanced)
2. **Random Forest**
3. **XGBoost**
4. **Neural Network** (3 hidden layers)
### Feature Engineering
**Traditional Features:**
- Financial ratios (payment-to-income, loan-to-income)
- Credit history (grade, delinquencies, accounts)
- Demographics (employment, home ownership)
**Cybersecurity Features (Innovation!):**
- Application edit count & score
- Information consistency score
- Behavioral risk composite
- Device anomaly detection
- Rush/off-hours application flags
- Login irregularity score
### Evaluation Metrics
- ROC-AUC
- F1-Score
- Precision & Recall
- Confusion Matrix
- SHAP Values
---
## ๐ Results Summary
### Model Performance
| Model | Accuracy | Precision | Recall | F1 | ROC-AUC |
|-------|----------|-----------|--------|-----|---------|
| **LR Enhanced** | **96.63%** | 88.63% | **95.43%** | 91.90% | **99.43%** |
| XGBoost | 96.87% | **90.27%** | 94.58% | **92.37%** | 99.38% |
| Neural Net | **97.08%** | **93.12%** | 92.25% | 92.68% | 99.34% |
| Random Forest | 95.64% | 85.99% | 93.44% | 89.56% | 98.81% |
| LR Baseline | 68.66% | 34.63% | 63.62% | 44.85% | 72.91% |
### Impact of Cybersecurity Features
| Metric | Baseline | Enhanced | Improvement |
|--------|----------|----------|-------------|
| ROC-AUC | 72.91% | 99.43% | **+36.38%** |
| Precision | 34.63% | 88.63% | **+155.92%** |
| F1-Score | 44.85% | 91.90% | **+104.92%** |
| Recall | 63.62% | 95.43% | **+50.00%** |
### Feature Importance (SHAP Analysis)
**Top 5 Features:**
1. ๐ฅ info_consistency_score (44.15%) - **Cybersecurity**
2. ๐ฅ app_edit_score (22.78%) - **Cybersecurity**
3. ๐ฅ behavioral_risk_composite (9.64%) - **Cybersecurity**
4. grade_encoded (5.10%) - Traditional
5. int_rate (3.63%) - Traditional
**Cybersecurity features: 71.29% of total importance! ๐ฅ**
---
## ๐ผ Business Impact
### Expected Benefits (per $100M portfolio)
- ๐ฐ **$4-7M annual savings** through improved default detection
- ๐ **8-10% approval rate increase** via reduced false positives
- ๐ฏ **95% default detection** vs 64% baseline
- โ
**83% reduction** in false rejections
### Deployment Recommendations
**Phase 1 (Months 1-2): Shadow Mode**
- Run parallel to existing system
- Validate on real data
**Phase 2 (Months 3-4): Partial Deployment**
- 10% of applications
- Monitor closely
**Phase 3 (Months 5-6): Full Deployment**
- All applications
- Continuous monitoring
---
## ๐ Explainability
### SHAP Analysis
Every prediction includes:
- โ
Feature contribution breakdown
- โ
Waterfall plots for individual loans
- โ
Global importance rankings
- โ
Dependence plots showing relationships
### Why This Matters
- โ
Regulatory compliance (GDPR, Fair Lending)
- โ
Build trust with stakeholders
- โ
Identify bias and discrimination
- โ
Enable manual review process
---
## โ ๏ธ Important Notes
### Simulated Features
The cybersecurity features in this project are **simulated** based on established risk-behavior correlations from fraud detection literature.
**Why simulation?**
- โ
LendingClub dataset lacks behavioral data
- โ
Demonstrates framework methodology
- โ
Proves concept viability
- โ Not production-validated
**For real deployment:**
- Requires actual application log data
- Device fingerprinting systems
- Login analytics infrastructure
- Validation with ground truth
### Research Purpose
This is a **proof-of-concept** demonstrating:
1. How to integrate behavioral features
2. Framework for digital lenders
3. Potential value of this approach
4. Methodology for future validation
---
## ๐ Academic Context
**Research Type:** Master's Thesis
**Institution:** Toronto Metropolitan University
**Program:** Data Science and Analytics
**Year:** 2025
### Research Contributions
1. **Novel Framework** - First integration of cybersecurity concepts in credit risk
2. **Quantified Impact** - 71% importance from behavioral signals
3. **Explainability** - Complete SHAP analysis framework
4. **Practical Guidelines** - Deployment roadmap with business case
5. **Open Methodology** - Replicable for future research
### Future Research Directions
- ๐ฌ Validate with real behavioral data from digital lenders
- ๐ Fairness audits across demographic groups
- ๐ Temporal analysis of behavioral patterns
- ๐ Extension to other financial products
- ๐ Privacy-preserving data collection methods
---
## ๐ ๏ธ Technologies Used
**Machine Learning:**
- scikit-learn (ML models)
- XGBoost (Gradient boosting)
- TensorFlow/Keras (Neural networks)
- SHAP (Explainability)
- imbalanced-learn (SMOTE)
**Data Processing:**
- pandas (Data manipulation)
- numpy (Numerical computing)
**Visualization:**
- matplotlib & seaborn (Static plots)
- Plotly (Interactive charts)
- Streamlit (Web app)
**Deployment:**
- Streamlit Cloud (Free hosting)
- Docker (Containerization)
- Git/GitHub (Version control)
---
## ๐ธ Screenshots
### Prediction Interface

*Real-time loan default prediction with cybersecurity features*
### Model Comparison

*Performance metrics across all 5 models*
### SHAP Explanations

*Feature importance showing cybersecurity dominance*
---
## ๐ค Contributing
This is an academic research project. If you'd like to:
- Report bugs โ Open an issue
- Suggest features โ Open an issue
- Contribute code โ Fork and create a pull request
- Cite this work โ See citation below
---
## ๐ Citation
If you use this work in your research, please cite:
```bibtex
@mastersthesis{yourname2025loan,
title={Risk Assessment for Loan Default Using Machine Learning with Security-Aware Features},
author={Tirthkumar Patel},
year={2025},
school={Toronto Metropolitan University},
type={Master's Thesis},
url={https://github.com/yourusername/loan-default-risk-prediction}
}
```
---
## ๐ง Contact
**Author:** Tirthkumar Patel
**Email:** tirthp552@gmail.com
**LinkedIn:** [linkedin.com/in/yourprofile](www.linkedin.com/in/tirthkumar-patel-4b24a0211)
**GitHub:** [@tirthpatel1020](https://github.com/tirthpatel1020)
**Institution:** Toronto Metropolitan University
**Supervisor:** Dr. Ayลe Baลar
**Department:** Data Science and Analytics
---
## ๐ License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
**Academic Use:** Free to use for research and education with proper citation.
---
## ๐ Acknowledgments
- **LendingClub** for providing the dataset
- **Toronto Metropolitan University** for research support
- **SHAP library** for explainability tools
- **Streamlit** for the web framework
- **Research supervisors** and committee members
- **Open-source community** for various libraries
---
## ๐ Related Resources
- [LendingClub Dataset (Kaggle)](https://www.kaggle.com/datasets/wordsforthewise/lending-club)
- [SHAP Documentation](https://shap.readthedocs.io/)
- [Streamlit Documentation](https://docs.streamlit.io/)
- [Project Documentation](/docs/)
---
## โญ Star This Repository!
If you find this project useful, please consider giving it a โญ!
**Made with โค๏ธ for advancing credit risk assessment through behavioral analytics**
---
*Last Updated: November 2025*