CoolFace
Apppublic

genome06/home-credit-risk-analysis

sourceHugging Facemitupdated 6mo agoView on Hugging Face
0likes
App README

๐Ÿ’ณ Predictive Analytics for Home Credit Default Risk (Kaggle Competition)

![Python](https://www.python.org/) ![FastAPI](https://fastapi.tiangolo.com/) ![Streamlit](https://streamlit.io/) ![Docker](https://www.docker.com/) ![ML Model](https://lightgbm.readthedocs.io/) ![License](https://opensource.org/licenses/MIT)

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:

Risk CategoryProbability RangeBusiness StrategyOperational Impact
๐ŸŸข Low Risk< 30%Auto-ApprovalZero human intervention; maximizes customer experience and reduces operational overhead.
๐ŸŸก Medium Risk30% - 60%Conditional Offer / Manual ReviewRequest additional collateral or verify income via physical documents. Risk-based pricing (higher interest) may be applied.
๐Ÿ”ด High Risk> 60%Immediate RejectionPrevents Non-Performing Loans (NPL) and protects the bank's capital reserves.

๐Ÿ“ˆ 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

text
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.

[image]

โš™๏ธ Installation & Local Setup

  1. 1.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
  1. 1.Manual Setup (Local)
python -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate
pip install -r requirements.txt
  1. 1.Docker Setup (Recommended)
docker build -t credit-scoring-app .
docker run -p 7860:7860 credit-scoring-app

Access 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.