視覺化接受門檻的分位數
你已經知道 quantile() 如何用來計算門檻值,也看過它如何把貸款分成「接受」與「拒絕」。那這個門檻在測試集上長什麼樣子?要怎麼把它視覺化?
為了檢查這點,你可以先畫出機率的長條圖,然後再加上一條代表門檻值的參考線。這樣就能在分布中直觀看到門檻的位置。
模型預測 clf_gbt_preds 已載入至工作空間。
本練習屬於課程
以 Python 進行信用風險建模
練習說明
- 以預測機率
clf_gbt_preds繪製長條圖。 - 使用
quantile()計算接受率 85% 的門檻值,並將結果儲存為threshold。 - 再次繪製長條圖,不過這次請用
.axvline()加上一條參考線。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Plot the predicted probabilities of default
plt.____(____, color = 'blue', bins = 40)
# Calculate the threshold with quantile
____ = np.____(____, ____)
# Add a reference line to the plot for the threshold
plt.____(x = ____, color = 'red')
plt.____()