Search code examples
rr-caretglmnet

Caret: Error in switch(tolower(trControl$method), oob = NULL, alt_cv = , cv = createFolds(y,


I'm using caret package to tune alpha and lambda parameters for glmnet model. My features are in X (dataframe, 47 obs. of 14474 variables, a p>>N problem) and the dependent variable, y is a dataframe of 47 obs. of 1 variable.

When I try

   trC = trainControl(method=cv, number=10)  
   fitModel = train(X, y, trControl=trC, method="glmnet")  

I get

 Error en switch(tolower(trControl$method), oob = NULL, alt_cv = , cv = createFolds(y,:   
   EXPR must be a length 1 vector
 Además: Mensajes de aviso perdidos
 In if (trControl$method == "oob" & !(method %in% c("rf", "treebag",  :
 la condición tiene longitud > 1 y sólo el primer elemento será usado

I've tried transposing y, and also changing to class(y) = "numeric", instead of "data.frame" but I get the same error, that I don't understand. Any clue?


Solution

  • Use method = "cv" not method = cv.

    Max