A production-grade credit risk modeling framework designed to calculate and predict Expected Credit Loss (ECL) in accordance with Basel II/III and IFRS 9 / Ind AS 109 financial reporting standards.
This repository implements a dual-layer risk evaluation pipeline trained on over 2.2 Million historical loan records, optimizing default boundaries while mitigating class imbalances and multi-collinear data leakage.
You can access and test the live interactive ECL Scenario Simulator here: 👉 Live Expected Credit Loss Calculator (Streamlit Sharing) (Note: If you customize your Streamlit subdomain during deployment, please update this link in your repository!)
Note
Portfolio Project Notice (Version 1.0.0): This project is structured as an iterative portfolio engine to showcase end-to-end data pipeline construction, statistical model building, and dynamic web deployment. As Version 1.0.0, it establishes the core predictive foundation. Subsequent releases will focus on advanced feature engineering, macroeconomic overlays, and reject inference models on the rejected applicant dataset.
To keep the repository clean and structured, the project is divided into dedicated notebooks representing sequential stages of the project lifecycle:
├── ECL_prediction/
│ ├── .gitignore # Standard and data-science specific git exclusions
│ ├── README.md # Detailed project documentation and guide
│ ├── requirements.txt # Project dependency definitions
│ │
│ ├── Data_Ingestion_and_Exploration.ipynb # Step 01: Raw data acquisition via Kaggle & EDA scrap work
│ ├── ECL_Prediction_Pipeline.ipynb # Step 02: Core model building, feature trimming, and evaluation
│ │
│ ├── app/
│ │ ├── app.py # Streamlit interactive scenario simulator dashboard
│ │ ├── ensemble_pd_model.joblib # Saved model (Generated post-training)
│ │ ├── label_encoders.joblib # Saved label encoders (Generated post-training)
│ │ └── optimized_features.joblib # Saved feature lists (Generated post-training)
- Data_Ingestion_and_Exploration.ipynb: Handles automated dependency setup, Kaggle dataset downloading, file unpacking, and initial exploration of LendingClub's raw 150+ telemetry parameters.
- ECL_Prediction_Pipeline.ipynb: The core machine learning engine. It covers target engineering, imputation, class imbalance solutions, model training (Random Forest + HistGradientBoosting ensemble), Permutation Feature Importance, feature reduction (down to 11 high-value features), and ECL matrix forecasting.
The standard regulatory risk equation for Expected Credit Loss is defined as:
- Probability of Default (PD): Modeled using a soft-voting ensemble of
RandomForestClassifierandHistGradientBoostingClassifier. Class imbalance is penalized dynamically (class_weight='balanced') to prevent the model from ignoring default cases (raising default recall from 0.00 to institutional standards). - Loss Given Default (LGD): Modeled empirically based on historical recovery matrices, standardized at a standard institutional 80% loss rate post-default.I will look forward to be more precise in the further versions for these 2 features.2
- Exposure at Default (EAD): Modeled directly as the active outstanding loan capital (
loan_amnt).
After executing our validation engine against the testing portfolio, the framework generated the following financial provision metrics:
-
Total Outstanding Portfolio Exposure (EAD):
$6,759,057,350.00 -
Total Required Capital Risk Provisions (ECL):
$2,426,929,066.38 -
Portfolio Risk Provision Ratio:
35.91% -
Validation Performance: Achieved a highly stable, generalized 0.7060 ROC-AUC validation score and 73% general accuracy despite stripping out highly collinear variables like
int_rate,loan_amnt, andannual_inc.
Clone the repository and install the required dependencies:
git clone https://github.com/b25cs1051-KUSH/ECL-Prediction-Machine.git
cd ECL-Prediction-Machine
pip install -r requirements.txtThe model relies on the LendingClub dataset. You can download it automatically through the first notebook or run the following Kaggle API commands:
pip install kaggle
kaggle datasets download -d wordsforthewise/lending-club --unzipNote: Place the
accepted_2007_to_2018Q4.csv.gzfile directly into the repository root. All data files are excluded in.gitignoreto prevent committing gigabyte-scale datasets.
Open the main pipeline notebook ECL_Prediction_Pipeline.ipynb in Jupyter and run all cells. The final cell will train the optimized ensemble engine and serialize the artifacts:
app/ensemble_pd_model.joblibapp/label_encoders.joblibapp/optimized_features.joblib
Launch the interactive web simulator dashboard to test borrower scenarios:
streamlit run app/app.pyInteractive Calculator: The app runs in a realistic Demo Heuristic Mode by default. Once you run the training pipeline and export the joblib files, it automatically transitions into a Live ML Inference Mode, querying your actual trained model in real time!
This is Version 1.0.0 of the ECL Prediction Machine.
You may notice rejected_2007_to_2018Q4.csv.gz in the LendingClub data download. In this first version, we have focused exclusively on accepted_2007_to_2018Q4.csv.gz to model the default probability of active borrowers. Pushing rejected loans directly into this model is not feasible because they lack a target variable (they were never issued, so they could never "default" or "pay back").
However, the rejected dataset is highly valuable for the next phase:
- Reject Inference: We can model selection bias (the fact that we only train default models on borrowers who were accepted) using Heckman’s two-stage correction.
- Credit Decisioning Classifier: Training a classifier on accepted vs. rejected applications to model the bank's automated approval boundaries.
For Version 2.0, we will shift focus from pure feature exclusion to deep feature engineering:
- Bureau Telemetry Interaction: Engineering credit utilisation ratios (
revol_bal/ total credit limits) and inquiry density. - Macroeconomic Overlay: Injecting interest rate cycle indicators and GDP growth trends to model "Point-in-Time" (PIT) PD instead of purely historical "Through-the-Cycle" (TTC) PD.
- Employment Length Encoding: Converting categorical string categories into numerical representations reflecting occupational stability.
- Languages & Core: Python 3.10+, HTML, CSS
- Data Science:
pandas,numpy,scikit-learn,joblib - Exploratory Data Analysis:
ydata-profiling/fg-data-profiling - Web App: Streamlit
- Visualizations:
matplotlib,seaborn - Formulas: LaTeX / KaTeX rendering
credit-risk • machine-learning • fintech • ifrs9 • basel-iii • probability-of-default • ensemble-learning • financial-engineering • data-science
This project is licensed under the MIT License - see the LICENSE file for details.