Loan Data Machine Learning Model

Keegan Fernandes
3 min readAug 16, 2021

--

Photo by Frederick Warren on Unsplash

The data for this project can be found here. The goal of this project was to make a model that could predict whether a customer taking a loan would default on his debt. As with all my data projects, I started by making an EDA. I wanted to use deep learning for the modeling process. I started by making a Logistic Regression model as a baseline and got poor results. I then made a Feed-Forward neural network with one hidden layer and obtained slightly better results. With each hidden layer, I added the model managed to obtain slightly better results, however; it didn't converge. After looking online, I found no method to classify tabular data with deep learning. Adding additional nodes would mean that the model would eventually converge. However, after adding eleven hidden layers and seeing no major improvements, I decided to use an XGBoost Classifier and got a 92% accuracy.

Satisfied with the result, I proceeded to make an app using streamlit after saving the model as a pickle.

import streamlit as st
import pandas as pd
import pickle
st.markdown("""#Loan Qualification""")
progress = st.progress(0)
model = pickle.load(open("Model_For_Deployment.sav","rb"))
features = []
features.append(st.text_input(label = "Interest Rate" , value = 0.5))features.append(st.text_input(label = "Installment : The monthly installments owed by the borrower if the loan is funded" , value = 100))features.append(st.text_input(label = "Log.Annual.Inc: The natural log of the self-reported annual income of the borrower." , value = 10))features.append(st.text_input(label = "DTI: The debt-to-income ratio of the borrower (amount of debt divided by annual income)." , value = 0.5))features.append(st.text_input(label = "FICO :" , value = 500))features.append(st.text_input(label = "Days.with.cr.line : The number of days the borrower has had a credit line." , value = 1000))features.append(st.text_input(label = "Revol.bal: The borrower's revolving balance (amount unpaid at the end of the credit card billing cycle)" , value = 5))features.append(st.text_input(label = "Revol.util: The borrower's revolving line utilization rate (the amount of the credit line used relative to total credit available)" , value = 5))features.append(st.text_input(label = " The borrower's number of inquiries by creditors in the last 6 months" , value = 5))features.append(st.text_input(label = "The number of times the borrower had been 30+ days past due on a payment in the past 2 years." , value = 0))features.append(st.text_input(label = "The borrower's number of derogatory public records (bankruptcy filings, tax liens, or judgments)" , value = 0))X = pd.DataFrame({
"1" : [features[0]],
"2" : [features[1]],
"3" : [features[2]],
"4" : [features[3]],
"5" : [features[4]],
"6" : [features[5]],
"7" : [features[6]],
"8" : [features[7]],
"9" : [features[8]],
"10" : [features[9]],
"11" : [features[10]],
})
progress.progress(100)
if st.button("Submit"):
prediction = model.predict(X)[0]
if prediction == 0:
st.warning("Sorry you won't be able to acquire a loan")
else:
st.success("Congratulations!! You are eligible for a loan.")

It’s a bare bones app but hey it works. I had a lot of fun making this app and have many more ideas thanks for reading this far 😊.

--

--

Keegan Fernandes
Keegan Fernandes

Written by Keegan Fernandes

First year student in Msc Data Science. Writes about data science and machine learning tutorials and the impact it has on the world.

No responses yet