简体   繁体   中英

Setting the parameters for SVM Classification in R

Description:

  1. For a data set, I would like to apply SVM by using radial basis function ( RBF ) kernel with Weston, Watkins native multi-class .
  2. The rbf kernel parameter sigma must be tuned and I want to use k-folds cross validation to do this. I consider a fixed C .

Solution:

It seems that I can use the nice package mlr to do this, So, to tune the rbf parameter sigma using CV for MSVM classification, (using this tutorial )

#While C is fix = 3, define a range to search sigma over it. Search between [10^{-6}, 10^{6}]
num_ps = makeParamSet(
  makeDiscreteParam("C", values = 3),
  makeNumericParam("sigma", lower = -6, upper = 6, trafo = function(x) 10^x)
)
#Define the Grid search method
ctrl = makeTuneControlGrid()
#Apply the k-folds CV
rdesc = makeResampleDesc("CV", iters = 3L)

res = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc,
  par.set = num_ps, control = ctrl)

Question:

For this part

res = tuneParams("classif.ksvm", task = iris.task, resampling = rdesc,
      par.set = num_ps, control = ctrl)

According to the documentation, by using the integrated learner classif.ksvm , I'm asking to apply the multiclass classification that is defined in the package ksvm .

How can I know which method and kernel type are used? I mean, how to force the learner classif.ksvm to use the classification type ( kbb-svc ) and the kernel ( rbfdot ) which are already defined in ksvm ?

If this is not possible, then how to define a new learner with all of my requirements?

You have to set the fixed parameters within the learner. Therefore you first have to create it:

library(mlr)
lrn = makeLearner("classif.ksvm", par.vals = list(C = 3, type = "kbb-svc", kernel = "rbfdot"))

Then you only define the parameters that you want to change within the ParamSet

num_ps = makeParamSet(
  makeNumericParam("sigma", lower = -6, upper = 6, trafo = function(x) 10^x)
)

Then you can do the tuning as in your example

ctrl = makeTuneControlGrid()
rdesc = makeResampleDesc("CV", iters = 3L)
res = tuneParams(lrn, task = iris.task, resampling = rdesc, par.set = num_ps, control = ctrl)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM