title: How can I draw a ROC curve for a randomForest model with three classes in R?
body: <p>I'm using the R package, randomForest, to create a model that classifies into three groups.  </p>
  
  <pre><code> model = randomForest(formula = condition ~ ., data = train, ntree = 2000,      
                         mtry = bestm, importance = TRUE, proximity = TRUE) 
  
             Type of random forest: classification
                   Number of trees: 2000
                   No. of variables tried at each split: 3
  
             OOB estimate of  error rate: 5.71%
  
             Confusion matrix:
             lethal mock resistant class.error
   lethal        20    1         0  0.04761905
   mock           1   37         0  0.02631579
   resistant      2    0         9  0.18181818
  </code></pre>
  
  <p>I've tried with several libraries.  For instance, with ROCR, you can't do three classifications, only two.  Behold:</p>
  
  <pre><code>pred=prediction(predictions,train$condition)
  
  Error in prediction(predictions, train$condition) : 
    Number of classes is not equal to 2.
    ROCR currently supports only evaluation of binary classification 
    tasks.
  </code></pre>
  
  <p>data from model$votes is looking like this:</p>
  
  <pre><code>         lethal        mock   resistant
   3   0.04514364 0.952120383 0.002735978
   89  0.32394366 0.147887324 0.528169014
   16  0.02564103 0.973009447 0.001349528
   110 0.55614973 0.433155080 0.010695187
   59  0.06685633 0.903271693 0.029871977
   43  0.13424658 0.865753425 0.000000000
   41  0.82987552 0.033195021 0.136929461
   86  0.32705249 0.468371467 0.204576043
   87  0.37704918 0.341530055 0.281420765
   ........
  </code></pre>
  
  <p>I can get some pretty ugly ROC plots this way using the pROC package:</p>
  
  <pre><code>predictions &lt;- as.numeric(predict(model, test, type = 'response'))
  roc.multi &lt;- multiclass.roc(test$condition, predictions, 
                              percent=TRUE)
  rs &lt;- roc.multi[['rocs']]
  plot.roc(rs[[2]])
  sapply(2:length(rs),function(i) lines.roc(rs[[i]],col=i))
  </code></pre>
  
  <p>Those plots look like this:
  <a href="https://i.stack.imgur.com/YNvHI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YNvHI.png" alt="Figure 1: Ugly ROC curve"></a></p>
  
  <p>There's no way to smooth those lines though, because they aren't so much of a curve as they are 4 or so points each.  </p>
  
  <p>I need a way to plot a nice smooth ROC curve for this model, but I can't seem to find one.  Does anyone know of a good approach?  Thanks very much in advance!</p>