核准率
設定核准率並計算對應的門檻值,可以用來決定你要接受的新貸款比例。在這個練習中,假設測試資料是一批全新的貸款申請。你需要使用 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(____[____].____())