Predictive Modeling & Analytics on Home Equity Line of Credit

Overview

Predictive Modeling & Analytics on Home Equity Line of Credit Data (Python)

HMEQ Data Set

In this assignment we will use Python to examine a data set containing Home Equity Loans. The data set contains two target variables. The first target, TARGET_BAD_FLAG indicates whether or not the loan defaulted. If the value is set to 1, then the loan went bad and the bank lost money. If the value is set to 0, the loan was repaid.

The second target, TARGET_LOSS_AMT, indicates the amount of money that was lost for loans that went bad. The remaining variables contain information about the customer at the time that the loan was issued.

This is the data that we will use throughout this class in order to develop predictive models that will be used to determine the level of risk for each loan.

As with all real world data, this data is far from perfect.

It contains both numerical and categorical variables. It contains missing data. It contains outliers.

Table of Contents

  • Data Preparation
  • Tree Based Models
  • Regression Based Models
  • Neural Network

Building Machine Learning Models

Developed different predictive models to determine the level risk of each loan based on whether or not loans defaulted, and loss amount on bad loans. Evaluated each model with ROC curve and RMSE accuracy metrics.

Data Preparation

  • Download the HMEQ Data set
  • Read the data into Python
  • Explore both the input and target variables using statistical techniques.
  • Explore both the input and target variables using graphs and other visualization.
  • Look for relationships between the input variables and the targets.
  • Fix (impute) all missing data.
  • Note: For numerical data, create a flag variable to indicate if the value was missing
  • Convert all categorical variables numeric variables

Tree Based Models

We will continue to use Python to develop predictive models. In this assignment, we will use three different tree based techniques to analyze the data: DECISION TREES, RANDOM FORESTS, and GRADIENT BOOSTING. The deliverables for each technique are given below.

Create a Training and Test Data Set:

Decision Trees:

  • Develop a decision tree to predict the probability of default
  • Calculate the accuracy of the model on both the training and test data set
  • Create a graph that shows the ROC curves for both the training and test data set. Clearly label each curve and display the Area Under the ROC curve.
  • Display the Decision Tree using a Graphviz program
  • List the variables included in the decision tree that predict loan default.
  • Develop a decision tree to predict the loss amount assuming that the loan defaults
  • Calculate the RMSE for both the training data set and the test data set
  • Display the Decision Tree using a Graphviz program
  • List the variables included in the decision tree that predict loss amount.

Random Forests:

  • Develop a Random Forest to predict the probability of default
  • Calculate the accuracy of the model on both the training and test data set
  • Create a graph that shows the ROC curves for both the training and test data set. Clearly label each curve and display the Area Under the ROC curve.
  • List the variables included in the Random Forest that predict loan default.
  • Develop a Random Forest to predict the loss amount assuming that the loan defaults
  • Calculate the RMSE for both the training data set and the test data set
  • List the variables included in the Random Forest that predict loss amount.

Gradient Boosting:

  • Develop a Gradient Boosting model to predict the probability of default
  • Calculate the accuracy of the model on both the training and test data set
  • Create a graph that shows the ROC curves for both the training and test data set. Clearly - label each curve and display the Area Under the ROC curve.
  • List the variables included in the Gradient Boosting that predict loan default.
  • Develop a Gradient Boosting to predict the loss amount assuming that the loan defaults
  • Calculate the RMSE for both the training data set and the test data set
  • List the variables included in the Gradient Boosting that predict loss amount.

ROC Curves:

  • Generate a ROC curve for the Decision Tree, Random Forest, and Gradient Boosting models using the Test Data Set
  • Use different colors for each curve and clearly label them
  • Include the Area under the ROC Curve (AUC) on the graph.

Regression Based Models

we will continue to use Python to develop predictive models. In this assignment, we will use two different types of regression: Linear and Logistic. We will use Logistic regression to determine the probability of a crash. Linear regression will be used to calculate the damages assuming that a crash occurs

Create a Training and Test Data Set:

Logistic Regression

  • Develop a logistic regression model to determine the probability of a loan default. Use all of the variables.
  • Develop a logistic regression model to determine the probability of a loan default. Use the variables that were selected by a DECISION TREE.
  • Develop a logistic regression model to determine the probability of a loan default. Use the variables that were selected by a RANDOM FOREST.
  • Develop a logistic regression model to determine the probability of a loan default. Use the variables that were selected by a GRADIENT BOOSTING model.
  • Develop a logistic regression model to determine the probability of a loan default. Use the variables that were selected by STEPWISE SELECTION.
  • For each of the models
    • Calculate the accuracy of the model on both the training and test data set
    • Create a graph that shows the ROC curves for both the training and test data set. Clearly label each curve and display the Area Under the ROC curve.
    • Display a ROC curve for the test data with all your models on the same graph (tree based and regression). Discuss which one is the most accurate. Which one would you recommend using?
    • For one of the Regression Models, print the coefficients. Do the variables make sense? If not, what would you recommend?

Linear Regression:

  • Develop a linear regression model to determine the expected loss if the loan defaults. Use all of the variables.
  • Develop a linear regression model to determine the expected loss if the loan defaults. Use the variables that were selected by a DECISION TREE.
  • Develop a linear regression model to determine the expected loss if the loan defaults. Use the variables that were selected by a RANDOM FOREST.
  • Develop a linear regression model to determine the expected loss if the loan defaults. Use the variables that were selected by a GRADIENT BOOSTING model.
  • Develop a linear regression model to determine the expected loss if the loan defaults. Use the variables that were selected by STEPWISE SELECTION.
  • For each of the models
    • Calculate the RMSE for both the training data set and the test data set
    • List the RMSE for the test data set for all of the models created (tree based and regression). Discuss which one is the most accurate. Which one would you recommend using?
    • For one of the Regression Models, print the coefficients. Do the variables make sense? If not, what would you recommend?

Neural Networks

we will continue to use Python to develop predictive models. In this assignment, we will use two different types of regression: Linear and Logistic. We will use Logistic regression to determine the probability of a crash. Linear regression will be used to calculate the damages assuming that a crash occurs.

Create a Training and Test Data Set:

Tensor Flow Model To Predict Loan Defaults:

  • Develop a model using Tensor Flow that will predict Loan Default.

    • For your model, do the following:
    • Try at least three different Activation Functions
    • Try one and two hidden layers
    • Try using a Dropout Layer
  • Explore using a variable selection technique

  • For each of the models

    • Calculate the accuracy of the model on both the training and test data set
    • Create a graph that shows the ROC curves for both the training and test data set.
    • Clearly label each curve and display the Area Under the ROC curve.
    • Display a ROC curve for the test data with all your models on the same graph (tree based, regression, and TF). Discuss which one is the most accurate. Which one would you recommend using?

Tensor Flow Model to Predict Loss Given Default:

  • Develop a model using Tensor Flow that will predict Loan Default.
  • For your model, do the following:
    • Try at least three different Activation Functions
    • Try one and two hidden layers
    • Try using a Dropout Layer
  • Explore using a variable selection technique
  • For each of the models
    • Calculate the RMSE for both the training data set and the test data set
    • List the RMSE for the test data set for all of the models created (tree based, regression, and TF). Discuss which one is the most accurate. Which one would you recommend using?

Data Dictionary

VARIABLE DEFINITION ROLE TYPE CONVENTIONAL WISDOM
TARGET_BAD_FLAG BAD=1 (Loan was defaulted) TARGET BINARY HMEQ = Home Equity Line of Credit Loan. BINARY TARGET
TARGET_LOSS_AMT If loan was Bad, this was the amount not repaid. TARGET NUMBER HMEQ = Home Equity Line of Credit Loan. NUMERICAL TARGET
LOAN HMEQ Credit Line INPUT NUMBER The bigger the loan, the more risky the person
MORTDUE Current Outstanding Mortgage Balance INPUT NUMBER If you owe a lot of money on your current mortgage versus the value of your house, you are more risky.
VALUE Value of your house INPUT NUMBER If you owe a lot of money on your current mortgage versus the value of your house, you are more risky.
REASON Why do you want a loan? INPUT CATEGORY If you are consolidating debt, that might mean you are having financial trouble.
JOB What do you do for a living? INPUT CATEGORY Some jobs are unstable (and therefore are more risky)
YOJ Years on Job INPUT NUMBER If you habe been at your job for a while, you are less likely to lose that job. That makes you less risky.
DEROG Derogatory Marks on Credit Record. These are very bad things that stay on your credit report for 7 years. These include bankruptcies or leins placed on your property. INPUT NUMBER Lots of Derogatories mean that something really bad happened to you (such as a bankruptcy) in your past. This makes you more risky.
DELINQ Delinquencies on your current credit report. This refers to the number of times you were overdue when paying bills in the last three years. INPUT NUMBER When you have a lot of delinquencies, you might be more likely to default on a loan.
CLAGE Credit Line Age (in months) is how long you have had credit. Are you a new high school student with a new credit card or have you had credit cards for many years? INPUT NUMBER If you have had credit for a long time, you are considered less risky than a new high school student.
NINQ Number of inquiries. This is the number of times within the last 3 years that you went out looking for credit (such as opening a credit card at a store) INPUT NUMBER Conventional wisdom in that if you are looking for more credit, you might be in financial trouble. Thus you are risky.
CLNO Number of credit lines you have (credit cards, loans, etc.). INPUT NUMBER This is a double edged swoard. Peole who have a lot of credit lines tend to be safe. The reason is that if OTHER PEOPLE think you are trustworthy enough for a credit card, then maybe you are. However, if you have too many credit lines, you might be risky because you have the potential to run up a lot of debt.
DEBTINC Debt to Income Ratio. Take the money you spend every month and divide it by the amount of money you earn every month. INPUT NUMBER If your debt to income ratio is high then you are risky because you might not be able to pay your bills.
Owner
Dhaval Patel
Dhaval Patel
Toolchest provides APIs for scientific and bioinformatic data analysis.

Toolchest Python Client Toolchest provides APIs for scientific and bioinformatic data analysis. It allows you to abstract away the costliness of runni

Toolchest 11 Jun 30, 2022
Shot notebooks resuming the main functions of GeoPandas

Shot notebooks resuming the main functions of GeoPandas, 2 notebooks written as Exercises to apply these functions.

1 Jan 12, 2022
CS50 pset9: Using flask API to create a web application to exchange stocks' shares.

C$50 Finance In this guide we want to implement a website via which users can “register”, “login” “buy” and “sell” stocks, like below: Background If y

1 Jan 24, 2022
SparseLasso: Sparse Solutions for the Lasso

SparseLasso: Sparse Solutions for the Lasso Introduction SparseLasso provides a Scikit-Learn based estimation of the Lasso with cross-validation tunin

Gabriel Okasa 1 Nov 08, 2021
Data pipelines built with polars

valves Warning: the project is very much work in progress. Valves is a collection of functions for your data .pipe()-lines. This project aimes to host

14 Jan 03, 2023
Pizza Orders Data Pipeline Usecase Solved by SQL, Sqoop, HDFS, Hive, Airflow.

PizzaOrders_DataPipeline There is a Tony who is owning a New Pizza shop. He knew that pizza alone was not going to help him get seed funding to expand

Melwin Varghese P 4 Jun 05, 2022
Implementation in Python of the reliability measures such as Omega.

OmegaPy Summary Simple implementation in Python of the reliability measures: Omega Total, Omega Hierarchical and Omega Hierarchical Total. Name Link O

Rafael Valero Fernández 2 Apr 27, 2022
Automated Exploration Data Analysis on a financial dataset

Automated EDA on financial dataset Just a simple way to get automated Exploration Data Analysis from financial dataset (OHLCV) using Streamlit and ta.

Darío López Padial 28 Nov 27, 2022
Show you how to integrate Zeppelin with Airflow

Introduction This repository is to show you how to integrate Zeppelin with Airflow. The philosophy behind the ingtegration is to make the transition f

Jeff Zhang 11 Dec 30, 2022
wikirepo is a Python package that provides a framework to easily source and leverage standardized Wikidata information

Python based Wikidata framework for easy dataframe extraction wikirepo is a Python package that provides a framework to easily source and leverage sta

Andrew Tavis McAllister 35 Jan 04, 2023
InDels analysis of CRISPR lines by NGS amplicon sequencing technology for a multicopy gene family.

CRISPRanalysis InDels analysis of CRISPR lines by NGS amplicon sequencing technology for a multicopy gene family. In this work, we present a workflow

2 Jan 31, 2022
A Python package for modular causal inference analysis and model evaluations

Causal Inference 360 A Python package for inferring causal effects from observational data. Description Causal inference analysis enables estimating t

International Business Machines 506 Dec 19, 2022
Parses data out of your Google Takeout (History, Activity, Youtube, Locations, etc...)

google_takeout_parser parses both the Historical HTML and new JSON format for Google Takeouts caches individual takeout results behind cachew merge mu

Sean Breckenridge 27 Dec 28, 2022
Calculate multilateral price indices in Python (with Pandas and PySpark).

IndexNumCalc Calculate multilateral price indices using the GEKS-T (CCDI), Time Product Dummy (TPD), Time Dummy Hedonic (TDH), Geary-Khamis (GK) metho

Dr. Usman Kayani 3 Apr 27, 2022
Includes all files needed to satisfy hw02 requirements

HW 02 Data Sets Mean Scale Score for Asian and Hispanic Students, Grades 3 - 8 This dataset provides insights into the New York City education system

7 Oct 28, 2021
Sample code for Harry's Airflow online trainng course

Sample code for Harry's Airflow online trainng course You can find the videos on youtube or bilibili. I am working on adding below things: the slide p

102 Dec 30, 2022
Bamboolib - a GUI for pandas DataFrames

Community repository of bamboolib bamboolib is joining forces with Databricks. For more information, please read our announcement. Please note that th

Tobias Krabel 863 Jan 08, 2023
Code for the DH project "Dhimmis & Muslims – Analysing Multireligious Spaces in the Medieval Muslim World"

Damast This repository contains code developed for the digital humanities project "Dhimmis & Muslims – Analysing Multireligious Spaces in the Medieval

University of Stuttgart Visualization Research Center 2 Jul 01, 2022
The micro-framework to create dataframes from functions.

The micro-framework to create dataframes from functions.

Stitch Fix Technology 762 Jan 07, 2023
Very basic but functional Kakuro solver written in Python.

kakuro.py Very basic but functional Kakuro solver written in Python. It uses a reduction to exact set cover and Ali Assaf's elegant implementation of

Louis Abraham 4 Jan 15, 2022