Python 信用风险建模
Michael Crabtree
Data Scientist, Ford Motor Company
# 选择部分特定列
X_multi = cr_loan_prep[['loan_int_rate','person_emp_length']]
# 选择除 loan_status 外的所有数据
X = cr_loan_prep.drop('loan_status', axis = 1)
.get_booster() 和 .get_score() 方法# 训练模型
clf_gbt.fit(X_train,np.ravel(y_train))
# 打印特征重要性
clf_gbt.get_booster().get_score(importance_type = 'weight')
{'person_home_ownership_RENT': 1, 'person_home_ownership_OWN': 2}
# importance_type = 'weight' 的列重要性
{'person_home_ownership_RENT': 1, 'person_home_ownership_OWN': 2}
plot_importance() 函数xgb.plot_importance(clf_gbt, importance_type = 'weight')
{'person_income': 315, 'loan_int_rate': 195, 'loan_percent_income': 146}
| 列 | 重要性 | 模型准确率 | 模型违约召回率 |
|---|---|---|---|
| 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 |
classification_report() 中显示Python 信用风险建模