I am using ROCR package and I was wondering how can one plot a ROC curve for knn model in R? Is there any way to plot it all with this package?

I don't know how to use the prediction function of ROCR for knn. Here's my example, i am using isolet dataset from UCI repository where i renamed the class attribute as y:

cl <- factor(isolet_training$y)
knn_isolet <- knn(isolet_training, isolet_testing, cl, k=2, prob=TRUE)

Now my question is, what are the arguments to pass to the prediction function of ROC. I tried the 2 below alternatives which are not working:

pred_knn <- prediction(knn_isolet$y, cl)
    pred_knn <- prediction(knn_isolet$y, isolet_testing$y)
  • 4
    $\begingroup$ ROCR is not bound to a specific model. The only information you need are the true labels and the predictions of a model. Can you please provide some code and tell us where exactly you get stuck ? $\endgroup$ – steffen Jul 31 '12 at 14:32
  • 1
    $\begingroup$ @steffen i added an example $\endgroup$ – blerta Aug 1 '12 at 8:56
  • $\begingroup$ you have opened a very similar question for solving the same problem. I suggest to edit this one and flag the other one for close (either you choose or the mods will ;)). I see no value to keep both open. If you do not agree, please comment. $\endgroup$ – steffen Aug 1 '12 at 12:47

ROCR plots ROCs for binary classification only, and ISOLET has 26 classes.

| cite | improve this answer | |
  • $\begingroup$ You are right, I just realized it now myself, so I thought to use pROC, but there's another issue: I have to plot ROC curves of 6 different algorithms in one single plot and pROC supports only 2 curves in one plot. Do you have any idea how to do this? $\endgroup$ – blerta Aug 1 '12 at 11:48
  • $\begingroup$ @blerta re: plotting multiple ROC curves with pROC; try adding add = TRUE to your plot.roc() command, to all but the first ROC you try to plot. $\endgroup$ – bright-star Jun 6 '13 at 6:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.