ประสิทธิภาพของโมเดลสินเชื่อ

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

Michael Crabtree

Data Scientist, Ford Motor Company

การวัดความแม่นยำของโมเดล

  • คำนวณความแม่นยำ

สูตรคำนวณความแม่นยำ

  • ใช้เมธอด .score() จาก scikit-learn
# Check the accuracy against the test data
clf_logistic1.score(X_test,y_test)
0.81
  • ทำนายค่า loan_status ได้ถูกต้อง 81%
การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

กราฟ ROC curve

  • Receiver Operating Characteristic curve
    • พล็อตอัตรา true positive (sensitivity) เทียบกับอัตรา false positive (fall-out)
fallout, sensitivity, thresholds = roc_curve(y_test, prob_default)
plt.plot(fallout, sensitivity, color = 'darkorange')

ตัวอย่างกราฟ ROC

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

การวิเคราะห์กราฟ ROC

  • Area Under Curve (AUC): พื้นที่ระหว่างเส้นโค้งกับการทำนายแบบสุ่ม

ตัวอย่างกราฟ ROC พร้อมคำอธิบาย lift และ AUC

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

Threshold ของการผิดนัดชำระ

  • Threshold: จุดที่ค่าความน่าจะเป็นถูกจัดว่าเป็นการผิดนัดชำระ

แผนภาพแสดง probability threshold

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

การกำหนด threshold

  • กำหนดป้ายกำกับสินเชื่อใหม่โดยใช้ threshold ที่ 0.5
preds = clf_logistic.predict_proba(X_test)
preds_df = pd.DataFrame(preds[:,1], columns = ['prob_default'])
preds_df['loan_status'] = preds_df['prob_default'].apply(lambda x: 1 if x > 0.5 else 0)

ตัวอย่างข้อมูลพร้อมค่าความน่าจะเป็นและสถานะสินเชื่อ

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

รายงานการจำแนกประเภทสินเชื่อ

  • classification_report() ใน scikit-learn
from sklearn.metrics import classification_report
classification_report(y_test, preds_df['loan_status'], target_names=target_names)

ตัวอย่าง classification report

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

การเลือก classification metrics

  • เลือกและจัดเก็บค่าเฉพาะจาก classification_report()
  • ใช้ฟังก์ชัน precision_recall_fscore_support() จาก scikit-learn

ตัวอย่าง classification report พร้อม default recall

from sklearn.metrics import precision_recall_fscore_support
precision_recall_fscore_support(y_test,preds_df['loan_status'])[1][1]
การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

มาฝึกกันเถอะ!

การสร้างโมเดลความเสี่ยงด้านเครดิตด้วย Python

Preparing Video For Download...