1

R の gbm パッケージには、各フォールドを独自のノードに送信することで交差検証を並列化する便利な機能があります。さまざまなハイパーパラメーターで実行される複数の交差検証済み GBM モデルを構築したいと考えています。理想的には、私は複数のコアを持っているので、これらの複数のモデルの構築を並列化することもできました。12 個のコアを使用すると、理論的には、3 倍の検証を使用して 4 つのモデルを同時に構築できます。このようなもの:

tuneGrid <- expand.grid(
        n_trees = 5000, 
        shrink = c(.0001),
        i.depth = seq(10,25,5),
        minobs = 100,
        distro = c(0,1) #0 = bernoulli, 1 = adaboost
        )
cl <- makeCluster(4, outfile="GBMlistening.txt")
registerDoParallel(cl) #4 parent cores to run in parallel
err.vect <- NA #initialize
system.time(
err.vect <- foreach (j=1:nrow(tuneGrid), .packages=c('gbm'),.combine=rbind) %dopar% {
        fit <- gbm(Label~., data=training, 
            n.trees = tuneGrid[j, 'n_trees'], 
            shrinkage = tuneGrid[j, 'shrink'],
            interaction.depth=tuneGrid[j, 'i.depth'], 
            n.minobsinnode = tuneGrid[j, 'minobs'], 
            distribution=ifelse(tuneGrid[j, 'distro']==0, "bernoulli", "adaboost"),
            w=weights$Weight,
            bag.fraction=0.5,
            cv.folds=3,
            n.cores = 3) #will this make 4X3=12 workers?
        cv.test <- data.frame(scores=1/(1 + exp(-fit$cv.fitted)), Weight=training$Weight, Label=training$Label)
        print(j) #write out to the listener
        cbind(gbm.roc.area(cv.test$Label, cv.test$scores), getAMS(cv.test), tuneGrid[j, 'n_trees'], tuneGrid[j, 'shrink'], tuneGrid[j, 'i.depth'],tuneGrid[j, 'minobs'], tuneGrid[j, 'distro'], j )
}
)
stopCluster(cl) #clean up after ourselves

私はキャレット パッケージを使用しますが、キャレットでデフォルト設定されているものを超えるハイパーパラメータがいくつかあるため、現時点では独自のカスタム モデルをキャレットで構築したくありません。どの並列バックエンドが使用されるかに影響することを知っているので、私は Windows マシンを使用しています。

これを行うと、起動した 4 つのクラスターのそれぞれが、それぞれ 3 つのワーカーを生成し、合計 12 のワーカーが離れていきますか? または、一度に動作するコアは 4 つだけですか?

4

1 に答える 1