【问题标题】:Why does my code take so long to process?为什么我的代码需要这么长时间才能处理?
【发布时间】:2020-12-22 10:41:30
【问题描述】:

我尝试在我的计算机上运行来自此 web site 的代码。 我使用来自kaggle competition 的数据集 在我的训练数据中有 1022 行和 81 个变量。 我运行这段代码:

hyper_grid <- expand.grid(
  shrinkage = c(.01, .1, .3),
  interaction.depth = c(1, 3, 5),
  n.minobsinnode = c(5, 10, 15),
  bag.fraction = c(.65, .8, 1), 
  optimal_trees = 0,               # a place to dump results
  min_RMSE = 0                     # a place to dump results
)

random_index <- sample(1:nrow(ames_train), nrow(ames_train))
random_ames_train <- ames_train[random_index, ]

# grid search 
for(i in 1:nrow(hyper_grid)) {
  
  # reproducibility
  set.seed(123)
  
  # train model
  gbm.tune <- gbm(
    formula = SalePrice ~ .,
    distribution = "gaussian",
    data = random_ames_train,
    n.trees = 5000,
    interaction.depth = hyper_grid$interaction.depth[i],
    shrinkage = hyper_grid$shrinkage[i],
    n.minobsinnode = hyper_grid$n.minobsinnode[i],
    bag.fraction = hyper_grid$bag.fraction[i],
    train.fraction = .75,
    n.cores = NULL, # will use all cores by default
    verbose = FALSE
  )

我等了 1 个多小时。 我认为这是因为我的笔记本电脑功能不强。 在图片上你可以看到我的电脑的参数。

请回答:我的电脑可以执行这个操作吗? 如果是,我应该等多久?

【问题讨论】:

    标签: r gbm


    【解决方案1】:

    这需要很长时间,因为您要训练 81 个 GBM 模型,而且 GBM 很复杂。要粗略估计训练时间,您可以训练一个模型,然后将该时间乘以 81。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-17
      • 1970-01-01
      • 2019-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-29
      相关资源
      最近更新 更多