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)
比較真實標籤與二元分數
table(sat$label, sat$binary_score)
0 1
0 5729 3
1 15 56
正確辨識的異常 $\div$ 異常總數
table(sat$label, sat$binary_score)
0 1
0 5729 3
1 15 56
recall <- 56 / (15 + 56)
recall
0.7887324
正確辨識的異常 $\mathbf{\div}$ 被判為異常的總數
table(sat$label, sat$binary_score)
0 1
0 5729 3
1 15 56
precision <- 56 / (56 + 3)
precision
0.9491525
R 中的異常偵測入門