比较模型报告
您已经使用了逻辑回归模型和梯度提升树。现在是比较这两个模型、决定哪个用于最终预测的时候了。
比较不同模型预测违约概率能力的一个简单起点,是查看它们在 classification_report() 中的指标。借助该报告,您可以并排查看每个模型的多种评分指标。由于数据和模型通常是不平衡的,违约样本较少,请先关注违约类别的各项指标。
已将训练好的模型 clf_logistic 和 clf_gbt 载入工作区,并提供了它们的预测结果 preds_df_lr 和 preds_df_gbt。两者均使用了 0.4 的阈值。测试集 y_test 也可用。
本练习是课程的一部分
Python 信用风险建模
练习说明
- 打印逻辑回归预测的
classification_report()。 - 打印梯度提升树预测的
classification_report()。 - 使用
precision_recall_fscore_support()打印逻辑回归的 F-1 分数的macro average。 - 使用
precision_recall_fscore_support()打印梯度提升树的 F-1 分数的macro average。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Print the logistic regression classification report
target_names = ['Non-Default', 'Default']
print(____(____, ____['loan_status'], target_names=target_names))
# Print the gradient boosted tree classification report
print(____(____, ____['loan_status'], target_names=target_names))
# Print the default F-1 scores for the logistic regression
print(____(____,____['loan_status'], average = 'macro')[2])
# Print the default F-1 scores for the gradient boosted tree
print(____(____,____['loan_status'], average = 'macro')[2])