Grid Search For SVM
Grid Search For SVM
Grid Search For SVM
dataset = dataset[3:5]
library(caTools)
set.seed(123)
Feature Scaling
training_set[-3] = scale(training_set[-3])
test_set[-3] = scale(test_set[-3])
https://rpubs.com/markloessi/506999 1/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
# install.packages('caret')
library(caret)
classifier
##
## 300 samples
## 2 predictor
##
## No pre-processing
## Summary of sample sizes: 300, 300, 300, 300, 300, 300, ...
##
## C Accuracy Kappa
##
## Accuracy was used to select the optimal model using the largest value.
## The final values used for the model were sigma = 1.560428 and C = 1.
Lets strip that down to only the best values for Sigma and C.
classifier$bestTune
## sigma C
## 3 1.560428 1
https://rpubs.com/markloessi/506999 2/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
cm
## y_pred
## 0 1
## 0 58 6
## 1 6 30
set = training_set
plot(set[, -3],
https://rpubs.com/markloessi/506999 3/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
set = test_set
https://rpubs.com/markloessi/506999 4/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
===============================================
# install.packages('e1071')
library(e1071)
data = training_set,
type = 'C-classification',
kernel = 'radial')
https://rpubs.com/markloessi/506999 5/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
cmO
## y_predO
## 0 1
## 0 58 6
## 1 4 32
knitr::include_graphics("k-fold_crossValidation.png")
https://rpubs.com/markloessi/506999 6/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
# install.packages('caret')
library(caret)
training_fold = training_set[-x, ]
test_fold = training_set[x, ]
data = training_fold,
type = 'C-classification',
kernel = 'radial')
return(accuracy)
})
accuracy = mean(as.numeric(cv))
accuracy
## [1] 0.9132814
set = training_set
plot(set[, -3],
https://rpubs.com/markloessi/506999 7/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
set = test_set
https://rpubs.com/markloessi/506999 8/9
10/14/21, 6:07 PM RPubs - Grid Search applied in R
https://rpubs.com/markloessi/506999 9/9