我需要在R中绘制ROC曲线,但我不知道如何纠正它。
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')
但是,测试表Teste $ TOTAL_PEDIDO有4个值(高,常,低和最小),并绘制ROC曲线,该值必须是原子的。
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')
并显示消息:
Error in sort.list(y) : 'x' must be atomic for 'sort.list'
Have you called 'sort' on a list?
答案 0 :(得分:-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)