Skip to content

Instantly share code, notes, and snippets.

@crazyhottommy
Last active November 29, 2016 16:29
Show Gist options
  • Save crazyhottommy/c6bd14895236e5960e5111fa03e5ff0a to your computer and use it in GitHub Desktop.
Save crazyhottommy/c6bd14895236e5960e5111fa03e5ff0a to your computer and use it in GitHub Desktop.

From David Robinson:

A tidyverse approach to ROC curves #rstats pic.twitter.com/buizc7U9ns

— David Robinson (@drob) November 29, 2016
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
library(tidyverse)
theme_set(theme_minimal())

roc<- iris %>% 
        gather(Metric, Value, -Species) %>%
        mutate(Positive = Species == "virginica") %>%
        group_by(Metric) %>% 
        arrange(-Value) %>% 
        mutate(TPR = cumsum(Positive) / sum(Positive),
               FPR = cumsum(!Positive) / sum(!Positive))

ggplot(roc, aes(FPR, TPR, color = Metric)) + 
        geom_line() + 
        geom_abline(lty = 2) +
        ggtitle("ROC at predicting Virginica iris species")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment