사기 탐지의 실제 비용
원본 학습용 데이터(model_orig)와 리밸런싱된 학습용 데이터(model_smote)로 두 개의 모델을 만들었어요. test 세트의 각 사례에 대한 예측 클래스는 각각 predicted_class_orig와 predicted_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로 배우는 사기 탐지
연습 안내
- 테스트 세트에
model_orig을(를) 배포했을 때의 실제 비용을fixedcost가 10일 때cost_model()로 계산하세요. - 테스트 세트에
model_smote을(를) 배포했을 때의 실제 비용을fixedcost가 10일 때cost_model()로 계산하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Calculate the total cost of deploying the original model
cost_model(___, ___, ___, ___)
# Calculate the total cost of deploying the model using SMOTE
cost_model(___, ___, ___, ___)