合奏学习者,装袋和adaboosting

时间:2016-02-18 17:15:26

标签: r math machine-learning statistics ensemble-learning

我实现了两种集成技术,即r中的baggingadaboosting,可以与任何学习者一起使用。

我的网格:

grids <- list(
              "knn" = expand.grid(k = c(3, 5, 7, 9, 11, 13, 15))
             )

我的变量:

n <- c(2, 4) 
boots <- createResample(trainData$BAD, times = 50, list = TRUE)

我的装袋:

for(i in seq_along(grids)) { 

            method <- names(grids[i])

            for(j in 1:nrow(grids[[i]])) {
                grid <- data.frame(grids[[i]][j, ])
                colnames(grid) <- names(grids[[i]])

                # start bagging
                bagging <- foreach(k = 1:length(n)) %do% {

                    predictions <- foreach(m = 1:n[k], .combine = cbind) %do% {

                        tune <- train(BAD ~ ., data = trainData, method = method, trControl = ctrl, tuneGrid = grid, 
                                      metric = "ROC")

                        pred <- c(predict(tune, newdata = trainData, type = "prob")$BAD,
                                  predict(tune, newdata = testData, type = "prob")$BAD)
                    }
                    pred_means <- rowMeans(predictions) 
                }   
                resu_bag <- c(resu_bag, unlist(bagging))  
            }
        }

我的adaboosting:

for(i in seq_along(grids)) { 
    method <- names(grids[i])

    for(j in 1:nrow(grids[[i]])) {
        grid <- data.frame(grids[[i]][j, ])
        colnames(grid) <- names(grids[[i]])

        # start boosting
        boosting <- foreach(k = 1:length(n)) %do% {

            predictions <- foreach(m = 1:n[k], .combine = cbind) %do% {
            train_boo <- trainData[boots[[m]], ]

            tune <- train(BAD ~ ., data = train_boo, method = method, trControl = ctrl, tuneGrid = grid, 
                          metric = "ROC")
            pred <- c(predict(tune, newdata = trainData, type = "prob")$BAD,
                      predict(tune, newdata = testData, type = "prob")$BAD)
          }
            pred_means <- rowMeans(predictions)
        }
        resu_boo <- c(resu_boo, unlist(boosting))  
    }
}

我的问题:

  1. 请问您的实施是否正确?
  2. 模型的表现与单个学习者的表现相同甚至更差。为什么会这样?我做错了什么?
  3. 非常感谢你!

0 个答案:

没有答案