1

e1071を使用すると、SVMモデルのパラメーターを調整できます。

svmmodels <- lapply(trainingtemp, function(data)
                    {
                      svm.tune <- tune.svm(label~., data=data,
                                           gamma=10^(-3:0), cost=10^(-3:3));
                      svm(label~., data=data,
                          method="C-classification",
                          kernel="radial", cost=svm.tune$best.parameters$cost, 
                               gamma=svm.tune$best.parameters$gamma)
                    })

ただし、特定のデータでは、tune.svmによって空のモデルが返されます(これにはいくつかの理由が考えられます)。tune.svmが次のエラーメッセージを返した場合、svm関数のデフォルトパラメータを使用できるこの状況でtryCatchを使用する方法。

Error in predict.svm(ret, xhold, decision.values = TRUE) : 
 Model is empty!
Calls: lapply ... svm.formula -> svm.default -> na.action -> predict -> predict.svm
Execution halted
4

1 に答える 1

2

これは機能するはずです:

tryCatch(
     svm.tune <- tune.svm(label~., data=data,
                            gamma=10^(-3:0), cost=10^(-3:3))
     svm(label~., data=data,
                      method="C-classification",
                      kernel="radial", cost=svm.tune$best.parameters$cost, 
                           gamma=svm.tune$best.parameters$gamma)
}, error = function(err) {
  ## here you can your svm with defualt parameter 
   svm(label~., data=data,
                      method="C-classification",
                      kernel="radial")
})
于 2013-03-01T14:02:07.540 に答える