Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rm(list = ls(all = TRUE))
- library(glmnet)
- library(caret)
- timeControl <- trainControl(method = "timeslice",
- initialWindow = 950,
- horizon = 1,
- fixedWindow = FALSE,
- returnData=TRUE,
- returnResamp="all",
- savePredictions=TRUE,
- )
- # create grid for parameters evaluation, alpha=1 -> LASSO
- grid <- expand.grid(.alpha=seq(0,1,.1),
- .lambda=seq(50,0,-.1),
- )
- # train the elnet model
- trainModel <- train(y=seq(0.01,10,.01), x=matrix(rep(log(seq(.01,10,.01)),10), nrow = 1000),
- method="glmnet",
- metric="RMSE",
- trControl=timeControl,
- tuneGrid=grid,
- )
- > trainModel$pred[ which(trainModel$pred[,"lambda"]==0 & trainModel$pred[,"Resample"]=="Training01"),]
- pred obs rowIndex alpha lambda Resample
- 501 7.159336 9.51 951 0.0 0 Training01
- 1002 7.163996 9.51 951 0.1 0 Training01
- 1503 7.163973 9.51 951 0.2 0 Training01
- 2004 7.164281 9.51 951 0.3 0 Training01
- 2505 7.163766 9.51 951 0.4 0 Training01
- 3006 7.164378 9.51 951 0.5 0 Training01
- 3507 7.163292 9.51 951 0.6 0 Training01
- 4008 7.163606 9.51 951 0.7 0 Training01
- 4509 7.163839 9.51 951 0.8 0 Training01
- 5010 7.164014 9.51 951 0.9 0 Training01
- 5511 7.164132 9.51 951 1.0 0 Training01
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement