多クラス問題

Rで学ぶSupport Vector Machines

Kailash Awati

Instructor

アイリスデータセット - はじめに

  • 5つの属性を150件計測
    • 花弁の幅と長さ - 数値(予測変数)
    • がく片の幅と長さ - 数値(予測変数)
    • 種 - カテゴリ:setosa、virginica、versicolor(目的変数)
  • データセット:UCI MLリポジトリ
Rで学ぶSupport Vector Machines

アイリスデータセットの可視化

  • 花弁の長さと幅をプロットする。
library(ggplot2)

# Plot petal length vs width for dataset, distinguish species by color
p <- ggplot(data = iris,
            aes(x = Petal.Width,
                y = Petal.Length,
                color = Species)) +
     geom_point()

# Display plot
p
Rで学ぶSupport Vector Machines

第2章4節 - アイリスデータセット:花弁の長さと幅、種を色で区別

Rで学ぶSupport Vector Machines

SVMアルゴリズムによる多クラス問題の対処法

  • SVMは本質的に二値分類器です。
  • 次の投票戦略で多クラス問題に適用できます:
    • データを2クラスずつのサブセットに分割する。
    • 各サブセットで二値分類問題を解く。
    • 多数決により各データポイントにクラスを割り当てる。
  • これをone-against-one分類戦略と呼ぶ。
Rで学ぶSupport Vector Machines

多クラス線形SVMの構築

  • アイリスデータセットで線形SVMを構築する
    • 80/20の訓練/テスト分割(シード10)、デフォルトコスト
library(e1071)

# Build model
svm_model <- svm(Species ~ ., 
                data = trainset, 
                type = "C-classification", 
                kernel = "linear")
  • 正解率を計算する
pred_train <- predict(svm_model, trainset)
mean(pred_train == trainset$Species)
0.9756098
pred_test <- predict(svm_model, testset)
mean(pred_test == testset$Species)
0.962963
Rで学ぶSupport Vector Machines

練習しましょう!

Rで学ぶSupport Vector Machines

Preparing Video For Download...