RBFカーネル

Rで学ぶSupport Vector Machines

Kailash Awati

Instructor

RBFカーネルの概要

  • データセット内の2点間の距離の減少関数。
  • k-NNアルゴリズムを近似する。
Rで学ぶSupport Vector Machines

第4章3節 - RBFカーネル - 点間距離の関数としての影響

Rで学ぶSupport Vector Machines

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 Machines

第4章3節 - 複雑なデータセット、デフォルトRBFカーネル、svm.plotによるプロット

Rで学ぶSupport Vector Machines

決定境界の改善

  • tune.svm()gammacostをチューニング
# 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 Machines

チューニング済みモデル

  • 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 Machines

第4章3節 - 複雑なデータセット、チューニング済みRBFカーネル、svm.plotによるプロット

Rで学ぶSupport Vector Machines

練習しましょう!

Rで学ぶSupport Vector Machines

Preparing Video For Download...