Measuring prediction performance with a confusion matrix

To measure the performance of a classification model, we can first generate a classification table based on our predicted label and actual label. Then, we can use a confusion matrix to obtain performance measures such as precision, recall, specificity, and accuracy. In this recipe, we will demonstrate how to retrieve a confusion matrix using the caret package.

Getting ready

In this recipe, we will continue to use the telecom churn dataset as our example dataset.

How to do it...

Perform the following steps to generate a classification measurement:

  1. Train an svm model using the training dataset:
    > svm.model= train(churn ~ .,
    +                   data = trainset,
    +                   method = "svmRadial")
    
  2. You can then predict labels ...

Get R: Recipes for Analysis, Visualization and Machine Learning 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.