Session Ready
Exercise

True cost of fraud detection

You've built two models on both the original training set (model_orig) and the rebalanced training set (model_smote). The predicted classes for the cases in the test set are called predicted_class_orig and predicted_class_smote, respectively. Rather than comparing fraud detection models based on their accuracy, it's better to compute their cost of detection.

Here is the definition of the cost_model() function. Review it to understand how the cost is computed.

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)
}
Instructions
100 XP
  • Use cost_model() to calculate the true cost of deploying model_orig on the test set, with a fixedcost equal to 10.
  • Use cost_model() to calculate the true cost of deploying model_smote on the test set, with a fixedcost equal to 10.