Credit Risk Modeling in Python
Michael Crabtree
Data Scientist, Ford Motor Company
# Model Intercept
array([-3.30582292e-10])
# Coefficients for ['loan_int_rate','person_emp_length','person_income']
array([[ 1.28517496e-09, -2.27622202e-09, -2.17211991e-05]])
# Calculating probability of default
int_coef_sum = -3.3e-10 +
(1.29e-09 * loan_int_rate) + (-2.28e-09 * person_emp_length) + (-2.17e-05 * person_income)
prob_default = 1 / (1 + np.exp(-int_coef_sum))
prob_nondefault = 1 - (1 / (1 + np.exp(-int_coef_sum)))
# Intercept
intercept = -1.02
# Coefficient for employment length
person_emp_length_coef = -0.056
person_emp_length
, the person is less likely to default# Intercept
intercept = -1.02
# Coefficient for employment length
person_emp_length_coef = -0.056
person_emp_length
, the person is less likely to defaultintercept | person_emp_length | value * coef | probability of default |
---|---|---|---|
-1.02 |
10 | (10 * -0.06 ) |
.17 |
-1.02 |
11 | (11 * -0.06 ) |
.16 |
-1.02 |
12 | (12 * -0.06 ) |
.15 |
Numeric: loan_int_rate
, person_emp_length
, person_income
Non-numeric:
cr_loan_clean['loan_intent']
EDUCATION
MEDICAL
VENTURE
PERSONAL
DEBTCONSOLIDATION
HOMEIMPROVEMENT
0
or 1
in a new column column_VALUE
get_dummies()
within pandas
# Separate the numeric columns
cred_num = cr_loan.select_dtypes(exclude=['object'])
# Separate non-numeric columns
cred_cat = cr_loan.select_dtypes(include=['object'])
# One-hot encode the non-numeric columns only
cred_cat_onehot = pd.get_dummies(cred_cat)
# Union the numeric columns with the one-hot encoded columns
cr_loan = pd.concat([cred_num, cred_cat_onehot], axis=1)
.predict_proba()
method within scikit-learn# Train the model
clf_logistic.fit(X_train, np.ravel(y_train))
# Predict using the model
clf_logistic.predict_proba(X_test)
# Probabilities: [[non-default, default]]
array([[0.55, 0.45]])
Credit Risk Modeling in Python