Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💳 Smart Credit Risk Analyzer

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.

Dashboard View


🧠 Project Overview

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.


🎯 Objectives

  • Predict whether a borrower will default in the next 2 years
  • Build explainable and auditable ML pipeline
  • Deploy model as an interactive web dashboard

🚀 Key Features

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 (/predict endpoint)
  • Streamlit dashboard for interactive UI
  • Ready for Render / Streamlit Cloud deployment

📸 Dashboard Preview

Dashboard View


📊 Model Comparison

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


🧩 Explainability (SHAP)

Plot Description
SHAP Bar Top features impacting default risk
SHAP Summary Global SHAP distribution
SHAP Local Why a specific borrower was predicted default

🔍 Top 5 Most Important Features:

  1. NumberOfTimes90DaysLate
  2. RevolvingUtilizationOfUnsecuredLines
  3. DebtRatio
  4. NumberOfTime60-89DaysPastDueNotWorse
  5. age

🧱 Tech Stack

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

🧪 Project Structure

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

⚙️ Setup Instructions

1️⃣ Clone the Repository

git clone https://github.com/<your-username>/credit-risk-analyzer.git
cd credit-risk-analyzer

2️⃣ Create Virtual Environment

python -m venv venv
venv\Scripts\activate  # Windows
# or
source venv/bin/activate  # macOS/Linux

3️⃣ Install Dependencies

pip install -r requirments.txt

4️⃣ Run Locally

  • 🧠 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

🌍 Deployment

  • Option 1 – Streamlit Cloud (Frontend only)

    • Push to GitHub (public)
    • Visit https://share.streamlit.io
    • Select dashboard/app.py as 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.py to 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.

About

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.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages