Motivarea kernelului RBF

Support Vector Machines în R

Kailash Awati

Instructor

Kernel pătratic (parametri impliciți)

  • Împărțiți datele în test/antrenament (neafișat)
  • Utilizați kernel polinomial de grad 2 (parametri impliciți)
svm_model <- svm(y ~ ., data = trainset, 
                type = "C-classification", 
                kernel = "polynomial", 
                degree = 2)
svm_model
....
Number of Support Vectors:  204
# Predictions
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
0.8666667
plot(svm_model, trainset)
Support Vector Machines în R

Cap. 4.2 - set de date complex, kernel pătratic implicit, grafic cu svm.plot

Support Vector Machines în R

Încercați un polinom de grad mai mare

  • Excludeți gradele impare -3, 5, 9 etc.
  • Încercați gradul 4
svm_model <- svm(y ~ ., data = trainset, 
                type = "C-classification", 
                kernel = "polynomial", 
                degree = 4)
svm_model
...
Number of Support Vectors: 203
# Predictions
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
0.8583333
plot(svm_model, trainset)
Support Vector Machines în R

Cap. 4.2 - set de date complex, kernel cu grad=4 implicit, grafic cu svm.plot

Support Vector Machines în R

O altă abordare

  • Euristică: punctele apropiate au aceeași clasificare:
    • Similar cu algoritmul K-Nearest Neighbors.
  • Pentru un punct dat din set, de ex. X1 = (a, b):
    • Kernelul trebuie să aibă un maxim în (a, b)
    • Trebuie să descrească pe măsură ce ne îndepărtăm de (a, b)
    • Rata de descreștere trebuie să fie aceeași în toate direcțiile
    • Rata de descreștere trebuie să fie reglabilă
  • O funcție simplă cu această proprietate este exp(-gamma * r), unde r este distanța dintre X1 și orice alt punct X
Support Vector Machines în R

Cum variază kernelul RBF cu gamma (cod)

#rbf function
rbf <- function(r, gamma) exp(-gamma * r)

ggplot(data.frame(r = c(-0, 10)), aes(r)) + stat_function(fun = rbf, args = list(gamma = 0.2), aes(color = "0.2")) + stat_function(fun = rbf, args = list(gamma = 0.4), aes(color = "0.4")) + stat_function(fun = rbf, args = list(gamma = 0.6), aes(color = "0.6")) + stat_function(fun = rbf, args = list(gamma = 0.8), aes(color = "0.8")) + stat_function(fun = rbf, args = list(gamma = 1), aes(color = "1")) + stat_function(fun = rbf, args = list(gamma = 2), aes(color = "2")) + scale_color_manual("gamma", values = c("red","orange","yellow", "green","blue","violet")) + ggtitle("Radial basis function (gamma = 0.2 to 2)")
Support Vector Machines în R

Kernelul RBF pentru diferite valori gamma

Support Vector Machines în R

Timp de practică!

Support Vector Machines în R

Preparing Video For Download...