"Format of predictions is invalid." error in R

2

I'm trying to draw the ROC curve for the results of my Naive Bayes classifier.

attach(TrainFactor)

NB <- naiveBayes(Result~., data=TrainFactor)
NB_pred <- predict(NB, TestFactor, type = c("class"))
NB_table <- table(NB_pred, TestFactor[,31])

## ROC 
NB_predictiontest <- prediction(NB_pred,TestFactor$Result)
NB_perftest <- performance(NB_predictiontest,"tpr","fpr")

plot(NB_perftest,col="blue",lwd=2, main="Naive Bayes ROC Curve")

But I get an error when I try to execute the "prediction" function:

Error in prediction(NB_pred, TestFactor[, 31]) : 
  Format of predictions is invalid.

Can anyone help me with this?

    
asked by user3529582 31.03.2016 в 16:59
source

2 answers

1

As Matias says, the ROC curve evaluates a probability vector. It is generated from the results of the classification considering different cut points, then you need to have the prediction not as a class, but as a probability. By default, it returns the probabilities, so you do not need to put anything in type .

NB_pred <- predict(NB, TestFactor) 

(You should also make sure that TestFactor$Result is binary)

    
answered by 11.10.2016 / 22:10
source
0

The ROC is a metric to evaluate a binary classifier and evaluates a probability vector (between 0 and 1) against the actual values of your validation set.

Try something like NB_pred <- predict(NB, TestFactor, type = "probs")
(I'm not sure of the syntax)

    
answered by 17.06.2016 в 18:57