Pemodelan Risiko Kredit dengan Python
Michael Crabtree
Data Scientist, Ford Motor Company
# Intersep model
array([-3.30582292e-10])
# Koefisien untuk ['loan_int_rate','person_emp_length','person_income']
array([[ 1.28517496e-09, -2.27622202e-09, -2.17211991e-05]])
# Menghitung probabilitas gagal bayar
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)))
# Intersep
intercept = -1.02
# Koefisien untuk lama bekerja
person_emp_length_coef = -0.056
person_emp_length menurunkan peluang gagal bayar# Intersep
intercept = -1.02
# Koefisien untuk lama bekerja
person_emp_length_coef = -0.056
person_emp_length menurunkan peluang gagal bayar| intercept | 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 |
Numerik: loan_int_rate, person_emp_length, person_income
Non-numerik:
cr_loan_clean['loan_intent']
EDUCATION
MEDICAL
VENTURE
PERSONAL
DEBTCONSOLIDATION
HOMEIMPROVEMENT
0 atau 1 di kolom baru column_VALUEget_dummies() di pandas# Pisahkan kolom numerik
cred_num = cr_loan.select_dtypes(exclude=['object'])
# Pisahkan kolom non-numerik
cred_cat = cr_loan.select_dtypes(include=['object'])
# One-hot encode hanya kolom non-numerik
cred_cat_onehot = pd.get_dummies(cred_cat)
# Gabungkan kolom numerik dengan kolom hasil one-hot
cr_loan = pd.concat([cred_num, cred_cat_onehot], axis=1)
.predict_proba() di scikit-learn# Latih model
clf_logistic.fit(X_train, np.ravel(y_train))
# Prediksi dengan model
clf_logistic.predict_proba(X_test)
# Probabilitas: [[tidak gagal bayar, gagal bayar]]
array([[0.55, 0.45]])
Pemodelan Risiko Kredit dengan Python