Example 1:

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

Example 2: Do a similar svm analysis as that in the previous question using the iris data set. Discuss the number of support vectors/samples.

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

Example 3: Use the iris dataset (or any other data set) to select 80% of the samples for training svm(), then use the rest 20% for validation. Discuss your results.

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