# NOT RUN {
library(AUC)
data(churn)
r <- roc(churn$predictions, churn$labels)
td <- tidy(r)
td
library(ggplot2)
ggplot(td, aes(fpr, tpr)) +
geom_line()
# compare the ROC curves for two prediction algorithms
library(dplyr)
library(tidyr)
rocs <- churn %>%
pivot_longer(contains("predictions"),
names_to = "algorithm",
values_to = "value"
) %>%
nest(data = -algorithm) %>%
mutate(tidy_roc = purrr::map(data, ~ tidy(roc(.x$value, .x$labels)))) %>%
unnest(tidy_roc)
ggplot(rocs, aes(fpr, tpr, color = algorithm)) +
geom_line()
# }
Run the code above in your browser using DataLab