[R] Caret package and lasso

Max Kuhn mxkuhn at gmail.com
Wed Apr 7 20:03:40 CEST 2010


Linda,

Thanks for the example.

I did this to make it more reproducible:

  set.seed(1)
  X<-matrix(rnorm(50*100),nrow=50)
  y<-rnorm(50*1)

  dimnames(X)

  colnames(X) <- paste("V", 1:nrow(X))

  # Applying caret package

  set.seed(2)
  con<-trainControl(method="cv",number=10)

  data<-NULL
  data<- train(X,y, "lasso", metric="RMSE",tuneLength = 10, trControl = con)

I see your point here, but this code gives the same results:

  fit2 <- enet(X, y, lambda = 0)
  predict(fit2, mode = "fraction", s = data$bestTune$.fraction, type =
"coefficient")$coef

(at least train() names the predictors).

To me, it looks like enet is doing some filtering:

   > dim(X)
   [1]  50 100
   > length(fit2$meanx)
   [1] 56

This appears to be independent of caret. I would contact the package
maintainer off-list and ask.

Max



More information about the R-help mailing list