This repository contains two main scripts for preparing and modelling Loss Given Default (LGD) on LendingClub loan data.
The framework combines Explainable Boosting Machines (EBM) for feature selection with Beta Regression for statistical calibration, and extends into segmented LGD bands with decision-tree and multinomial logistic gates.
- Purpose: Prepares LendingClub loan-level datasets for LGD modelling.
- Key steps:
- Compute realized LGD for defaulted/charged-off loans.
- Clean and transform borrower, loan, and payment features.
- Classify job titles into NAICS 2-digit sectors using a transparent, rule-based classifier.
- Merge point-in-time macroeconomic and industry-level covariates (e.g., GDP, inflation, consumer spending).
- Export a clean, analysis-ready dataset.
- Purpose: Implements the hybrid LGD modelling pipeline.
- Key components:
- Train single EBM models with hyperparameter tuning for feature ranking.
- Perform correlation and redundancy analysis on top-ranked features.
- Estimate baseline Beta Regression with probit/logit links.
- Extend to segmented Beta Regression with:
- Decision Tree gates (soft and hard).
- Multinomial Logistic regression gates.
- Evaluate models with metrics (R², MAE, RMSE) and residual diagnostics.
- Visualise predictive distributions, mixture densities, and marginal effects.
The modelling is based on LendingClub loan-level data:
- Accepted applications:
accepted_2007_to_2018Q4.csv - Rejected applications:
rejected_2007_to_2018Q4.csv
They can be downloaded directly from the Kaggle LendingClub Loan Data.
Python libraries:
numpy,pandas,matplotlib,seaborn,scipy,statsmodelsscikit-learn,interpret(for EBM)xgboost(optional)rpy2(for R–Python integration)
R packages (via rpy2):
betaregstats
-
Data preparation
Rundata_processing.pyto generate a clean dataset with engineered features. -
LGD modelling
Runlgd_modeling.pyto:- Train EBM and Beta Regression models.
- Compare predictive and statistical performance.
- Generate plots and diagnostics.
- Design and methodology were fully developed by the author.
- Code implementation was supported with AI assistance:
- Claude (Anthropic): keyword expansion for job–industry classification.
- ChatGPT (OpenAI): coding support, documentation structuring, and simplifications.
- All outputs and modelling decisions were critically reviewed and validated by the author.
Special thanks to:
-
Professor Gianluca Fusai (City St Georges, University of London) —
For insightful discussions on loss modeling and constructive feedback on the approach. -
Mr. Massimo Liquori (BDO) For practical guidance on risk model validation and valuable comments that improved the robustness of the implementation.
Gael Chen
Project: From Machine Learning to Statistical Rigor: A Hybrid Framework for LGD Estimation
Date: September 2025