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)
}
Latihan ini adalah bagian dari kursus
Fraud Detection in R
Petunjuk latihan
- Use
cost_model()to calculate the true cost of deployingmodel_origon the test set, with afixedcostequal to 10. - Use
cost_model()to calculate the true cost of deployingmodel_smoteon the test set, with afixedcostequal to 10.
Latihan interaktif praktis
Cobalah latihan ini dengan menyelesaikan kode contoh berikut.
# Calculate the total cost of deploying the original model
cost_model(___, ___, ___, ___)
# Calculate the total cost of deploying the model using SMOTE
cost_model(___, ___, ___, ___)