Last active
August 29, 2015 14:26
-
-
Save tomatau/e5a2402fe1aa49654daf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import pandas as pd | |
import statsmodels.api as sm | |
import math | |
import matplotlib.pyplot as plt | |
import numpy as np | |
loansData = pd.read_csv('loansData_clean.csv') | |
loansData['IR_TF'] = loansData['Interest.Rate'] < 12 | |
loansData['intercept'] = 1.0 | |
logit = sm.Logit(loansData['IR_TF'], loansData[independentVariablesList]) | |
result = logit.fit() | |
coeff = result.params | |
print coeff | |
# multi variant? | |
# mx+b // not -b-mx-nz | |
def interest_rate(FicoScore, AmountRequested, coeff): | |
return -(coeff['intercept'] + (coeff['FICO.Score'] * FicoScore) + (coeff['Amount.Requested'] * AmountRequested)) | |
def logistic_function(FicoScore, AmountRequested, coeff): | |
return 1 / (1 + math.exp(interest_rate(FicoScore, AmountRequested, coeff))) | |
print logistic_function(750, 10000, coeff) | |
# 0.9759220629968894 | |
# 0.024077937003110648 | |
""" | |
p is > 0.7 | |
Higher FICO Score translates to more chance of getting a loan | |
with an interest rate less than 12% | |
""" | |
# plt.plot( | |
# np.linspace(550, 950, num=400), | |
# [ logistic_function(coeff, 10000, y) for y in range(550, 950) ] | |
# ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated interest rate function