How to Create a Simple ROC Curve

I’m using the R statistical package and the ROCR package within that. Both of these are free and very flexible. Sometimes with that flexibility comes ambiguity as to what you should do to accomplish a relatively simple task. I am doing a data-mining (machine-learning) project in which I predict a cancer patient’s prognosis. The algorithms I use can give a probability of what either outcome (let’s say “good” or “bad”) will be. I can use those probabilities to create an ROC curve. If you don’t know what this is, Wikipedia has a nice tutorial on it.

Below is the code I used to create this.

rocCurve = function(probabilityPredictions, actualClasses)
{
  pred = prediction(probabilityPredictions, actualClasses)
  perf = performance(pred, 'tpr', 'fpr')
 
  plot(perf, lwd=2)
  abline(0, 1, lwd=2, lty=3)
}

Leave a Reply