開始使用免費開始

用視覺化評分信用風險模型

現在,你想要將模型的表現視覺化。在 ROC 圖中,X 與 Y 軸分別是你已經看過的兩個指標:偽陽性率(fall-out)與真正率(sensitivity)。

你可以用以下程式碼繪製模型表現的 ROC 圖:

fallout, sensitivity, thresholds = roc_curve(y_test, prob_default)
plt.plot(fallout, sensitivity)

若要計算 AUC 分數,請使用 roc_auc_score()

信用資料 cr_loan_prep 與資料集 X_testy_test 都已載入至工作區。經訓練的 LogisticRegression() 模型 clf_logistic 也已載入至工作區。

本練習屬於課程

以 Python 進行信用風險建模

檢視課程

練習說明

  • 產生違約機率的預測,並將結果存到 preds
  • 列印模型在測試集 Xy 上的準確率。
  • 在測試資料與違約機率上使用 roc_curve() 以取得 falloutsensitivity,接著以 fallout 為 x 軸繪製 ROC 曲線。
  • 使用測試資料與違約機率計算模型的 AUC,並將其存到 auc

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Create predictions and store them in a variable
____ = clf_logistic.____(____)

# Print the accuracy score the model
print(clf_logistic.____(____, ____))

# Plot the ROC curve of the probabilities of default
prob_default = preds[:, 1]
fallout, sensitivity, thresholds = ____(____, ____)
plt.plot(fallout, sensitivity, color = 'darkorange')
plt.plot([0, 1], [0, 1], linestyle='--')
plt.____()

# Compute the AUC and store it in a variable
____ = ____(____, ____)
編輯並執行程式碼