R로 배우는 트리 기반 Machine Learning
Sandro Raabe
Data Scientist
no만 항상 예측하는 "나이브" 모델도 정확도 98% 가능→ 음성 98%의 불균형 데이터셋에서 발생 가능






predictions
# A tibble: 153 x 2
.pred_class true_class
<fct> <fct>
1 yes no
2 no no
3 no yes
4 yes yes
# 단일 임곗값에서 민감도 계산
sens(predictions,
estimate = .pred_class,
truth = true_class)
# A tibble: 1 x 2
.metric .estimate
<chr> <dbl>
1 sensitivity 0.872
accuracy(), conf_mat()와 유사한 인수# 테스트셋에서 확률 예측 predictions <- predict(model, data_test,type = "prob") %>%bind_cols(data_test)
# A tibble: 9,116 x 13
.pred_yes still_customer age gender ...
<dbl> <fct> <int> <fct> ...
1 0.0557 no 45 M ...
2 0.0625 no 49 F ...
3 0.330 no 51 M ...
4 ...
...
# 모든 임곗값에 대한 ROC 곡선 계산 roc <- roc_curve(predictions,estimate = .pred_yes,truth = still_customer)# ROC 곡선 그리기 autoplot(roc)

# 곡선 아래 면적 계산
roc_auc(predictions,
estimate = .pred_yes,
truth = still_customer)
# A tibble: 1 x 3
.metric .estimator .estimate
<chr> <chr> <dbl>
1 roc_auc binary 0.872
R로 배우는 트리 기반 Machine Learning