SVMのチューニング

Rで学ぶSupport Vector Machines

Kailash Awati

Instructor

チューニングの目的

  • 複雑なカーネルでは最適なパラメータを手動で見つけることは困難です。
  • 目的: tune.svm() 関数を使用して最適なパラメータセットを見つけること。
Rで学ぶSupport Vector Machines

チューニングの概要

  • 仕組み:
    • 各パラメータの探索範囲を設定する。例: cost = 10^(-1:3)gamma = c(0.1,1,10)coef0 = c(0.1,1,10)
    • パラメータ値のすべての組み合わせでSVMモデルを構築し、精度を評価する。
    • 最高精度をもたらすパラメータの組み合わせを返す。
  • 計算コストが高い処理です!
Rで学ぶSupport Vector Machines
  • 以前作成した放射状分離可能なデータセットで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 Machines
  • 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 Machines

第3章4節 - 放射状分離可能なデータセット、チューニング済み二次カーネル、svm.plotによる可視化

Rで学ぶSupport Vector Machines

練習しましょう!

Rで学ぶSupport Vector Machines

Preparing Video For Download...