Skip to content

Instantly share code, notes, and snippets.

@joeleonjr
Created December 5, 2016 21:18
Show Gist options
  • Save joeleonjr/205f5667f0850b41d02a2b3ca891350a to your computer and use it in GitHub Desktop.
Save joeleonjr/205f5667f0850b41d02a2b3ca891350a to your computer and use it in GitHub Desktop.
import pandas as pd
import statsmodels.api as sm
import matplotlib
matplotlib.use('TkAgg')
import matplotlib.pyplot as plt
import numpy as np
import sys
def logit_function(x):
p = 1/(1 + np.exp(x))
return p
def logistic_function(fico_sore, loan_amount, coeff):
FICO_coeff = coeff['FICO.Score']
loan_amount_coeff = coeff['Amount.Requested']
intercept = coeff['constant']
x = intercept + FICO_coeff*fico_score + loan_amount_coeff*loan_amount
p = logit_function(x)
return p
def data_prep():
data = pd.read_csv('cleaned_loansData.csv')
data['IR_TF'] = data['Interest.Rate'].map(lambda x: 0 if x<12 else 1)
data['constant'] = float(1.0)
ind_vars = ['FICO.Score', 'Amount.Requested', 'constant']
return data, ind_vars
if __name__ == '__main__':
if len(sys.argv) != 3:
print("Please input a FICO Score and Loan Amount")
sys.exit()
else:
try:
fico_score = float(sys.argv[1])
loan_amount = float(sys.argv[2])
data, ind_vars = data_prep()
logit = sm.Logit(data['IR_TF'], data[ind_vars])
result = logit.fit()
coeff = result.params
p = logistic_function(fico_score, loan_amount, coeff)
print('The probability that you will get a loan from Lending Club with a FICO score of ' + str(fico_score) + ' and a loan amount of $' +
str(loan_amount) + ' is: ' + str(p*100) + '%.')
plt.figure(figsize=(6,6))
plt.plot(p)
plt.show()
except ValueError:
print("Please enter a number for both the FICO Score and Loan Amount")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment