块运行时间和编织运行时间问题

时间:2019-03-04 06:23:57

标签: r knitr chunked-encoding

我得到了以下代码。

library(gbm)
library(magrittr)

mydata = read.csv(file="optometry_student.csv",header=T,sep=",")
set.seed(24)
mycombinations = expand.grid(shrinkage=c(0.001,0.01,0.1),interaction.depth=c(3,6,9),bag.fraction=c(0.5,0.5,0.5),optimal_trees=0,min_deviance=0)
for(i in 1:nrow(mycombinations)) {
  set.seed(24)
  bagging_m <- gbm(
    formula = tabxneg0~.,
    distribution="bernoulli",
    data = mydata,
    n.trees = 500,
    interaction.depth = mycombinations$interaction.depth[i],
    shrinkage = mycombinations$shrinkage[i],
    bag.fraction = mycombinations$bag.fraction[i],
    cv = 5
  )
  mycombinations$optimal_trees[i] <- which.min(bagging_m$cv.error)
  mycombinations$min_deviance <-min(bagging_m$cv.error)
}
mycombinations %>%
  dplyr::arrange(min_deviance) %>%
  head(5)

当我第一次运行此代码时,大约需要2分钟才能完成。但是,当我将其编织为pdf时,它始终处于运行状态,无法获取输出

而且,当我第二次尝试运行此块时,它也无法完成。

有人知道导致相同代码运行时间不同的原因吗?

0 个答案:

没有答案