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:
- Train an svm model using the training dataset:
> svm.model= train(churn ~ ., + data = trainset, + method = "svmRadial")
- You can then predict labels using the fitted model,
svm.model
:
> svm.pred = predict(svm.model, testset[,! names(testset) %in% c("churn")])
- Next, you can generate a classification table:
>...