Support Vector Machines in R
Kailash Awati
Instructor
tune.svm()
function.cost = 10^(-1:3)
, gamma = c(0.1,1,10)
, coef0 = c(0.1,1,10)
tune_out <- tune.svm(x = trainset[,-3], y = trainset[,3], type = "C-classification", kernel = "polynomial", degree = 2, cost = 10^(-1:2), gamma = c(0.1,1,10), coef0 = c(0.1,1,10))
#print out tuned parameters tune_out$best.parameters$cost tune_out$best.parameters$gamma tune_out$best.parameters$coef0
0.1
10
1
tune.svm()
.svm_model <- svm(y ~ ., data = trainset, type = "C-classification", kernel = "polynomial", degree = 2,
cost = tune_out$best.parameters$cost,
gamma = tune_out$best.parameters$gamma,
coef0 = tune_out$best.parameters$coef0)
pred_train <- predict(svm_model, trainset)
mean(pred_train == trainset$y)
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
1
0.9677419
#plot using svm plot
plot(svm_model, trainset)
Support Vector Machines in R