Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tuning ksvm from kernlab

Tags:

r

kernlab

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.

like image 774
GaidinD Avatar asked Nov 11 '22 00:11

GaidinD


1 Answers

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.

like image 78
catastrophic-failure Avatar answered Nov 15 '22 06:11

catastrophic-failure