信用風險的欄位選擇

以 Python 進行信用風險建模

Michael Crabtree

Data Scientist, Ford Motor Company

選擇特定欄位

  • 我們一直用所有欄位來做預測
# Selects a few specific columns
X_multi = cr_loan_prep[['loan_int_rate','person_emp_length']]
# Selects all data except loan_status
X = cr_loan_prep.drop('loan_status', axis = 1)
  • 如何判斷各欄位的重要性
    • 邏輯斯回歸:欄位係數
    • 梯度加速樹:?
以 Python 進行信用風險建模

欄位重要性

  • 使用 .get_booster().get_score() 方法
    • Weight:欄位在所有樹中出現的次數
# Train the model
clf_gbt.fit(X_train,np.ravel(y_train))
# Print the feature importances
clf_gbt.get_booster().get_score(importance_type = 'weight')
{'person_home_ownership_RENT': 1, 'person_home_ownership_OWN': 2}
以 Python 進行信用風險建模

解讀欄位重要性

# Column importances from importance_type = 'weight'
{'person_home_ownership_RENT': 1, 'person_home_ownership_OWN': 2}

使用 XGBoost 的決策樹

以 Python 進行信用風險建模

繪製欄位重要性

  • 使用 plot_importance() 函式
xgb.plot_importance(clf_gbt, importance_type = 'weight')
{'person_income': 315, 'loan_int_rate': 195, 'loan_percent_income': 146}

特徵重要性圖

以 Python 進行信用風險建模

選擇訓練欄位

  • 欄位重要性可用來決定訓練要用哪些欄位
  • 不同欄位組合會影響模型表現
Columns Importances Model Accuracy Model Default Recall
loan_int_rate, person_emp_length (100, 100) 0.81 0.67
loan_int_rate, person_emp_length, loan_percent_income (98, 70, 5) 0.84 0.52
以 Python 進行信用風險建模

模型的 F1 評分

  • 比較不同欄位組的準確率與召回率很費時
  • F1 分數是一個同時兼顧準確率與召回率的指標

F1 分數公式

  • 會出現在 classification_report() 的一部分

含 F1 分數標示的分類報告

以 Python 進行信用風險建模

一起來練習吧!

以 Python 進行信用風險建模

Preparing Video For Download...