私はいくつかのデータを持っており、Y変数は要因です-良いか悪いか。「caret」パッケージの「train」メソッドを使用して、サポート ベクター マシンを構築しています。「トレーニング」機能を使用して、さまざまな調整パラメーターの値を確定し、最終的なサポート ベクター マシンを取得することができました。テストデータについては、「クラス」を予測できます。しかし、テスト データの確率を予測しようとすると、エラーを下回ります (たとえば、私のモデルでは、テスト データの 1 番目のデータ ポイントが y='good' であることがわかりますが、'good' になる確率を知りたいです)。 ...一般に、サポート ベクター マシンの場合、モデルは予測の確率を計算します..Y 変数に 2 つの結果がある場合、モデルは各結果の確率を予測します.最大の確率を持つ結果が最終的な解と見なされます)
**Warning message:
In probFunction(method, modelFit, ppUnk) :
kernlab class probability calculations failed; returning NAs**
以下のサンプルコード
library(caret)
trainset <- data.frame(
class=factor(c("Good", "Bad", "Good", "Good", "Bad", "Good", "Good", "Good", "Good", "Bad", "Bad", "Bad")),
age=c(67, 22, 49, 45, 53, 35, 53, 35, 61, 28, 25, 24))
testset <- data.frame(
class=factor(c("Good", "Bad", "Good" )),
age=c(64, 23, 50))
library(kernlab)
set.seed(231)
### finding optimal value of a tuning parameter
sigDist <- sigest(class ~ ., data = trainset, frac = 1)
### creating a grid of two tuning parameters, .sigma comes from the earlier line. we are trying to find best value of .C
svmTuneGrid <- data.frame(.sigma = sigDist[1], .C = 2^(-2:7))
set.seed(1056)
svmFit <- train(class ~ .,
data = trainset,
method = "svmRadial",
preProc = c("center", "scale"),
tuneGrid = svmTuneGrid,
trControl = trainControl(method = "repeatedcv", repeats = 5))
### svmFit finds the optimal values of tuning parameters and builds the model using the best parameters
### to predict class of test data
predictedClasses <- predict(svmFit, testset )
str(predictedClasses)
### predict probablities but i get an error
predictedProbs <- predict(svmFit, newdata = testset , type = "prob")
head(predictedProbs)
この行の下の新しい質問: 以下の出力によると、9 つのサポート ベクターがあります。12 個のトレーニング データ ポイントのうち 9 個を認識する方法は?
svmFit$finalModel
クラス「ksvm」のサポート ベクター マシン オブジェクト
SV タイプ: C-svc (分類) パラメータ: コスト C = 1
Gaussian Radial Basis カーネル関数。ハイパーパラメータ: シグマ = 0.72640759446315
サポート ベクターの数 : 9
目的関数値: -5.6994 トレーニング エラー: 0.083333