Besides implementing a loop
function to perform the k-fold cross-validation, you can use the tuning
function (for example, tune.nnet
, tune.randomForest
, tune.rpart
, tune.svm
, and tune.knn
.) within the e1071
package to obtain the minimum error value. In this recipe, we will illustrate how to use tune.svm
to perform the 10-fold cross-validation and obtain the optimum classification model.
In this recipe, we continue to use the telecom churn
dataset as the input data source to perform 10-fold cross-validation.
Perform the following steps to retrieve the minimum estimation error using cross-validation:
- Apply
tune.svm
on the training dataset,trainset
, with the 10-fold cross-validation as the tuning control (if you find an error message, such ascould not find function predict.func
, please clear the workspace, restart the R session, and reload thee1071
library again):
> tuned = tune.svm(churn~., data = trainset...