genome06/home-credit-risk-analysis
๐ณ Predictive Analytics for Home Credit Default Risk (Kaggle Competition)
     
An end-to-end Machine Learning solution designed to predict the probability of a client's loan default. This project bridges the gap between complex data science modeling and real-world deployment using a modular Object-Oriented Programming (OOP) architecture.
๐ Project Overview
Home Credit strives to broaden financial inclusion for the unbanked population by providing a positive and safe borrowing experience. This project utilizes historical loan application data to predict whether an applicant will have difficulties repaying their loan.
Key Features:
- Single Prediction Mode: Interactive UI to input individual applicant data and receive a real-time risk score.
- Batch Prediction Mode (CSV): High-volume automated processing allowing users to upload CSV files (e.g.,
application_test.csv) and download full results. - Explainable AI (XAI): Integrated SHAP Values to interpret model decisions, ensuring transparency in credit scoring.
- Smart Risk Rating: Automated categorization into Low, Medium, and High Risk with actionable business recommendations and system messages.
๐ Business Insights & Strategic Decision Making
This project goes beyond technical accuracy by aligning model outputs with core banking KPIs and risk management strategies. The goal is to optimize the balance between Loan Growth and Credit Loss Mitigation.
๐ 1. Key Risk Drivers (Feature Interpretability)
Using SHAP (SHapley Additive exPlanations), the model identifies the most influential factors driving credit default:
- Financial Health (Payment Rate): The model heavily penalizes high payment-to-income ratios. High-risk candidates typically have an annuity-to-credit ratio that suggests an unsustainable debt burden.
- External Credibility (EXT_SOURCES): Normalized scores from external providers act as a proxy for financial reputation. A low average across these sources is the strongest indicator of potential delinquency.
- Employment Stability (Days Employed): The model detects a non-linear relationship where longer tenure in current employment significantly reduces the probability of default, reflecting the importance of income stability.
๐ก๏ธ 2. Risk-Based Action Plan (The Strategy)
To optimize operational efficiency, the application categorizes applicants into a Tri-Tier Risk System:
๐ 3. Strategic Value for Home Credit
- Expansion to the Unbanked: By using non-traditional features (like employment duration and goods price ratios), the model allows Home Credit to safely lend to individuals without a traditional credit history.
- Profitability Optimization: By accurately identifying Low-Risk individuals, the bank can offer faster approvals and lower interest rates, gaining a competitive edge in the market.
- Regulatory Compliance (XAI): Using Explainable AI (SHAP) ensures that the bank can provide a "Reason for Denial" to applicants, fulfilling transparency requirements set by central bank regulations.
๐ ๏ธ Tech Stack & Architecture
Core Technologies
- Modeling: LightGBM (Gradient Boosting Machine) with Hyperparameter Tuning.
- XAI: SHAP (SHapley Additive exPlanations).
- Backend: FastAPI (High-performance Python web framework).
- Frontend: Streamlit (Interactive Data Dashboard).
- Containerization: Docker (Multi-process orchestration).
Modular OOP Design
The project follows Clean Architecture principles to ensure maintainability and scalability:
DataTransformer: A dedicated class for feature engineering (26 features), robust median imputation, and vectorized log transformations.CreditPredictor: Manages model inference, risk thresholding logic, and business insight mapping.Schemas: Utilizes Pydantic for rigorous data validation and automatic Swagger documentation.
๐ Directory Structure
credit-scoring-app/
โโโ app/
โ โโโ api/ # FastAPI Endpoints & Pydantic Schemas
โ โโโ core/ # OOP Logic (Preprocessor & Predictor)
โ โโโ frontend/ # Streamlit UI Components
โโโ artifacts/ # Serialized Models (.joblib) & Scalers
โโโ Dockerfile # Containerization Script
โโโ requirements.txt # Project Dependencies
โโโ run.sh # Orchestration Script (Internal API & External UI)
โโโ README.md๐ Model Interpretability (XAI)
This model is built on transparency. Using SHAP Values, the system identifies key risk drivers for each prediction. Global analysis shows that EXTSOURCE ratings, PAYMENTRATE, and DAYS_EMPLOYED are the most significant factors in determining repayment probability.
โ๏ธ Installation & Local Setup
- Clone the Repository
git clone [https://github.com/yourusername/home-credit-risk-app.git](https://github.com/yourusername/home-credit-risk-app.git)
cd home-credit-risk-app- Manual Setup (Local)
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt- Docker Setup (Recommended)
docker build -t credit-scoring-app .
docker run -p 7860:7860 credit-scoring-appAccess the UI at http://localhost:7860.
๐ Deployment
This application is designed to be deployed on Hugging Face Spaces. It uses a custom run.sh entrypoint to orchestrate both the FastAPI backend (internal) and the Streamlit frontend (public) within a single Docker container.
Disclaimer: This project is a personal portfolio developed for educational purposes. It utilizes the public dataset provided by Home Credit on Kaggle. This application is not affiliated with, endorsed by, or an official product of Home Credit Group.
