针对二进制分类的R中的Xgboost超参数调整

问题描述 投票:0回答:1

我不熟悉R,并尝试对xgboost-二进制分类进行超参数调整,但是我遇到了错误,如果有人可以帮助我,我将不胜感激

as.matrix(cv.res)[,3]中的错误:下标超出范围另外:警告消息:'early.stop.round'已过时。请改用“ early_stopping_rounds”。请参阅help(“ Deprecated”)和help(“ xgboost-deprecated”)。

请在下面的代码段中找到

 I would appreciate if some one could provide another alternative too apart from this approach in R

X_Train <- as(X_train, "dgCMatrix")


GS_LogLoss = data.frame("Rounds" = numeric(), 
                        "Depth" = numeric(),
                        "r_sample" = numeric(),
                        "c_sample" = numeric(), 
                        "minLogLoss" = numeric(),
                        "best_round" = numeric())

for (rounds in seq(50,100, 25)) {
  
  for (depth in c(4, 6, 8, 10)) {
    
    for (r_sample in c(0.5, 0.75, 1)) {
      
      for (c_sample in c(0.4, 0.6, 0.8, 1)) {
        
        for (imb_scale_pos_weight in c(5, 10, 15, 20, 25))	{
          
          for (wt_gamma in c(5, 7, 10)) {
            
            for (wt_max_delta_step in c(5,7,10)) {
              
              for (wt_min_child_weight in c(5,7,10,15))	{
                
                
                set.seed(1024)
                eta_val = 2 / rounds
                cv.res = xgb.cv(data = X_Train, nfold = 2, label = y_train, 
                                nrounds = rounds, 
                                eta = eta_val, 
                                max_depth = depth,
                                subsample = r_sample, 
                                colsample_bytree = c_sample,
                                early.stop.round = 0.5*rounds,
                                scale_pos_weight= imb_scale_pos_weight,
                                max_delta_step = wt_max_delta_step,
                                gamma = wt_gamma,
                                objective='binary:logistic', 
                                eval_metric = 'auc',
                                verbose = FALSE)
                
                print(paste(rounds, depth, r_sample, c_sample, min(as.matrix(cv.res)[,3]) ))
                GS_LogLoss[nrow(GS_LogLoss)+1, ] = c(rounds, 
                                                     depth, 
                                                     r_sample, 
                                                     c_sample, 
                                                     min(as.matrix(cv.res)[,3]), 
                                                     which.min(as.matrix(cv.res)[,3]))
                
              }
            }
          }
        }	
      }
    }
  }	
}

`

r machine-learning xgboost grid-search hyperparameters
1个回答
0
投票

要选择超参数,可以使用元包tidymodels,尤其是包parsnipparsniprsamplersample

这样的工作流程会起作用:

yardstick

请注意,与yardstick中的原始名称相比,模型说明中的名称可能会发生更改,因为tune是一个统一的接口,在多个模型中具有一致的名称。参见tune

© www.soinside.com 2019 - 2024. All rights reserved.