gakonst

Untitled

Jan 23rd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. library(e1071)
  2. library(MLmetrics)
  3. library(ROCR)
  4.  
  5. data = read.csv('../bayes.csv')
  6. ytest = data[,1]
  7. pred_m1 = data[,2]
  8. pred_m2 = data[,3]
  9.  
  10. # Threshold 0.5
  11. pred_m1[pred_m1 >= 0.5] = 1
  12. pred_m1[pred_m1 < 0.5] = 0
  13. m1 = prediction(pred_m1, ytest)
  14. ROCcurve <- performance(m1, "tpr", "fpr")
  15. plot(ROCcurve, col = "blue")
  16. abline(0,1, col = "grey")
  17. performance(m1, "auc")
  18.  
  19. pred_m2 = data[,3]
  20. pred_m2[pred_m2 < 0.5] = 0
  21. pred_m2[pred_m2 >= 0.5] = 1
  22. ConfusionMatrix(pred_m2, ytest)
  23. m2 = prediction(pred_m2, ytest)
  24. # Define positive class when calling Rec/Prec/F1
  25. Recall(pred_m2, ytest, '1')
  26. Precision(pred_m2, ytest, '1')
  27. F1_Score(pred_m2, ytest, '1')
  28. ROCcurve2 <- performance(m2, "tpr", "fpr")
  29. plot(ROCcurve2, col = "red")
  30.  
  31. # Get the AUC
  32. performance(m2, "auc")
Advertisement
Add Comment
Please, Sign In to add comment