衡量效能

R 中的異常偵測入門

Alastair Rushworth

Data Scientist

使用決策閾值

選一個高門檻值

high_score <- quantile(sat$score, probs = 0.99)
high_score
    99% 
0.6228078

將分數二元化

sat$binary_score <- as.numeric(score >= high_score)
R 中的異常偵測入門

一致性表格

比較真實標籤與二元分數

table(sat$label, sat$binary_score)
       0    1
  0 5729    3
  1   15   56

  • 在 71 個異常中找出 56 個
R 中的異常偵測入門

召回率(Recall)

正確辨識的異常 $\div$ 異常總數

  • 1 代表召回率完美;演算法偵測到所有異常
table(sat$label, sat$binary_score)
       0    1
  0 5729    3
  1   15   56
recall <- 56 / (15 + 56)
recall
0.7887324
R 中的異常偵測入門

精確率(Precision)

正確辨識的異常 $\mathbf{\div}$ 被判為異常的總數

  • 1 代表精確率完美;沒有把正常樣本誤標為異常
table(sat$label, sat$binary_score)
       0    1
  0 5729    3
  1   15   56
precision <- 56 / (56 + 3)
precision
0.9491525
R 中的異常偵測入門

一起來練習吧!

R 中的異常偵測入門

Preparing Video For Download...