|
1 | | -## Project Overview |
| 1 | +# 🏦 LendingClub ML App |
2 | 2 |
|
3 | | -- The goal of this project is to train machine learning classification models to predict default probabilities of [Lending Club dataset](https://www.kaggle.com/datasets/ethon0426/lending-club-20072020q1) loans issued in 2018 by training these models on pre-2018 loan data from this dataset |
4 | | -- Leveraging these predictions, an IRR-optimized portfolio of highest-yielding 2018 loans is constructed for a hypothetical investor looking to maximize his or her returns on this loan set |
5 | | -- To better present and visualize key ML results and recommendations an interactive dashboard application using a Python Dash frontend and Flask backend is created |
6 | | - - See **Build and run app** for instructions on how to build and run app |
7 | | - - See **Sample app visualizations** for sample screenshots of app |
| 3 | +[](https://python.org) |
| 4 | +[](https://docker.com) |
| 5 | +[](LICENSE) |
| 6 | +[]() |
8 | 7 |
|
| 8 | +> A comprehensive machine learning application for predicting loan defaults and optimizing investment portfolios using the LendingClub dataset. |
9 | 9 |
|
10 | | -## Build and run app |
| 10 | +## 🎯 Project Overview |
11 | 11 |
|
12 | | -- This app uses docker-compose to run and network our `frontend` and `backend` services |
13 | | -- If docker-compose not already installed, see installation [instructions](https://docs.docker.com/compose/gettingstarted/) |
| 12 | +This project demonstrates advanced machine learning techniques applied to financial risk assessment. The application trains multiple classification models on historical LendingClub loan data to predict default probabilities, then uses these predictions to construct an IRR-optimized investment portfolio. |
14 | 13 |
|
15 | | -**Scripted e2e**: |
16 | | -``` |
17 | | -# Run from root dir |
| 14 | +### Key Features |
| 15 | + |
| 16 | +- **🤖 Multiple ML Models**: 8+ different algorithms including Logistic Regression, Random Forest, Gradient Boosting, and Neural Networks |
| 17 | +- **📊 Interactive Dashboard**: Real-time visualization of loan data, model performance, and portfolio optimization |
| 18 | +- **💰 Portfolio Optimization**: IRR-based portfolio construction with customizable investment criteria |
| 19 | +- **🔮 Live Predictions**: Real-time loan default predictions via REST API |
| 20 | +- **📈 Advanced Analytics**: Comprehensive EDA with interactive choropleth maps and statistical analysis |
| 21 | + |
| 22 | +### Business Impact |
| 23 | + |
| 24 | +- **7.40% IRR** for 36-month loans (vs. 6.30% baseline) |
| 25 | +- **10.63% IRR** for 60-month loans (vs. 8.11% baseline) |
| 26 | +- **1.51% and 0.99% alpha** over baseline for 36-month and 60-month loans respectively |
| 27 | +- **Statistically significant** results at 1% confidence level |
| 28 | + |
| 29 | +## 🚀 Quick Start |
| 30 | + |
| 31 | +### Prerequisites |
| 32 | + |
| 33 | +- Docker & Docker Compose |
| 34 | +- Python 3.9+ (for local development) |
| 35 | +- Git |
| 36 | + |
| 37 | +### Installation & Running |
| 38 | + |
| 39 | +**Option 1: Docker Compose (Recommended)** |
| 40 | +```bash |
| 41 | +# Clone the repository |
| 42 | +git clone https://github.com/yourusername/LendingClub_ML_App.git |
| 43 | +cd LendingClub_ML_App |
| 44 | + |
| 45 | +# Run the entire application |
18 | 46 | bash build_e2e.sh |
19 | 47 | ``` |
20 | 48 |
|
21 | | -**Manually**: |
| 49 | +**Option 2: Manual Docker Build** |
| 50 | +```bash |
| 51 | +# Build and run backend |
| 52 | +docker build -t flask_backend:v1 -f ./app/backend/Dockerfile.backend . |
| 53 | +docker run -d -p 5000:5000 --name flask_backend flask_backend:v1 |
22 | 54 |
|
23 | | -- See **/app/backend/build_backend.md** for instructions on how to manually build backend |
24 | | -- See **/app/frontend/build_frontend.md** for instructions on how to manually build frontend |
| 55 | +# Build and run frontend |
| 56 | +docker build -t dash_frontend:v1 -f ./app/frontend/Dockerfile.frontend . |
| 57 | +docker run -d -p 8050:8050 --name dash_frontend dash_frontend:v1 |
| 58 | +``` |
25 | 59 |
|
26 | | -## Sample app visualizations |
| 60 | +**Option 3: Local Development** |
| 61 | +```bash |
| 62 | +# Backend |
| 63 | +cd app/backend |
| 64 | +pip install -r requirements_backend.txt |
| 65 | +python flask_serve.py |
| 66 | + |
| 67 | +# Frontend (in another terminal) |
| 68 | +cd app/frontend |
| 69 | +pip install -r requirements_frontend.txt |
| 70 | +python app.py |
| 71 | +``` |
27 | 72 |
|
28 | | -1. Distributions of loan grades by state: |
| 73 | +### Access the Application |
29 | 74 |
|
30 | | -<div align="center"> |
31 | | - <a href="./"> |
32 | | - <img src="./images/choropleth.gif" width="79%"/> |
33 | | - </a> |
34 | | -</div> |
35 | | - |
| 75 | +- **Frontend Dashboard**: http://localhost:8050 |
| 76 | +- **Backend API**: http://localhost:5000 |
| 77 | +- **API Documentation**: http://localhost:5000/api/v1/predict |
36 | 78 |
|
37 | | -2. Loan default rates & interest rates vs FICO score: |
| 79 | +## 📊 Application Screenshots |
38 | 80 |
|
| 81 | +### 1. Interactive Choropleth Map - Loan Default Rates by State |
39 | 82 | <div align="center"> |
40 | | - <a href="./"> |
41 | | - <img src="./images/lineplots_bargraphs.gif" width="79%"/> |
42 | | - </a> |
| 83 | + <img src="./images/choropleth.gif" width="80%" alt="Choropleth Map showing loan default rates by state"/> |
43 | 84 | </div> |
44 | | - |
45 | 85 |
|
46 | | -3. Retrieve live ML model default predictions on sample anonymized customer data: |
| 86 | +### 2. FICO Score Analysis - Default Rates & Interest Rates |
| 87 | +<div align="center"> |
| 88 | + <img src="./images/lineplots_bargraphs.gif" width="80%" alt="Line plots showing relationship between FICO scores, default rates, and interest rates"/> |
| 89 | +</div> |
47 | 90 |
|
| 91 | +### 3. Real-time ML Predictions Interface |
48 | 92 | <div align="center"> |
49 | | - <a href="./"> |
50 | | - <img src="./images/predict_models.gif" width="79%"/> |
51 | | - </a> |
| 93 | + <img src="./images/predict_models.gif" width="80%" alt="Interactive interface for real-time loan default predictions"/> |
52 | 94 | </div> |
53 | 95 |
|
| 96 | +## 🔧 API Documentation |
| 97 | + |
| 98 | +### Prediction Endpoint |
| 99 | + |
| 100 | +**POST** `/api/v1/predict` |
| 101 | + |
| 102 | +Predict loan default probability using trained ML models. |
| 103 | + |
| 104 | +#### Request Body |
| 105 | +```json |
| 106 | +{ |
| 107 | + "query": [[feature1, feature2, ..., featureN]], |
| 108 | + "model": "GBC" |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +#### Response |
| 113 | +```json |
| 114 | +{ |
| 115 | + "prediction": "No Default", |
| 116 | + "confidence": [0.123, 0.877] |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +#### Available Models |
| 121 | +- `QDA` - Quadratic Discriminant Analysis |
| 122 | +- `LDA` - Linear Discriminant Analysis |
| 123 | +- `LOGIT` - Logistic Regression |
| 124 | +- `GBC` - Gradient Boosting Classifier |
| 125 | + |
| 126 | +#### Example Usage |
| 127 | +```bash |
| 128 | +curl -X POST http://localhost:5000/api/v1/predict \ |
| 129 | + -H "Content-Type: application/json" \ |
| 130 | + -d '{"query": [[50000, 700, 5, 10]], "model": "GBC"}' |
| 131 | +``` |
| 132 | + |
| 133 | +## 🏗️ Architecture |
| 134 | + |
| 135 | +``` |
| 136 | +┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 137 | +│ Frontend │ │ Backend │ │ Data Layer │ |
| 138 | +│ (Dash/Flask) │◄──►│ (Flask API) │◄──►│ (Pickle Files)│ |
| 139 | +│ Port: 8050 │ │ Port: 5000 │ │ │ |
| 140 | +└─────────────────┘ └─────────────────┘ └─────────────────┘ |
| 141 | +``` |
| 142 | + |
| 143 | +## 📈 Model Performance |
| 144 | + |
| 145 | +| Model | Non-2018 AUC | 2018 AUC | Performance | |
| 146 | +|-------|-------------|----------|-------------| |
| 147 | +| CatBoost Classifier | 0.892 | 0.841 | 🥇 Best | |
| 148 | +| MLP Neural Net | 0.884 | 0.816 | 🥈 Excellent | |
| 149 | +| Gradient Boosting | 0.831 | 0.766 | 🥉 Good | |
| 150 | +| Random Forest | 0.769 | 0.697 | ✅ Good | |
| 151 | + |
| 152 | +## 🛠️ Development |
| 153 | + |
| 154 | +### Project Structure |
| 155 | +``` |
| 156 | +LendingClub_ML_App/ |
| 157 | +├── app/ |
| 158 | +│ ├── backend/ # Flask API server |
| 159 | +│ │ ├── flask_serve.py |
| 160 | +│ │ ├── requirements_backend.txt |
| 161 | +│ │ └── Dockerfile.backend |
| 162 | +│ ├── frontend/ # Dash web application |
| 163 | +│ │ ├── app.py |
| 164 | +│ │ ├── constants/ |
| 165 | +│ │ ├── requirements_frontend.txt |
| 166 | +│ │ └── Dockerfile.frontend |
| 167 | +│ └── data/ # ML models and datasets |
| 168 | +├── notebooks/ # Jupyter notebooks for EDA |
| 169 | +├── presentation/ # Project presentation materials |
| 170 | +├── docker-compose.yml # Multi-container orchestration |
| 171 | +└── build_e2e.sh # End-to-end build script |
| 172 | +``` |
| 173 | + |
| 174 | +### Contributing |
| 175 | + |
| 176 | +1. Fork the repository |
| 177 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 178 | +3. Commit your changes (`git commit -m 'Add amazing feature'`) |
| 179 | +4. Push to the branch (`git push origin feature/amazing-feature`) |
| 180 | +5. Open a Pull Request |
54 | 181 |
|
55 | | -## Dataset |
56 | | -- See [Kaggle dataset](https://www.kaggle.com/datasets/ethon0426/lending-club-20072020q1) |
| 182 | +## 📚 Resources |
57 | 183 |
|
| 184 | +- **Dataset**: [LendingClub 2007-2020Q1](https://www.kaggle.com/datasets/ethon0426/lending-club-20072020q1) |
| 185 | +- **Blog Post**: [Predicting Loan Defaults using ML](https://nycdatascience.com/blog/student-works/predicting-loan-defaults-using-machine-learning-classification-models/) |
| 186 | +- **Video Presentation**: [YouTube](https://www.youtube.com/watch?v=1U1pIe5-GZ0&ab_channel=NYCDataScienceAcademy) |
| 187 | +- **Presentation Slides**: [PDF](./presentation/NYCDSA_Capstone_Presentation_vF.pdf) |
58 | 188 |
|
59 | | -## Blog post + live presentation |
| 189 | +## 📄 License |
60 | 190 |
|
61 | | -- Link to [blog post](https://nycdatascience.com/blog/student-works/predicting-loan-defaults-using-machine-learning-classification-models/) |
| 191 | +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. |
62 | 192 |
|
63 | | -- Link to [live presentation](https://www.youtube.com/watch?v=1U1pIe5-GZ0&ab_channel=NYCDataScienceAcademy) (youtube) |
| 193 | +## 👨💻 Author |
64 | 194 |
|
| 195 | +**Philippe Heitzmann** |
| 196 | +- Email: philheitz6[at]gmail[dot]com |
| 197 | +- LinkedIn: [Your LinkedIn Profile] |
| 198 | +- GitHub: [@yourusername](https://github.com/yourusername) |
65 | 199 |
|
66 | | -## Presentation slides |
| 200 | +--- |
67 | 201 |
|
68 | | -Please refer to **/presentation/NYCDSA_Capstone_Presentation_vF.pdf** for slides of presentation given on January 5th, 2021 to NYCDSA prospective students and alums regarding this project |
| 202 | +⭐ **Star this repository if you found it helpful!** |
0 commit comments