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 ...

Get R Data Mining now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.