首页 文章

在插入符号中设置种子平行随机森林以获得可重现的结果

提问于
浏览
2

我希望使用插入符号包并行运行随机森林,我希望设置种子以获得可重复的结果,如Fully reproducible parallel models using caret . 但是,我没有't understand line 9 in the following code taken from caret help: why do we sample 22 (plus the last model in line 12, 23) integer numbers (12 values for parameter k are evaluated)? For information, I wish to run 5-fold CV to evaluate 584 values for RF parameter ' mtry' . 任何帮助深表感谢 . 谢谢 .

## Not run:

## Do 5 repeats of 10-Fold CV for the iris data. We will fit
## a KNN model that evaluates 12 values of k and set the seed
## at each iteration.

set.seed(123)
seeds <- vector(mode = "list", length = 51)
for(i in 1:50) seeds[[i]] <- sample.int(1000, 22) # Why 22?

## For the last model:
seeds[[51]] <- sample.int(1000, 1)

ctrl <- trainControl(method = "repeatedcv", 
                 repeats = 5,
                 seeds = seeds)

1 回答

  • 1

    我说这是一个错误,应该是 12 而不是22 .

    根据我的理解,你将运行模型10 * 5 = 50次, for each value of k . 因此,对于 each i在1:50,你需要 12 seeds (每k一个) . 获得最佳k后,您将运行最终模型 . 这次,您只需要一个种子(不再重复重采样) .

相关问题