Predicting labels based on a model trained by a support vector machine
In the previous recipe, we trained an SVM based on the training dataset. The training process finds the optimum hyperplane that separates the training data by the maximum margin. We can then utilize the SVM fit to predict the label (category) of new observations. In this recipe, we will demonstrate how to use the predict
function to predict values based on a model trained by SVM.
Getting ready
You need to have completed the previous recipe by generating a fitted SVM and save the fitted model in model.
How to do it...
Perform the following steps to predict the labels of the testing dataset:
- Predict the label of the testing dataset based on the fitted SVM and attributes of the testing dataset:
> svm.pred = predict(model, testset[, !names(testset) %in% c("churn")])
- Then, you can use the
table
function to generate a classification table with the prediction result and labels of the testing dataset:
>...