Building and visualizing the tuned model
In the final exercise of this chapter, you will build a polynomial SVM using the optimal values of the parameters that you obtained from tune.svm()
in the previous exercise. You will then calculate the training and test accuracies and visualize the model using svm.plot()
. The e1071
library has been preloaded and the test and training datasets are available in the dataframes trainset
and testset
. The output of tune.svm()
is available in the variable tune_out
.
Este exercício faz parte do curso
Support Vector Machines in R
Instruções do exercício
- Build an SVM using a polynomial kernel of degree 2.
- Use the optimal parameters calculated using
tune.svm()
. - Obtain training and test accuracies.
- Plot the decision boundary against the training data.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
#Build tuned model
svm_model <- svm(y~ ., data = trainset, type = "C-classification",
kernel = ___, degree = ___,
cost = tune_out$___$cost,
gamma = tune_out$___$gamma,
coef0 = tune_out$___$coef0)
#Calculate training and test accuracies
pred_train <- predict(svm_model, ___)
mean(pred_train == ___$y)
pred_test <- predict(svm_model, ___)
mean(pred_test == ___$y)
#plot model
plot(svm_model, trainset)