信用风险的列选择

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)
  • 如何判断各列的重要性
    • 逻辑回归:列系数
    • 梯度提升树:?
Python 信用风险建模

列重要性

  • 使用 .get_booster().get_score() 方法
    • weight:该列在所有树中出现的次数
# 训练模型
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}
Python 信用风险建模

解读列重要性

# 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 信用风险建模

选择训练列

  • 列重要性可用于选择训练用列
  • 不同列集会影响模型表现
重要性 模型准确率 模型违约召回率
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 信用风险建模

Passons à la pratique !

Python 信用风险建模

Preparing Video For Download...