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.
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.
- π 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
Live Demo
https://credit-risk-scoring-system1.streamlit.app
- Binary credit risk prediction
- Probability of Default estimation
- Tuned XGBoost classifier
- Threshold optimization
- Feature engineering
- Feature selection
- 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
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.
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
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.
| Metric | Score |
|---|---|
| Accuracy | 0.6616 |
| Precision | 0.3240 |
| Recall | 0.6312 |
| F1 Score | 0.4282 |
| ROC-AUC | 0.7085 |
| Metric | Score |
|---|---|
| Accuracy | 0.6667 |
| Precision | 0.3284 |
| Recall | 0.6316 |
| F1 Score | 0.4321 |
| ROC-AUC | 0.7113 |
| 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.
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.
User Inputs (16)
β
Input Validation
β
Preprocessing
β
Encoding
β
31 Model Features
β
XGBoost Prediction
β
Default Probability
β
Risk Score
β
Business Rule Evaluation
β
Final Lending Decision
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
| 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 |
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
β
The deployed application provides an intuitive interface for evaluating a borrower's credit risk.
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.
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
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.
β 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.
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
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
Lending Club Loan Dataset (2007β2015)
https://www.kaggle.com/datasets/adarshsng/lending-club-loan-data-csv
- Scikit-Learn
- XGBoost
- Streamlit
- Plotly
Bhumika
B.Tech Computer Science Student
GitHub: https://github.com/Bhumika2906