I wonder it is possible to use random search in a predefined grid. For example, my grid has alpha
and lambda
for glmnet
method. alpha
is between 0 and 1, and lambda
is between -10 to 10. I want to use random search 5 times to randomly try points in this bound. I wrote the following code for grid search and it works fine, but I cannot modify it for random search in a bound.
rand_ctrl <- trainControl(method = "repeatedcv", repeats = 5,
search = "random")
grid <- expand.grid(alpha=seq(0,1,0.1),lambda=seq(-10,10,1)) # I think this should be modified
rand_search <- train(Response ~ ., data = train_dat,
method = "glmnet",
## Create 20 random parameter values
metric = "RMSE",
tuneLength = 5,
preProc = c("scale"),
tuneGrid = grid,
trControl = rand_ctrl)