開始使用免費開始

計算 specificity

使用不同的模型效能衡量指標,可以更準確地評估模型。 不同情境有不同的指標。 Specificity(特異度) 衡量被正確辨識為 真負類 的比例:

$$\text{specificity} = \frac{TN}{TN + FP}$$

這個公式表示當 specificity 趨近 100% 時,偽陽性(FP)的數量會「趨近於 0」。

在本練習中,你將用交叉驗證來檢視模型在樣本外的 specificity。

已預先載入的是信用卡客戶資料集的訓練資料 customers_train,以及決策樹規格 tree_spec,它是用以下程式碼建立的:

tree_spec <- decision_tree() %>% 
                set_engine("rpart") %>%
                set_mode("classification")

本練習屬於課程

R 的樹狀模型機器學習

檢視課程

練習說明

  • 建立 customers_train 的 3 折交叉驗證(CV folds),並將其儲存為 folds
  • 使用 fit_resamples() 計算交叉驗證的 specificity。該函式需傳入你的規格 tree_spec、模型公式、CV 摺疊,以及合適的 metric set。使用所有預測變數來預測 still_customer,並將結果儲存為 specificities
  • 使用單一函式彙整結果。

動手互動練習

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

# Create CV folds of the training data
folds <- ___(customers_train, v = ___)

# Calculate CV specificity
specificities <- ___(___, 
                     ___,
                     resamples = ___,
                     metrics = ___)

# Collect the metrics
___(specificities)
編輯並執行程式碼