Get startedGet started for free

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)
}

This exercise is part of the course

Fraud Detection in R

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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

# Calculate the total cost of deploying the model using SMOTE
cost_model(___, ___, ___, ___)
Edit and Run Code