Support Vector Machines in R
Kailash Awati
Instructor
svm_model <- svm(y ~ .,
data = trainset,
type = "C-classification",
kernel = "radial")
pred_train <- predict(svm_model, trainset)
mean(pred_train == trainset$y)
0.93125
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
0.9416667
#plot decision boundary
plot(svm_model, trainset)
gamma
and cost
using tune.svm()
# Tune parameters
tune_out <- tune.svm(x = trainset[,-3],
y = trainset[,3],
gamma = 5 * 10 ^ (-2:2),
cost = c(0.01, 0.1, 1, 10, 100),
type = "C-classification",
kernel = "radial")
# Print best values of cost and gamma
tune_out$best.parameters$cost
1
tune_out$best.parameters$gamma
5
best.parameters
svm_model <- svm(y ~ ., data = trainset,
type = "C-classification",
kernel = "radial",
cost = tune_out$best.parameters$cost,
gamma = tune_out$best.parameters$gamma)
mean(pred_test == testset$y)
0.95
plot(svm_model, trainset)
Support Vector Machines in R