RBF 커널

R에서의 Support Vector Machine

Kailash Awati

Instructor

RBF 커널 개요

  • 데이터셋 내 두 점 사이의 거리에 대한 감소 함수.
  • k-NN 알고리즘을 모방합니다.
R에서의 Support Vector Machine

4장 - RBF 커널 - 점 사이 거리에 따른 영향력

R에서의 Support Vector Machine

RBF 커널로 SVM 구축

  • 복잡한 데이터셋에 RBF 커널 SVM 구축
svm_model <- svm(y ~ ., 
                data = trainset, 
                type = "C-classification",
                kernel = "radial")
  • 훈련/테스트 정확도 계산 및 훈련 데이터셋으로 시각화.
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)
R에서의 Support Vector Machine

4장 - 복잡한 데이터셋, 기본 RBF 커널, svm.plot 시각화

R에서의 Support Vector Machine

결정 경계 최적화

  • tune.svm()으로 gamma와 cost 튜닝
# 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")
  • 최적 파라미터 출력
# Print best values of cost and gamma
tune_out$best.parameters$cost
1
tune_out$best.parameters$gamma
5
R에서의 Support Vector Machine

튜닝된 모델

  • 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)
  • 테스트 정확도 계산
mean(pred_test == testset$y)
0.95
  • 결정 경계 시각화
plot(svm_model, trainset)
R에서의 Support Vector Machine

4장 - 복잡한 데이터셋, 튜닝된 RBF 커널, svm.plot 시각화

R에서의 Support Vector Machine

연습할 시간입니다!

R에서의 Support Vector Machine

Preparing Video For Download...