Get startedGet started for free

Linear SVM for a radially separable dataset

In this exercise you will build two linear SVMs, one for cost = 1 (default) and the other for cost = 100, for the radially separable dataset you created in the first lesson of this chapter. You will also calculate the training and test accuracies for both costs. The e1071 library has been loaded, and test and training datasets have been created for you and are available in the data frames trainset and testset.

This exercise is part of the course

Support Vector Machines in R

View Course

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

#default cost mode;
svm_model_1 <- svm(y ~ ., data = ___, type = "C-classification", cost = ___, kernel = "linear")

#training accuracy
pred_train <- predict(svm_model_1, ___)
mean(pred_train == ___$y)

#test accuracy
pred_test <- predict(svm_model_1, ___)
mean(pred_test == ___$y)
Edit and Run Code