[R] tuning values of SVM

javed khan j@vedbtk111 @end|ng |rom gm@||@com
Wed Dec 11 10:51:07 CET 2019


I want to optimize the cost and sigma parameters of SVM using Caret and
PSO. The following code I am using after imported the data.

svm_obj <- function(param, maximize = FALSE) {
  mod <- train(log10(Effort) ~ ., data = tr,
               method = "svmRadial",
               preProc = c("center", "scale", "zv"),
               metric = "MAE",
               trControl = ctrl,
               tuneGrid = data.frame(C = 10^(param[1]), sigma =
10^(param[2])))
  if(maximize)
    -getTrainPerf(mod)[, "TrainRMSE"] else
      getTrainPerf(mod)[, "TrainRMSE"]
}
  num_mods <- 10

And for the PSO, the following code

library(pso)
  set.seed(45642)
  pso_res <- psoptim(par = c(0, 0), fn = svm_obj,
                     lower = c(0.2, 4), upper = c(0.1, 0.9),
                     control = list(maxit = ceiling(num_mods)))
  pso_res

Now, it gives me the result but when I try to get the optimal values of C
and sigma using pso_res$par, it gives me the values:

0.1 and 0.9

The minimum value I provided for C is 0.2 (and maximum value is 4 as shown
above), but how can it give me the optimal value 0.1, which is even lower
than the minimum provided value.

Where I am doing mistake?

	[[alternative HTML version deleted]]



More information about the R-help mailing list