การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python
Michael Crabtree
Data Scientist, Ford Motor Company
loan_status คือคลาสต่างๆ01y_train['loan_status'].value_counts()
| loan_status | จำนวนในชุดข้อมูล Training | เปอร์เซ็นต์รวม |
|---|---|---|
| 0 | 13,798 | 78% |
| 1 | 3,877 | 22% |
xgboost ใช้ฟังก์ชันการสูญเสียแบบ log-loss| สถานะสินเชื่อจริง | ความน่าจะเป็นที่พยากรณ์ | Log Loss |
|---|---|---|
| 1 | 0.1 | 2.3 |
| 0 | 0.9 | 2.3 |
| บุคคล | วงเงินสินเชื่อ | กำไรที่คาดได้ | สถานะที่พยากรณ์ | สถานะจริง | ความสูญเสีย |
|---|---|---|---|---|---|
| A | $1,000 | $10 | ผิดนัด | ไม่ผิดนัด | -$10 |
| B | $1,000 | $10 | ไม่ผิดนัด | ผิดนัด | -$1,000 |
| วิธีการ | ข้อดี | ข้อเสีย |
|---|---|---|
| รวบรวมข้อมูลเพิ่มเติม | เพิ่มจำนวนการผิดนัด | สัดส่วนการผิดนัดอาจไม่เปลี่ยนแปลง |
| ปรับโทษโมเดล | เพิ่ม recall สำหรับการผิดนัด | โมเดลต้องการการปรับแต่งมากขึ้น |
| สุ่มตัวอย่างข้อมูลต่างออกไป | ปรับแต่งทางเทคนิคน้อยที่สุด | ข้อมูลการผิดนัดลดลง |
loan_status จริง# Concat the training sets
X_y_train = pd.concat([X_train.reset_index(drop = True),
y_train.reset_index(drop = True)], axis = 1)
# Get the counts of defaults and non-defaults
count_nondefault, count_default = X_y_train['loan_status'].value_counts()
# Separate nondefaults and defaults
nondefaults = X_y_train[X_y_train['loan_status'] == 0]
defaults = X_y_train[X_y_train['loan_status'] == 1]
# Undersample the non-defaults using sample() in pandas
nondefaults_under = nondefaults.sample(count_default)
# Concat the undersampled non-defaults with the defaults
X_y_train_under = pd.concat([nondefaults_under.reset_index(drop = True),
defaults.reset_index(drop = True)], axis=0)
การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python