Create a ROC curve in R

1

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')

But the test table $ TOTAL_PEDIDO has 4 values (high, regular, low and min) and to plot the ROC curve the value must be atomic. So I did the following.

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 the message appears:

Error in sort.list(y) : 'x' must be atomic for 'sort.list'

Have you called 'sort' on a list?

    
asked by anonymous 29.08.2017 / 01:31

1 answer

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)
    
30.08.2017 / 05:28