0

I need to plot a ROC curve in R, but I do not know how to correct it.

cctrl2 <- trainControl(method = "cv", number = 10, classProbs = TRUE, savePredictions = TRUE)
modelNb <- train(Treino[, -5], Treino$TOTAL_PEDIDO, 
         method = "nb", 
         trControl = cctrl2)
test_class_pred_nb_probs <- predict(modelNb, Teste[, -5], type = "prob")
roc_nb = plot.roc(Teste[, 2],test_class_pred_nb_probs$alto, col='red')

However, the test table Teste$TOTAL_PEDIDO has 4 values (high, regular, low and min) and to plot the ROC curve the value must be atomic.

aux<-Teste[which(Teste$TOTAL_PEDIDO == "alto"),]
test_class_pred_nb_probs <- predict(modelNb, aux[, -5], type = "prob")
roc_nb = plot.roc(aux[, 2],test_class_pred_nb_probs$alto, col='red')

And shows the message:

Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
PaulDaigle
  • 21
  • 6
  • Please post a reproducible example: https://stackoverflow.com/help/mcve – Calimo Aug 29 '17 at 06:17
  • @Calimo, the table has more than 7,000 tuples. How can I post the table? – PaulDaigle Aug 29 '17 at 18:11
  • You don't need to include all of them, select a small sub-sample. And have a look at https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and don't forget to include the calls to library() etc. – Calimo Aug 30 '17 at 07:04

1 Answers1

-1
cctrl2 <- trainControl(method = "cv", number = 10,  classProbs = TRUE, savePredictions = TRUE)

modelNb <- train(Treino[, -2], Treino$TOTAL_PEDIDO,
              method = "nb", 
              trControl = cctrl2)

test_pred_nb <- predict(modelNb, Teste[, -2])
test_pred_nb_probs <- predict(modelNb, Teste[, -2], type = "prob")
roc_nb = multiclass.roc(Teste[, 2],
     test_pred_nb_probs$min,
     add=TRUE,
     col='blue')
roc_nb
rs <- roc_nb[['rocs']]
plot.roc(rs[[1]])

auc(roc_nb)
PaulDaigle
  • 21
  • 6