R – How to get true positive, false negative table from output of predict()


I would like to print simple table which will show how much rows in test set were predicted right and how much were wrong (true-negative, false-positive).

      |  class1   |   class2  |

(values in this table are not real)

I am currently using klaR package and NaiveBayes function which i use in predict() function. It looks like this:

prediction <- predict(naiveBayesSet, testSet)

Best Solution

You can use the table function in the base package to do something like this:

table(Predictions = prediction, TrueLabels = Labels)

where prediction is the the vector from your code above and Labels is a vector with the true labels in it.

Alternatively the function errormatrix() in the package klaR that you're already using can do this.

Related Question