核准率的影響
現在,請查看每筆貸款的 loan_amnt,以了解核准率對投資組合的影響。你可以在新的貸款集合 X_test 上,使用包含計算值(例如平均貸款金額)的交叉表。為此,你會將各分類的筆數乘上平均的 loan_amnt 值。
在列印這些數值時,試著使用貨幣格式,讓數字更貼近實務。畢竟,信用風險的核心就是金錢。你可以用以下程式碼達成:
pd.options.display.float_format = '${:,.2f}'.format
包含來自 X_test 的 loan_amnt 欄位的預測資料框 test_pred_df 已載入到工作空間。
本練習屬於課程
以 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))