模拟退火算法中mtry的上/下值

时间:2019-12-12 15:36:52

标签: r grid-search hyperparameters simulated-annealing

我从网上获得了这段代码。它使用网格搜索和模拟退火来调整R.Forest的参数。我的疑问是代码中的模拟退火算法在哪里找到mtry参数的起始值和终止值。我的意思是通常情况下,我们为这些类型的算法提供上下限值,但我找不到任何值。结果为我提供了MAE值和mtry的最佳值。从它在哪里计算,我感到惊讶?我用的是library(randomForest)

d=readARFF("Results.arff")
index <- createDataPartition(log10(d$Result), p = .70,list = FALSE)
tr <- d[index, ]
ts <- d[-index, ] 

index_2 <- createFolds(tr$Result, returnTrain = TRUE, list = TRUE)
ctrl <- trainControl(method = "cv", index = index_2, search="grid")

grid_search <- train(log10(Effort) ~ ., data = tr,
                     method = "rf",
                     ## Will create 48 parameter combinations
                     tuneLength = 8,
                     metric = "MAE",
                     preProc = c("center", "scale", "zv"),
                     trControl = ctrl)
getTrainPerf(grid_search)

obj <- function(param, maximize = FALSE) {
  mod <- train(log10(Effort) ~ ., data = tr,
               method = "rf",
               preProc = c("center", "scale", "zv"),
               metric = "MAE",
               trControl = ctrl,
               tuneGrid = data.frame(mtry = 10^(param[1])))##, sigma = 10^(param[2])))
  if(maximize)
    -getTrainPerf(mod)[, "TrainMAE"] else
      getTrainPerf(mod)[, "TrainMAE"]
}
num_mods <- 10

## Simulated annealing from base R
set.seed(45642)
tic()
san_res <- optim(par = c(0), fn = obj, method = "SANN",
                 control = list(maxit = num_mods))
san_res

0 个答案:

没有答案