开始使用免费开始使用

欺诈检测的真实成本

您已经在原始训练集(model_orig)和重采样后的训练集(model_smote)上各构建了一个模型。test 集中各样本的预测类别分别为 predicted_class_origpredicted_class_smote。与其用准确率比较欺诈检测模型,不如计算其检测成本更为合理。

下面给出了 cost_model() 函数的定义。请先阅读,了解成本是如何计算的。

cost_model <- function(predicted.classes, true.classes, amounts, fixedcost) {
  library(hmeasure)
  predicted.classes <- relabel(predicted.classes)
  true.classes <- relabel(true.classes)
  cost <- sum(true.classes * (1 - predicted.classes) * amounts + predicted.classes * fixedcost)
  return(cost)
}

本练习是课程的一部分

R 中的欺诈检测

查看课程

练习说明

  • 使用 cost_model() 计算在测试集上部署 model_orig 的真实成本,fixedcost 设为 10。
  • 使用 cost_model() 计算在测试集上部署 model_smote 的真实成本,fixedcost 设为 10。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Calculate the total cost of deploying the original model
cost_model(___, ___, ___, ___)

# Calculate the total cost of deploying the model using SMOTE
cost_model(___, ___, ___, ___)
编辑并运行代码