"SupportVectorMachine" (機械学習メソッド)
- Classifyのためのメソッドである.
- マージン最大化超平面を使って訓練データを2つのクラスに分割する超平面を求めることで,クラス確率をモデル化する.
詳細とサブオプション
- サポートベクトルマシンは二項分類器である.カーネル関数を使って例から特徴を抽出する.このメソッドは,訓練時に,クラスを分割するマージン最大化超平面を求める.マルチクラス分類問題は(1対1あるいは1対全のストラテジを使って)二項分類問題の集合に簡約される.現在の実装では.バックエンドでLibSVMフレームワークが使われている.
- オプション"KernelType"を使って使用するカーネルタイプを選択することができる.次は,"KernelType"の可能な設定である.
-
"RadialBasisFunction" 指数放射基底関数をカーネルとして使う "Polynomial" 多項式関数をカーネルとして使う "Sigmoid" シグモイド関数をカーネルとして使う "Linear" 線形関数をカーネルとして使う - カーネル"RadialBasisFunction"の形状
- カーネル"Polynomial"の形状
- カーネル"Sigmoid"の形状
- カーネル"Linear"の形状
- 次は,使用可能なオプションである.
-
"BiasParameter" 1 多項式カーネルおよびシグモイドカーネルのバイアス項 c "GammaScalingParameter" Automatic 先行カーネルのパラメータ 
"KernelType" "RadialBasisFunction" より高次元に写像する際に使うカーネル "MulticlassStrategy" Automatic マルチクラスの分類器を得るために使う方法 "PolynomialDegree" 3 多項式カーネルの多項式 d の次数 - 次は,"MulticlassStrategy"の可能な設定である.
-
"OneVersusOne" クラスの各ペアについて二項分類器を訓練する "OneVersusAll" 各クラスについて1つの二項分類器を訓練する - "GammaScalingParameter"はサポートベクトルの影響を制御する.ガンマの値が大きいと影響の半径は小さくなる.
- "PolynomialDegree"オプションは多項式カーネルタイプに独特である.
- "MulticlassStrategy"オプションは二項分類器のマルチクラス分類器への一般化に使われる. "OneVersusOne"ストラテジは各クラスを互いに対して検定するのに対し,"OneVersusAll"ストラテジは各クラスを訓練集合の残りに対して検定する.
例題
すべて開く すべて閉じる例 (2)
c = Classify[{1, 2, 3, 4} -> {1, 1, 2, 2}, Method -> "SupportVectorMachine"]Information[c]c[1.3]cluster1 = RandomVariate[MultinormalDistribution[{0, 0}, IdentityMatrix[2]], 200];
cluster2 = MapThread[{#1 Cos[#2], #1 Sin[#2]}&, { RandomReal[{4, 5}, 200], RandomReal[{0, 2 Pi}, 200]}];clusters = {cluster1, cluster2};ListPlot[clusters, PlotStyle -> Darker@{Yellow, Blue, Green}]c = Classify[<|Yellow -> clusters[[1]], Blue -> clusters[[2]]|>, Method -> "SupportVectorMachine"]訓練集合と各クラスの確率分布を特徴の関数としてプロットする:
Show[
Plot3D[{
c[{x, y}, "Probability" -> Yellow],
c[{x, y}, "Probability" -> Blue]
},
{x, -4, 4}, {y, -5, 4},
Exclusions -> None],
ListPointPlot3D[Map[Append[#, 1]&, clusters, {2}], PlotStyle -> {Yellow, Blue}]]オプション (5)
"GammaScalingParameter" (1)
"GammaScalingParameter"サブオプションの特定の値で分類器を訓練する:
c = Classify[<|1 -> {1, 23, 1.3, 4}, 2 -> {-4, -3.2, -4, -5}|>, Method -> {"SupportVectorMachine", "GammaScalingParameter" -> 3}]"GammaScalingParameter"はサポートベクトルの影響を制御する.
data1 = RandomVariate[MultinormalDistribution[{0, 0}, IdentityMatrix[2]], 200];
data2 = Transpose[{ #radius * Cos[#angle], #radius * Sin[#angle]}&@<|"radius" -> RandomReal[{5, 8}, 200], "angle" -> RandomReal[{0, 2 Pi}, 200]|>];
trainingset = <|4 -> data1, 2 -> data2|>;ListPlot[{data1, data2}]"GammaScalingParameter"を変えて2つの分類器を訓練する:
c2 = Classify[trainingset, Method -> {"SupportVectorMachine", "GammaScalingParameter" -> 2}]c20 = Classify[trainingset, Method -> {"SupportVectorMachine", "GammaScalingParameter" -> 20}]影響半径がどのように変わったかを見るために,検定集合に対する両者の性能を見る:
test = RandomReal[{-8, 8}, {2000, 2}];Grid[{{ListPlot[{Style@@@Transpose[{test, Hue /@ ( c2[test] / 4)}], data1}],
ListPlot[{Style@@@Transpose[{test, Hue /@ ( c20[test] / 4)}], data1}]}}, Frame -> All]"KernelType" (2)
Classify[<|1 -> {1, 23, 1.3, 4}, 2 -> {-4, -3.2, -4, -5}|>, Method -> {"SupportVectorMachine", "KernelType" -> "Linear"}]2つの分類器を"KernelType"の例を変えて訓練する:
data = {[image] -> 2, [image] -> 5, [image] -> 8, [image] -> 0, [image] -> 2, [image] -> 7, [image] -> 5, [image] -> 1, [image] -> 3, [image] -> 0, [image] -> 3, [image] -> 9, [image] -> 6, [image] -> 2, [image] -> 8, [image] -> 2, [image] -> 0, [image] -> 6, [image] -> 6, [image] -> 1, [image] -> 1, [image] -> 7, [image] -> 8, [image] -> 5, [image] -> 0, [image] -> 4, [image] -> 7, [image] -> 6, [image] -> 0, [image] -> 2, [image] -> 5, [image] -> 3, [image] -> 1, [image] -> 5, [image] -> 6, [image] -> 7, [image] -> 5, [image] -> 4, [image] -> 1, [image] -> 9, [image] -> 3, [image] -> 6, [image] -> 8, [image] -> 0, [image] -> 9, [image] -> 3, [image] -> 0, [image] -> 3, [image] -> 7, [image] -> 4, [image] -> 4, [image] -> 3, [image] -> 8, [image] -> 0, [image] -> 4, [image] -> 1, [image] -> 3, [image] -> 7, [image] -> 6, [image] -> 4, [image] -> 7, [image] -> 2, [image] -> 7, [image] -> 2, [image] -> 5, [image] -> 2, [image] -> 0, [image] -> 9, [image] -> 8, [image] -> 9, [image] -> 8, [image] -> 1, [image] -> 6, [image] -> 4, [image] -> 8, [image] -> 5, [image] -> 8, [image] -> 0, [image] -> 6, [image] -> 7, [image] -> 4, [image] -> 5, [image] -> 8, [image] -> 4, [image] -> 3, [image] -> 1, [image] -> 5, [image] -> 1, [image] -> 9, [image] -> 9, [image] -> 9, [image] -> 2, [image] -> 4, [image] -> 7, [image] -> 3, [image] -> 1, [image] -> 9, [image] -> 2, [image] -> 9, [image] -> 6};clinear = Classify[data, Method -> {"SupportVectorMachine", "KernelType" -> "Linear"}];cpolynomial = Classify[data, Method -> {"SupportVectorMachine", "KernelType" -> "Polynomial"}];clinear[{[image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}]
cpolynomial[{[image], [image], [image], [image], [image], [image], [image], [image], [image], [image]}]"MulticlassStrategy" (1)
"FisherIris"データ集合を使い,2つの分類器を"MulticlassStrategy"オプションを変えて訓練する:
trainingset = ExampleData[{"MachineLearning", "FisherIris"}, "TrainingData"];{c1, c2} = Classify[trainingset, Method -> {"SupportVectorMachine", "MulticlassStrategy" -> #}]& /@ {"OneVersusOne", "OneVersusAll"};検定集合についての両者の確度を見る."OneVersusOne"オプションの方が一般に性能がよい:
testset = ExampleData[{"MachineLearning", "FisherIris"}, "TestData"];ClassifierMeasurements[#, testset, "Accuracy"]& /@ {c1, c2}"PolynomialDegree" (1)
"Mushroom"訓練集合を使い,多項式カーネルタイプの次数を変えて2つの分類器を訓練する:
trainingset = ExampleData[{"MachineLearning", "Mushroom"}, "TrainingData"];{c1, c2} = Classify[trainingset, Method -> {"SupportVectorMachine", "KernelType" -> "Polynomial", "PolynomialDegree" -> #}]& /@ {3, 7};Information[#, "TrainingTime"]& /@ {c1 , c2}