O'Reilly logo

R Data Mining by Andrea Cirillo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Computing a confusion matrix with the caret package

It is now time to get a sense of how useful this package is, by computing the confusion matrix for all of the models we have previously fitted:

  • Logistic regression
  • Support vector machine
  • Random forest

The function we are going to employ here is the confusionMatrix() function, which basically takes the vector of predicted values and the vector of observed values (order here is not irrelevant) and produces as an output an appropriate confusion matrix. Moreover, it produces a whole set of metrics commutable from confusion matrices, as shown within the pertaining documentation, given the following confusion matrix:

Reference
Predicted Event No Event
Event A B
No Event C D

The ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required