Use the svm() algorithm of the e1071 package to carry out the support vector machine for the PlantGrowth data set. Then, discuss the number of support vector samples. Install the e1071 package in R if needed.
Support vector machines are a class of powerful tools which are popular in many algorithms - classification, data mining, AI and optimization. The problem shows there are 29 support vectors/samples.
library(e1071)
svm_plant <- svm(group ~ ., data = PlantGrowth)
summary(svm_plant)
##
## Call:
## svm(formula = group ~ ., data = PlantGrowth)
##
##
## Parameters:
## SVM-Type: C-classification
## SVM-Kernel: radial
## cost: 1
##
## Number of Support Vectors: 29
##
## ( 10 9 10 )
##
##
## Number of Classes: 3
##
## Levels:
## ctrl trt1 trt2
Repeating using iris dataset as stated in problem. The problem shows there are 51 support vectors/samples.
library(e1071)
svm_iris <- svm(Species ~ ., data = iris)
summary(svm_iris)
##
## Call:
## svm(formula = Species ~ ., data = iris)
##
##
## Parameters:
## SVM-Type: C-classification
## SVM-Kernel: radial
## cost: 1
##
## Number of Support Vectors: 51
##
## ( 8 22 21 )
##
##
## Number of Classes: 3
##
## Levels:
## setosa versicolor virginica
Repeating using iris dataset as stated in problem. This time we get 120 support vectors/samples.
library(caret)
## Warning: package 'caret' was built under R version 4.0.5
## Loading required package: ggplot2
## Loading required package: lattice
train_dataset <- createDataPartition(iris$Species, p = 0.80, list = FALSE)
validation <- iris[-train_dataset]
iris_dataset <- data.frame(iris[train_dataset])
svm(train_dataset ~ ., data = iris_dataset)
##
## Call:
## svm(formula = train_dataset ~ ., data = iris_dataset)
##
##
## Parameters:
## SVM-Type: eps-regression
## SVM-Kernel: radial
## cost: 1
## gamma: 0.03030303
## epsilon: 0.1
##
##
## Number of Support Vectors: 120