欄位重要性與違約預測
當你使用多個訓練集,且每個訓練集包含不同群組的欄位時,留意哪些欄位有影響、哪些沒有,非常重要。即使某些欄位對 loan_status 沒有任何影響,維護這些欄位仍可能代價高或耗時。
本練習的 X 資料是用以下程式碼建立的:
X = cr_loan_prep[['person_income','loan_int_rate',
'loan_percent_income','loan_amnt',
'person_home_ownership_MORTGAGE','loan_grade_F']]
請在這份資料上訓練一個 XGBClassifier() 模型,並檢查欄位重要性,看看各欄位對預測 loan_status 的貢獻。
cr_loan_pret 資料集與 X_train、y_train 已載入工作空間。
本練習屬於課程
以 Python 進行信用風險建模
練習說明
- 建立一個
XGBClassifier()模型,並在X_train與y_train訓練集上進行訓練,將結果儲存為clf_gbt。 - 透過
.get_booster()與.get_score()列印clf_gbt中各欄位的重要性。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create and train the model on the training data
____ = xgb.____().____(____,np.ravel(____))
# Print the column importances from the model
print(clf_gbt.____().____(importance_type = 'weight'))