Skip to content

Latest commit

Β 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’³ Credit Risk Scoring System

Python Machine Learning Streamlit Scikit-Learn Status

An end-to-end Machine Learning project that predicts the probability of loan default using historical U.S. Lending Club loan dataset (2007–2015) and provides explainable lending recommendations through an interactive Streamlit application.

Learning Milestone: This project marks my first end-to-end Machine Learning project and the first machine learning model I independently trained and deployed. It captures my complete journey of learning practical machine learningβ€”from preprocessing a real-world financial dataset to building, evaluating, optimizing, and deploying a credit risk prediction system.


πŸ“Œ Overview

Credit risk assessment is one of the most important tasks performed by financial institutions before approving a loan. Incorrect lending decisions can result in significant financial losses, making accurate default prediction essential.

This project develops a complete Credit Risk Scoring System capable of estimating the Probability of Default (PD) using historical Lending Club loan data. The predicted probability is further transformed into practical lending insights such as Risk Score, Risk Tier, Loan Decision, and Recommended Interest Rate. To better simulate real-world underwriting, the machine learning model is combined with predefined business rules before producing the final recommendation.

Unlike a simple classification project, this repository covers the complete machine learning lifecycleβ€”from raw data preprocessing and exploratory analysis to model development, optimization, and deployment through an interactive Streamlit application.


✨ Project Highlights

  • πŸ“Š Processed 2.26 million Lending Club loan records with 145 original features
  • 🧹 Performed complete data cleaning, preprocessing, and feature engineering
  • πŸ“ˆ Conducted detailed Exploratory Data Analysis (EDA) to identify important credit risk indicators
  • πŸ€– Compared multiple machine learning models including Logistic Regression and XGBoost
  • βš™οΈ Tuned the final XGBoost model using RandomizedSearchCV
  • 🎯 Optimized the classification threshold (0.45) to improve risky borrower detection
  • πŸ“‰ Reduced deployment complexity from 53 engineered features to 16 user-friendly borrower inputs
  • πŸ”„ Automatically transformed 16 inputs into 31 encoded model features during prediction
  • 🏦 Integrated machine learning predictions with rule-based underwriting policies
  • πŸ’» Built an interactive Streamlit dashboard for real-time credit risk assessment

πŸš€ Demo

Live Demo

https://credit-risk-scoring-system1.streamlit.app

🎯 Key Features

Machine Learning

  • Binary credit risk prediction
  • Probability of Default estimation
  • Tuned XGBoost classifier
  • Threshold optimization
  • Feature engineering
  • Feature selection

Interactive Dashboard

  • Borrower information form
  • Real-time prediction
  • Risk score generation
  • Risk tier classification
  • Lending recommendation
  • Suggested interest rate
  • Interactive risk gauge
  • Top prediction factors
  • Business rule alerts

πŸ“Š Dataset

This project uses the Lending Club Loan Dataset (2007–2015).

Attribute Value
Source Lending Club
Provider Kaggle
Rows 2,260,668
Original Features 145
Domain Consumer Lending

The dataset contains borrower information, loan characteristics, repayment history, and credit-related attributes used to build a supervised machine learning model for credit risk prediction.

A detailed description of the dataset and preprocessing steps is available in docs/pipeline.md.


βš™οΈ Machine Learning Pipeline


Raw Lending Club Dataset
↓
Data Cleaning
↓
Exploratory Data Analysis
↓
Feature Engineering
↓
Model Training
↓
Hyperparameter Tuning
↓
Threshold Optimization
↓
Feature Selection
↓
Streamlit Deployment
↓
Business Rule Evaluation
↓
Final Lending Recommendation


🧠 Model Development

Several supervised learning models were explored during development.

The final comparison focused primarily on:

Model Purpose
Logistic Regression (Balanced) Baseline Model
XGBoost Classifier Final Production Model

The XGBoost model demonstrated the strongest overall predictive performance and was selected for deployment after hyperparameter tuning using RandomizedSearchCV.


πŸ“ˆ Model Performance

Logistic Regression (Balanced)

Metric Score
Accuracy 0.6616
Precision 0.3240
Recall 0.6312
F1 Score 0.4282
ROC-AUC 0.7085

Tuned XGBoost

Default Threshold

Metric Score
Accuracy 0.6667
Precision 0.3284
Recall 0.6316
F1 Score 0.4321
ROC-AUC 0.7113

Final Operating Threshold (0.45)

Metric Score
Accuracy 0.6095
Precision 0.3021
Recall 0.7217
F1 Score 0.4259

The threshold was intentionally lowered from 0.50 to 0.45 to improve the detection of risky borrowers, prioritizing higher recallβ€”a common objective in credit risk applications where missing a potential defaulter is often more costly than incorrectly flagging a safe borrower.


🎯 Design Philosophy

This Credit Risk Scoring System is intentionally designed to prioritize the detection of high-risk borrowers rather than maximizing overall classification accuracy.

In credit lending, approving a borrower who later defaults (False Negative) is generally far more costly than incorrectly flagging a creditworthy borrower for additional review (False Positive). Therefore, the model was optimized to achieve a higher recall, enabling it to identify a larger proportion of potentially risky applicants.

To support this objective, the classification threshold was reduced from the default 0.50 to 0.45, increasing the model's sensitivity to risky borrowers. While this results in a lower precision and overall accuracy, it aligns more closely with practical lending scenarios where minimizing missed defaults is often a higher priority than minimizing false alarms.

This design choice reflects a business-oriented approach to credit risk assessment, balancing machine learning performance with the real-world cost of lending decisions.


πŸ—οΈ Deployment Architecture


User Inputs (16)
↓
Input Validation
↓
Preprocessing
↓
Encoding
↓
31 Model Features
↓
XGBoost Prediction
↓
Default Probability
↓
Risk Score
↓
Business Rule Evaluation
↓
Final Lending Decision


πŸ“„ Documentation

This repository contains detailed documentation covering the complete development process.

Document Description
README.md Project overview and quick start
docs/pipeline.md Complete project workflow and implementation details

The pipeline documentation includes:

  • Data Cleaning
  • Exploratory Data Analysis
  • Feature Engineering
  • Model Development
  • Threshold Optimization
  • Feature Selection
  • Streamlit Architecture
  • Business Rules
  • Limitations
  • Future Improvements

πŸ› οΈ Technology Stack

Category Technologies
Programming Language Python
Data Processing Pandas, NumPy
Data Visualization Matplotlib, Seaborn, Plotly
Machine Learning Scikit-Learn, XGBoost
Model Serialization Joblib
Web Framework Streamlit
Version Control Git, GitHub

πŸ“‚ Repository Structure

credit-risk-scoring-system/
β”‚
β”œβ”€β”€ app.py                        # Streamlit application
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ README.md
β”‚
β”œβ”€β”€ docs/
β”‚   └── pipeline.md               # Complete project documentation
β”‚
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ xgb_credit_risk_streamlit.pkl
β”‚   └── selected_features.pkl
|   |__ threshold.pkl
β”‚
β”œβ”€β”€ notebooks/
β”‚   β”œβ”€β”€ 01_data_cleaning.ipynb
β”‚   β”œβ”€β”€ 02_EDA.ipynb
β”‚   β”œβ”€β”€ 03_Encoding.ipynb
|   β”œβ”€β”€ 04_Baseline_model.ipynb
|   β”œβ”€β”€ 05_feature_eng.ipynb
|   β”œβ”€β”€ 06_Trained_Model.ipynb
β”‚   └── Streamlit_proj_model.ipynb
β”‚
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ predictor.py
β”‚   β”œβ”€β”€ preprocessing.py
β”‚   └── risk_logic.py
β”‚


πŸ“Š Streamlit Features

The deployed application provides an intuitive interface for evaluating a borrower's credit risk.

Borrower Information

The application accepts 16 meaningful borrower inputs, including:

  • Loan Amount
  • Annual Income
  • Loan Term
  • Employment Length
  • Credit History Length
  • Home Ownership
  • Loan Purpose
  • Debt-to-Income Ratio
  • Credit Utilization
  • Revolving Balance
  • Open Accounts
  • Mortgage Accounts
  • Total Accounts
  • Recent Delinquencies
  • Credit Inquiries
  • Bankruptcy History

These inputs are automatically transformed into the 31 encoded features expected by the trained XGBoost model.


Prediction Output

For every applicant, the system generates:

  • πŸ“ˆ Default Probability
  • 🎯 Risk Score (0–100)
  • 🟒 Risk Tier
  • 🏦 Lending Decision
  • πŸ’° Recommended Interest Rate
  • πŸ“Š Risk Gauge
  • πŸ” Top Prediction Factors
  • ⚠️ Business Rule Alerts

πŸ’Ό Business Rule Engine

To better reflect real-world lending practices, the application combines machine learning predictions with predefined underwriting policies.

Example policy checks include:

  • Loan-to-Income Ratio
  • Debt-to-Income Ratio
  • Credit Utilization
  • Bankruptcy History
  • Recent Delinquencies
  • Multiple Credit Inquiries

Whenever a policy is triggered, the application displays a business rule alert explaining the reason behind the lending recommendation.

This hybrid approach improves transparency and demonstrates how statistical models can be combined with domain-specific business logic.


πŸ“Œ Key Results

βœ” Successfully developed an end-to-end machine learning pipeline for credit risk prediction.

βœ” Processed over 2.26 million historical lending records.

βœ” Reduced deployment complexity from 53 engineered features to 16 user-friendly inputs without sacrificing usability.

βœ” Improved risky borrower detection by selecting an optimized 0.45 classification threshold.

βœ” Combined machine learning predictions with business rules to simulate a realistic lending workflow.

βœ” Built a complete Streamlit application capable of generating explainable lending recommendations in real time.


πŸ“– Detailed Documentation

For readers interested in the complete technical implementation, please refer to:

πŸ“„ docs/pipeline.md

The document covers:

  • Data Cleaning
  • Missing Value Treatment
  • Exploratory Data Analysis
  • Feature Engineering
  • Model Development
  • Hyperparameter Tuning
  • Threshold Optimization
  • Feature Selection
  • Streamlit Pipeline
  • Business Rule Design
  • Limitations
  • Future Improvements

πŸš€ Future Improvements

Potential enhancements include:

  • SHAP-based model explainability
  • Probability calibration
  • REST API deployment
  • Docker containerization
  • Cloud deployment
  • Automated feature selection
  • Real-time credit bureau integration
  • Loan repayment simulator
  • PDF credit assessment reports

πŸ“š References

Dataset

Lending Club Loan Dataset (2007–2015)

https://www.kaggle.com/datasets/adarshsng/lending-club-loan-data-csv

Documentation

  • Scikit-Learn
  • XGBoost
  • Streamlit
  • Plotly

πŸ‘©β€πŸ’» Author

Bhumika

B.Tech Computer Science Student

GitHub: https://github.com/Bhumika2906


⭐ If you found this project interesting, consider giving it a star!

About

Credit Risk Scoring System capable of estimating the Probability of Default (PD) using historical Lending Club loan data.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages