R 中的欺诈检测
Bart Baesens
Professor Data Science at KU Leuven



欺诈是一种罕见、深思熟虑、隐蔽、随时间演变且常被精心组织的犯罪,形式多样。









一场强风暴后,某保险公司收到大量理赔
数据中的欺诈占比可用以下函数计算:
table() 与 prop.table()用 prop.table(table(...)) 求欺诈的比例
prop.table(table(fraud_label))
0 1
0.9911 0.0089
labels <- c("no fraud", "fraud")
labels <- paste(labels, round(100 * prop.table(table(fraud_label)), 2), "%")
pie(table(fraud_label), labels, col = c("blue", "red"),
main = "Pie chart of storm claims")

用于评估欺诈检测模型:

predictions <- rep.int(0, times = nrow(claims))
predictions <- factor(predictions, levels = c("no fraud", "fraud"))
caret 的函数 confusionMatrix():library(caret)
confusionMatrix(data = predictions, reference = fraud_label)
Reference
Prediction 0 1
0 614 14
1 0 0
Accuracy : 0.9777
> total_cost <- sum(claim_amount[fraud_label == "fraud"])
> print(total_cost)
2301508
R 中的欺诈检测