Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. rm(list = ls(all = TRUE))
  2.  
  3.  
  4. library(glmnet)
  5. library(caret)
  6.  
  7. timeControl <- trainControl(method = "timeslice",
  8. initialWindow = 950,
  9. horizon = 1,
  10. fixedWindow = FALSE,
  11. returnData=TRUE,
  12. returnResamp="all",
  13. savePredictions=TRUE,
  14. )
  15.  
  16.  
  17. # create grid for parameters evaluation, alpha=1 -> LASSO
  18.  
  19. grid <- expand.grid(.alpha=seq(0,1,.1),
  20. .lambda=seq(50,0,-.1),
  21. )
  22.  
  23. # train the elnet model
  24.  
  25. trainModel <- train(y=seq(0.01,10,.01), x=matrix(rep(log(seq(.01,10,.01)),10), nrow = 1000),
  26. method="glmnet",
  27. metric="RMSE",
  28. trControl=timeControl,
  29. tuneGrid=grid,
  30. )
  31.  
  32. > trainModel$pred[ which(trainModel$pred[,"lambda"]==0 & trainModel$pred[,"Resample"]=="Training01"),]
  33. pred obs rowIndex alpha lambda Resample
  34. 501 7.159336 9.51 951 0.0 0 Training01
  35. 1002 7.163996 9.51 951 0.1 0 Training01
  36. 1503 7.163973 9.51 951 0.2 0 Training01
  37. 2004 7.164281 9.51 951 0.3 0 Training01
  38. 2505 7.163766 9.51 951 0.4 0 Training01
  39. 3006 7.164378 9.51 951 0.5 0 Training01
  40. 3507 7.163292 9.51 951 0.6 0 Training01
  41. 4008 7.163606 9.51 951 0.7 0 Training01
  42. 4509 7.163839 9.51 951 0.8 0 Training01
  43. 5010 7.164014 9.51 951 0.9 0 Training01
  44. 5511 7.164132 9.51 951 1.0 0 Training01
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement