Tell me more ×
Cross Validated is a question and answer site for statisticians, data analysts, data miners and data visualization experts. It's 100% free, no registration required.

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:

library(ROCR)
pred_knn <- prediction(knn_isolet$y, cl)
    pred_knn <- prediction(knn_isolet$y, isolet_testing$y)
share|improve this question
4  
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 ? – steffen Jul 31 '12 at 14:32
1  
@steffen i added an example – blerta Aug 1 '12 at 8:56
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. – steffen Aug 1 '12 at 12:47

2 Answers

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

share|improve this answer
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? – blerta Aug 1 '12 at 11:48

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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