November 4, 2013

ROC (Receiver Operating Characteristics) Curve in R

There are 2 packages to calculate different measures and draw different graphs of ROC cureve.
  1. ROCR (http://rocr.bioinf.mpi-sb.mpg.de/)
  2. pROC (http://cran.r-project.org/web/packages/pROC/pROC.pdf)

Code to generate ROC curve and AUC (Area under the curve) value

Using ROCR:
 # generate ROC curve  
 pred <- prediction(scores, labels)  
 perf <- performance(pred, "tpr", "fpr")  
 plot(perf)  

 #calculate AUC value  
 aucPerf <- performance( pred, 'auc')  
 auc <- slot(aucPerf, "y.values")  

Using pROC:
 roc.obj <- roc(response=labels, predictor=scores)  
 plot(roc.obj)  
 auc(roc.obj)  

2 comments:

  1. Well done! It is so well written and interactive. Keep writing such brilliant piece of work. Glad i came across this post. Last night even i saw similar wonderful R Programming tutorial on youtube so you can check that too for more detailed knowledge on R Programming.https://www.youtube.com/watch?v=rgFVq_Q6VF0

    ReplyDelete

  2. What a fantastic read on Data Science. This has helped me understand a lot in Data Science course. Please keep sharing similar write ups on Data Science. Guys if you are keen to know more on Data Science, must check this wonderful Data Science tutorial and i'm sure you will enjoy learning on Data Science training.:-https://www.youtube.com/watch?v=gXb9ZKwx29U&t=237s

    ReplyDelete