开始使用免费开始使用

接受率

设定接受率并计算相应阈值,可以用来控制您希望放行的新贷款比例。本练习中,假设测试数据是一批全新的贷款。您需要使用 numpy 中的 quantile() 函数来计算该阈值。

应使用该阈值为新的 loan_status 赋值。数据中的违约与非违约数量会发生变化吗?

已经为您提供训练好的模型 clf_gbt,以及其预测结果的数据框 test_pred_df

本练习是课程的一部分

Python 信用风险建模

查看课程

练习说明

  • 使用 .describe() 打印预测结果数据框中 prob_default 的汇总统计。
  • 使用 quantile() 计算 85% 接受率对应的阈值,并保存为 threshold_85
  • 基于 threshold_85 新建一列 pred_loan_status
  • 打印 pred_loan_status 中新取值的计数。

交互式实操练习

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

# Check the statistics of the probabilities of default
print(____[____].describe())

# Calculate the threshold for a 85% acceptance rate
____ = np.____(____['prob_default'], ____)

# Apply acceptance rate threshold
____[____] = ____[____].apply(lambda x: 1 if x > ____ else 0)

# Print the counts of loan status after the threshold
print(____[____].____())
编辑并运行代码