開始使用免費開始

繪製 ROC 曲線

用 ROC 曲線視覺化模型效能,可以把所有可能閾值下的表現彙整在同一張圖上。它會顯示每個閾值的靈敏度與特異度。ROC 曲線越往左上角,模型越好。

你將要預測信用卡客戶是否流失的類別機率,並把結果繪成 ROC 曲線。

已預先載入一個 model,這是一個在信用卡客戶訓練集上訓練完成的決策樹,以及測試資料 customers_test

本練習屬於課程

R 的樹狀模型機器學習

檢視課程

練習說明

  • 使用 model 在測試集上預測類別機率。
  • bind_cols() 把結果加入測試集,並將結果存為 predictions
  • 計算該結果的 ROC 曲線。
  • 使用 autoplot() 繪製 ROC 曲線。

動手互動練習

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

# Predict probabilities on test set
predictions <- predict(___, 
                       ___, 
                       type = "___") %>% 
  # Add test set
  ___(customers_test)

# Calculate the ROC curve for all thresholds
roc <- ___(___,
           estimate = ___, 
           truth = ___)

# Plot the ROC curve
___
編輯並執行程式碼