A complete end-to-end Machine Learning system that predicts whether a loan applicant will default or not — built with Python, FastAPI, Streamlit, SHAP, and XGBoost.
This project covers the entire ML lifecycle: data cleaning, feature engineering, model tuning, explainability, and deployment.
This project demonstrates how financial institutions can use ML to assess credit risk and make informed lending decisions.
It predicts loan default probability using customer financial history, delinquency records, and utilization metrics.
- Predict whether a borrower will default in the next 2 years
- Build explainable and auditable ML pipeline
- Deploy model as an interactive web dashboard
✅ End-to-End ML Pipeline
- Data Cleaning (missing values, outliers)
- Feature Engineering & Scaling
- Model Training with RandomForest + XGBoost
- Hyperparameter tuning via RandomizedSearchCV
- ROC-AUC ~ 0.87 (XGBoost tuned)
📊 Explainability (SHAP)
- Global feature importance (SHAP bar plots)
- Local prediction explainability (Waterfall plots)
🌐 Deployment
- FastAPI backend for predictions (
/predictendpoint) - Streamlit dashboard for interactive UI
- Ready for Render / Streamlit Cloud deployment
| Model | ROC-AUC | Accuracy | Recall (Default) | Precision (Default) |
|---|---|---|---|---|
| RandomForest (tuned) | 0.865 | 0.80 | 0.77 | 0.22 |
| XGBoost (tuned) | 0.870 | 0.94 | 0.20 | 0.61 |
📌 Chosen Model: Tuned XGBoost
✔️ High precision
✔️ Better generalization
✔️ Cleaner SHAP explainability
| Plot | Description |
|---|---|
![]() |
Top features impacting default risk |
![]() |
Global SHAP distribution |
![]() |
Why a specific borrower was predicted default |
NumberOfTimes90DaysLateRevolvingUtilizationOfUnsecuredLinesDebtRatioNumberOfTime60-89DaysPastDueNotWorseage
| Layer | Tools Used |
|---|---|
| Data & ML | Python, Pandas, NumPy, Scikit-Learn, XGBoost |
| Explainability | SHAP |
| API | FastAPI |
| Frontend | Streamlit |
| Deployment | Render (API), Streamlit Cloud (Dashboard) |
| Version Control | Git + GitHub |
credit-risk-analyzer/
├── api/ # FastAPI backend (model inference)
│ └── app.py
├── dashboard/ # Streamlit frontend (UI)
│ └── app.py
├── notebooks/ # Jupyter notebooks (EDA, training, explainability)
│ ├── 01_eda.ipynb
│ ├── 02_model_training.ipynb
│ └── 03_explainability.ipynb
├── models/ # Trained model and scaler (ignored in .gitignore)
├── explainability/ # SHAP plots
├── data/ # Cleaned dataset
├── requirments.txt # Dependencies
└── README.md
git clone https://github.com/<your-username>/credit-risk-analyzer.git
cd credit-risk-analyzerpython -m venv venv
venv\Scripts\activate # Windows
# or
source venv/bin/activate # macOS/Linuxpip install -r requirments.txt- 🧠 Backend (FastAPI)
uvicorn api.app:app --reload
# Visit: http://127.0.0.1:8000/docs- 📊 Frontend (Streamlit)
streamlit run dashboard/app.py
# Visit: http://localhost:8501-
Option 1 – Streamlit Cloud (Frontend only)
- Push to GitHub (public)
- Visit
https://share.streamlit.io - Select
dashboard/app.pyas entry file
-
Option 2 – Render (Backend API)
- Build Command:
pip install -r requirments.txt- Start Command:
uvicorn api.app:app --host 0.0.0.0 --port 8000- Update the API URL in
dashboard/app.pyto your deployed endpoint when not running locally.
🧾 Results Summary
- Cleaned and preprocessed 150,000 loan records
- Trained multiple classifiers and tuned hyperparameters
- Achieved ROC-AUC = 0.87 with tuned XGBoost
- Implemented SHAP explainability
- Built interactive UI + REST API
- Prepared for cloud deployment
🧑💻 Author
Arslan Haroon
Team Lead @ Wanile | Full-Stack & AI Engineer
📍 Lahore, Pakistan
🌐 LinkedIn: linkedin.com/in/arslan-haroon
💻 GitHub: github.com/arslanjajja1
🪄 Acknowledgments
Dataset: Give Me Some Credit (Kaggle) Inspiration: Financial risk modeling and model explainability practices in FinTech.



