0
$\begingroup$

I'd like to test the anova rbf kernel included in the kernlab package in caret. Following excelent tutorial (https://topepo.github.io/caret/custom_models.html) I've come up with the following code:

SVManova <- list(type = "Regression", library = "kernlab", loop = NULL)
prmanova <- data.frame(parameter = c("C", "sigma", "degree", "eps"),
                     class = rep("numeric", 4),
                     label = c("Cost", "Sigma", "Degree", "Eps"))
SVManova$parameters <- prmanova
    svmGridanova <- function(x, y, len = NULL) {
    library(kernlab)
    sigmas <- sigest(as.matrix(x), na.action = na.omit, scaled = TRUE, frac = 1)
    expand.grid(sigma = mean(sigmas[-2]), epsilon = 0.000001,
                C = 2 ^(-5:len), degree = 1:2) # len = tuneLength in train
    }
    SVManova$grid <- svmGridanova
svmFitanova <- function(x, y, wts, param, lev, last, weights, classProbs, ...) {
  ksvm(x = as.matrix(x), y = y,
       kernel = "anovadot",
       kpar = list(sigma = param$sigma, degree = param$degree),
       C = param$C, epsilon = param$epsilon,
       prob.model = classProbs,
       ...) #default type = "eps-svr"
}
SVManova$fit <- svmFitanova
    svmPredanova <- function(modelFit, newdata, preProc = NULL, submodels = NULL)
      predict(modelFit, newdata)
    SVManova$predict <- svmPredanova
svmProb <- function(modelFit, newdata, preProc = NULL, submodels = NULL)
  predict(modelFit, newdata, type="probabilities")
SVManova$prob <- svmProb
    svmSortanova <- function(x) x[order(x$C), ]
SVManova$sort <- svmSortanova

I then asked for the model to train some dataset:

set.seed(100) #use the same seed to train different models
svrFitanova <- train(R ~ .,
                data = trainSet,
                method = SVManova,
                preProc = c("center", "scale"),
                trControl = ctrl, tuneLength = 20,
                allowParallel = TRUE) #By default, RMSE and R2 are computed for regression (in all cases, selects the tunning and cross-val model with best value) , metric = "ROC"
#Print the results
svrFitanova

But I get the following error:

Error in train.default(x, y, weights = w, ...) : 
  The tuning parameter grid should have columns C, sigma, degree, eps

I don't see why this error occurs.... tune grid has four columns as requested... Any ideas? Thanks

$\endgroup$
1
$\begingroup$

In svmGridanova, change the variable name from epsilon to eps.

Max

$\endgroup$
  • $\begingroup$ Of course. I also changed eps and Eps to epsilon. Thanks! $\endgroup$ – jpcgandre Aug 30 '14 at 19:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.