Support Vector Machines in R
Kailash Awati
Instructor
library(ggplot2)
# Plot petal length vs width for dataset, distinguish species by color
p <- ggplot(data = iris,
aes(x = Petal.Width,
y = Petal.Length,
color = Species)) +
geom_point()
# Display plot
p
library(e1071)
# Build model
svm_model <- svm(Species ~ .,
data = trainset,
type = "C-classification",
kernel = "linear")
pred_train <- predict(svm_model, trainset)
mean(pred_train == trainset$Species)
0.9756098
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$Species)
0.962963
Support Vector Machines in R