simondp

ROC/Confusion matrix

Feb 28th, 2019
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. ### Example online
  2. # Load library
  3. library(pROC)
  4.  
  5. ### Actual outcomes
  6. outcomes <- c(rep(0,27),(rep(1,76)))
  7.  
  8. # Set seed
  9. set.seed(42)
  10.  
  11. ### Prediction Method 1
  12. pred1 <- c(rep(0,4),(rep(1,99)))
  13.  
  14. ### Prediction Method 2
  15. pred2 <- c(rnorm(27,mean=0.3, sd=0.2),rnorm(76,mean=0.5, sd=0.2))
  16.  
  17. # Compare ROC
  18. roc1 <- roc(outcomes,pred1)
  19. roc2 <- roc(outcomes,pred2)
  20. plot(roc1, print.auc=F, lty=2, xlim=c(1,0), lwd=3)
  21. text(0.15, 0.1, labels=sprintf("Method1|AUC: %0.3f", auc(roc1)), col="black")
  22. lines(roc2, col="green", lty=4, lwd=3)
  23. text(0.15, 0.05, labels=sprintf("Metod2|AUC: %0.3f", auc(roc2)), col="green")
  24.  
  25. # Compare confusion matrices
  26. confusionMatrix(factor(outcomes),factor(pred1))
  27. confusionMatrix(factor(outcomes),factor((pred2>=0.35)*1))
Advertisement
Add Comment
Please, Sign In to add comment