接受率的影响
现在,请查看每笔贷款的 loan_amnt,以了解不同接受率对投资组合的影响。您可以在新的贷款集合 X_test 上,使用带有计算值(如平均贷款金额)的交叉表。为此,您将把每个数量乘以平均的 loan_amnt 值。
在打印这些数值时,尝试按货币格式显示,使数字更贴近实际。毕竟,信用风险与资金直接相关。可以使用以下代码实现:
pd.options.display.float_format = '${:,.2f}'.format
工作区中已加载预测数据框 test_pred_df,其中包含来自 X_test 的 loan_amnt 列。
本练习是课程的一部分
Python 信用风险建模
练习说明
- 使用
.describe()打印loan_amnt列的汇总统计信息。 - 计算
loan_amnt的平均值,并存为avg_loan。 - 将
pandas的显示格式设置为'${:,.2f}'。 - 打印真实贷款状态与预测贷款状态的交叉表,并将每个单元格数值乘以
avg_loan。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Print the statistics of the loan amount column
print(____[____].____())
# Store the average loan amount
____ = np.____(____[____])
# Set the formatting for currency, and print the cross tab
pd.options.display.float_format = ____.format
print(pd.____(____[____],
____[____]).apply(lambda x: x * ____, axis = 0))