การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python
Michael Crabtree
Data Scientist, Ford Motor Company
prob_defaultloan_status ที่พยากรณ์ได้preds_df['loan_status'] = preds_df['prob_default'].apply(lambda x: 1 if x > 0.4 else 0)
| Loan | prob_default | threshold | loan_status |
|---|---|---|---|
| 1 | 0.25 | 0.4 | 0 |
| 2 | 0.42 | 0.4 | 1 |
| 3 | 0.75 | 0.4 | 1 |
prob_default ต่ำที่สุดimport numpy as np
# Compute the threshold for 85% acceptance rate
threshold = np.quantile(prob_default, 0.85)
0.804
| Loan | prob_default |
Threshold | Predicted loan_status |
Accept or Reject |
|---|---|---|---|---|
| 1 | 0.65 | 0.804 | 0 | Accept |
| 2 | 0.85 | 0.804 | 1 | Reject |
loan_status ใหม่โดยใช้ threshold ที่คำนวณได้# Compute the quantile on the probabilities of default
preds_df['loan_status'] = preds_df['prob_default'].apply(lambda x: 1 if x > 0.804 else 0)
prob_default อยู่ในช่วงที่โมเดลยังปรับเทียบได้ไม่ดี#Calculate the bad rate
np.sum(accepted_loans['true_loan_status']) / accepted_loans['true_loan_status'].count()
0 และ default คือ 1 แล้ว sum() จะเป็นจำนวนนับของการผิดนัด.count() ของคอลัมน์เดียวเท่ากับจำนวนแถวทั้งหมดของ data frameการสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python