SVM 튜닝

R에서의 Support Vector Machine

Kailash Awati

Instructor

튜닝의 목표

  • 복잡한 커널에서 최적 매개변수 값을 수동으로 찾기 어렵습니다.
  • 목표: tune.svm() 함수를 사용하여 최적 매개변수 집합을 찾습니다.
R에서의 Support Vector Machine

튜닝 개요

  • 작동 방식:
    • 각 매개변수의 탐색 범위 설정. 예: cost = 10^(-1:3), gamma = c(0.1,1,10), coef0 = c(0.1,1,10)
    • 가능한 모든 매개변수 조합에 대해 SVM 모델을 구축하고 정확도를 평가합니다.
    • 최고 정확도를 산출하는 매개변수 조합을 반환합니다.
  • 계산 비용이 높은 절차입니다!
R에서의 Support Vector Machine
  • 앞서 생성한 방사형 분리 데이터셋에 대해 SVM 모델 튜닝
    • 이전 강의에서 다항 커널 SVM 구축
    • SVM 정확도 약 94%.
  • gamma, cost, coef0 튜닝으로 성능을 개선할 수 있을까요?
tune_out <- tune.svm(x = trainset[,-3], y = trainset[,3], 
                     type = "C-classification", kernel = "polynomial", degree = 2,
                     cost = 10^(-1:2), gamma = c(0.1,1,10), coef0 = c(0.1,1,10))

#print out tuned parameters tune_out$best.parameters$cost tune_out$best.parameters$gamma tune_out$best.parameters$coef0
0.1
10
1
R에서의 Support Vector Machine
  • tune.svm()의 최적 매개변수 값으로 SVM 모델을 구축합니다.
svm_model <- svm(y ~ ., data = trainset, type = "C-classification", kernel = "polynomial", degree = 2,
        cost = tune_out$best.parameters$cost,
        gamma = tune_out$best.parameters$gamma,
        coef0 = tune_out$best.parameters$coef0)
  • 훈련 및 테스트 정확도 평가
pred_train <- predict(svm_model, trainset)
mean(pred_train == trainset$y)
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$y)
1

0.9677419
#plot using svm plot
plot(svm_model, trainset)
R에서의 Support Vector Machine

3장 4절 - 방사형 분리 데이터셋, 튜닝된 이차 커널, svm.plot을 사용한 플롯

R에서의 Support Vector Machine

연습할 시간입니다!

R에서의 Support Vector Machine

Preparing Video For Download...