Skip to content

Instantly share code, notes, and snippets.

@jakobludewig
Created October 17, 2018 15:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakobludewig/b79678f04a6c0a0b023b8685608d1d47 to your computer and use it in GitHub Desktop.
Save jakobludewig/b79678f04a6c0a0b023b8685608d1d47 to your computer and use it in GitHub Desktop.
Comparing AUC of classifiers with and without trivial points
rm(list = ls())
library(tidyverse)
model_roc_points <-
tribble(~model,~threshold,~FPR,~TPR,
"model_1",-Inf,0,0,
"model_1",0.25,0.25,0.375,
"model_1",0.5,0.5,0.75,
"model_1",Inf,1,1,
"model_2",-Inf,0,0,
"model_2",0.25,0.25,0.375,
"model_2",0.5,0.5,0.75,
"model_2",0.75,0.75,0.875,
"model_2",Inf,1,1)
model_roc_points %>%
ggplot(aes(x = FPR,y = TPR,
color = model)) +
geom_line() + geom_point(size = 3) +
geom_line(data = tibble(x = c(0,1),y =x) %>% tidyr::crossing(tibble(model = c("model_1","model_2"))),
aes(x = x, y= y),color = "black",linetype = "dashed") +
geom_ribbon(aes(x = FPR,ymax = TPR,fill = model),ymin = 0,alpha = 0.3)+
facet_wrap(~model) +
theme_bw() +
theme(text = element_text(size = 18),panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
scale_y_continuous(limits = c(0,1)) +
scale_x_continuous(limits = c(0,1))
model_roc_points %>%
dplyr::filter(!threshold %in% c(-Inf,Inf)) %>%
ggplot(aes(x = FPR,y = TPR,
color = model)) +
geom_line() + geom_point() +
geom_line(data = tibble(x = c(0,1),y =x) %>% tidyr::crossing(tibble(model = c("model_1","model_2"))),
aes(x = x, y= y),color = "black",linetype = "dashed") +
geom_ribbon(aes(x = FPR,ymax = TPR,fill = model),ymin = 0,alpha = 0.3)+
facet_wrap(~model) +
theme_bw() +
theme(text = element_text(size = 18),panel.border = element_blank(), panel.grid.major = element_blank(),
panel.grid.minor = element_blank(), axis.line = element_line(colour = "black")) +
scale_y_continuous(limits = c(0,1)) +
scale_x_continuous(limits = c(0,1))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment