Kernelul RBF

Support Vector Machines în R

Kailash Awati

Instructor

Kernelul RBF pe scurt

  • Funcție descrescătoare a distanței dintre două puncte din set.
  • Simulează algoritmul k-NN.
Support Vector Machines în R

Capitol 4.3 - kernel RBF - influență în funcție de distanța dintre puncte

Support Vector Machines în R

Construirea unui SVM cu kernel RBF

  • Construiți un SVM cu kernel RBF pentru un set de date complex
svm_model <- svm(y ~ ., 
                data = trainset, 
                type = "C-classification",
                kernel = "radial")
  • Calculați acuratețea pe antrenament/test și trasați graficul față de setul de antrenament.
pred_train <- predict(svm_model, trainset)
mean(pred_train == trainset$y)
0.93125
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
0.9416667
#plot decision boundary
plot(svm_model, trainset)
Support Vector Machines în R

Capitol 4.3 - set de date complex, kernel RBF implicit, reprezentare grafică cu svm.plot

Support Vector Machines în R

Rafinarea frontierei de decizie

  • Ajustați gamma și cost cu tune.svm()
# Tune parameters
tune_out <- tune.svm(x = trainset[,-3],
                     y = trainset[,3],
                     gamma = 5 * 10 ^ (-2:2),
                     cost = c(0.01, 0.1, 1, 10, 100),
                     type = "C-classification",
                     kernel = "radial")
  • Afișați cei mai buni parametri
# Print best values of cost and gamma
tune_out$best.parameters$cost
1
tune_out$best.parameters$gamma
5
Support Vector Machines în R

Modelul ajustat

  • Construiți modelul ajustat folosind best.parameters
svm_model <- svm(y ~ ., data = trainset, 
              type = "C-classification", 
              kernel = "radial",
              cost = tune_out$best.parameters$cost,
              gamma = tune_out$best.parameters$gamma)
  • Calculați acuratețea pe setul de test
mean(pred_test == testset$y)
0.95
  • Trasați frontiera de decizie
plot(svm_model, trainset)
Support Vector Machines în R

Capitol 4.3 - set de date complex, kernel RBF ajustat, reprezentare grafică cu svm.plot

Support Vector Machines în R

Timp de practică!

Support Vector Machines în R

Preparing Video For Download...