Cost of not detecting fraud
When no detection model is used, then all transactions in the transfers
dataset are considered legitimate. You will determine the corresponding confusion matrix. Despite fraud being rare, the resulting financial losses can be huge. You will compute the total cost of not detecting the fraudulent transfers.
The caret
package is already loaded for you to construct the confusionMatrix()
. The transfers
dataset is loaded in your workspace, don't hesitate to explore it in the Console.
Este exercício faz parte do curso
Fraud Detection in R
Instruções do exercício
- Use
rep.int()
to create a vector calledpredictions
in which all transfers are predicted as legitimate (class 0). Don't hesitate to look at the slides to see how this function was used in the video. - Use the function
confusionMatrix()
from thecaret
package to compute the confusion matrix ofpredictions
and thefraud_flag
column fromtransfers
. - Compute the total cost of not detecting fraud as the sum of fraudulent transferred amounts.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Create vector predictions containing 0 for every transfer
predictions <- factor(___(___, times = ___(___)), levels = c(0, 1))
# Compute confusion matrix
confusionMatrix(data = ___, reference = ___)
# Compute cost of not detecting fraud
cost <- sum(___[___ == ___])
print(cost)