接受率
设定接受率并计算相应阈值,可以用来控制您希望放行的新贷款比例。本练习中,假设测试数据是一批全新的贷款。您需要使用 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(____[____].____())