I want to use an SVM implementation in R to do some regression. I tried using svm
from e1071
already but I am limited by the kernel functions there. So I moved on to ksvm
from kernlab
. But I have a major disadvantage that a tuning function has not been provided in kernlab
(like tune.svm
in e1071
). Can someone explain how do I tune the parameters for different kernels there?
PS. I want to particularly use the rbfdot
kernel. So if at least someone can help me understand how to tune sigma, I'd be extremely grateful.
PPS. I'm completely aware that the "automatic"
value for kpar can be used "to calculate a good sigma". But I need something more tangible and more along the lines of tune.svm
.
Either you write your own wrapper (wouldn't be that hard to be honest) or you could try already proven implemented solutions, like mlr
and caret
.
mlr
tutorial has an example about it.
ps = makeParamSet(
makeDiscreteParam("C", values = 2^(-2:2)),
makeDiscreteParam("sigma", values = 2^(-2:2))
)
ctrl = makeTuneControlGrid()
rdesc = makeResampleDesc("CV", iters = 3L)
res = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc, par.set = ps, control = ctrl)
This will perform 3-fold cross-validation to select parameters from the grid and evaluate accuracy on the iris dataset. You can, of course, change resampling strategies (leave-one-out, monte-carlo CV, CV, repeated CV, bootstrap validation and holdout are all implemented), search strategy (grid search, random search, generalized simulated annealing and iterated F-race are all supported) and evaluation metrics.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With