开始使用免费开始使用

信用模型的可视化评估

现在,您希望将模型的性能可视化。在 ROC 图中,X 轴和 Y 轴分别是您已经见过的两个指标:假阳性率(fall-out)和真正率(sensitivity)。

您可以使用以下代码绘制其 ROC 图:

fallout, sensitivity, thresholds = roc_curve(y_test, prob_default)
plt.plot(fallout, sensitivity)

要计算 AUC 分数,请使用 roc_auc_score()

信用数据集 cr_loan_prep 以及数据集 X_testy_test 已加载到工作区中。已训练好的 LogisticRegression() 模型 clf_logistic 也已加载到工作区。

本练习是课程的一部分

Python 信用风险建模

查看课程

练习说明

  • 为违约概率创建一组预测,存入 preds
  • 打印模型在测试集 Xy 上的准确率分数。
  • 在测试数据和违约概率上使用 roc_curve() 生成 falloutsensitivity,然后以 fallout 为 x 轴绘制 ROC 曲线。
  • 使用测试数据和违约概率计算模型的 AUC,并将其存入 auc

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Create predictions and store them in a variable
____ = clf_logistic.____(____)

# Print the accuracy score the model
print(clf_logistic.____(____, ____))

# Plot the ROC curve of the probabilities of default
prob_default = preds[:, 1]
fallout, sensitivity, thresholds = ____(____, ____)
plt.plot(fallout, sensitivity, color = 'darkorange')
plt.plot([0, 1], [0, 1], linestyle='--')
plt.____()

# Compute the AUC and store it in a variable
____ = ____(____, ____)
编辑并运行代码