Support Vector Machines in R
Kailash Awati
Instructor
ggplot()
to plot the dataset in $X_1 - X_2$ spacep <- ggplot(data = df4, aes(x = x1sq, y = x2sq, color = y)) +
geom_point() +
scale_color_manual(values = c("red", "blue")) +
geom_abline(slope = -1, intercept = 0.49)
p
(gamma * (u.v) + coef0) ^ degree
degree
is the degree of the polynomialgamma
and coef0
are tuning parametersu
, v
are vectors (datapoints) belonging to the datasetdegree = 2
cost
, gamma
and coef0
(1, 1/2 and 0)svm_model <- svm(y ~ ., data = trainset, type = "C-classification", kernel = "polynomial", degree = 2)
# Predictions
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
0.9354839
# Visualize model
plot(svm_model, trainset)
Support Vector Machines in R