開始使用免費開始

ROC AUC

你在上一個練習繪製的 ROC 曲線表現不錯。

現在你要計算 ROC 曲線下的面積(AUC),以及你先前用過的其他分類評估指標。

confusion_matrixclassification_report 函式已為你預先載入,還有你先前建好的 logreg 模型,以及 X_trainX_testy_trainy_test。此外,模型在測試集上的預測標籤已儲存為 y_pred,而測試集中屬於正類別的機率則儲存為 y_pred_probs

同時也已建立一個 knn 模型,並在主控台列印了其效能指標,方便你比較兩個模型的 roc_auc_scoreconfusion_matrixclassification_report

本練習屬於課程

使用 scikit-learn 進行監督式學習

檢視課程

練習說明

  • 匯入 roc_auc_score
  • 計算並列印 ROC AUC 分數,傳入測試標籤與正類別機率的預測值。
  • 計算並列印混淆矩陣。
  • 呼叫 classification_report()

動手互動練習

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

# Import roc_auc_score
____

# Calculate roc_auc_score
print(____(____, ____))

# Calculate the confusion matrix
print(____(____, ____))

# Calculate the classification report
print(____(____, ____))
編輯並執行程式碼