代码之家  ›  专栏  ›  技术社区  ›  user5898644

xgbTree插入符号矩阵是否?

  •  0
  • user5898644  · 技术社区  · 9 年前

    例如,我正在运行以下代码:

    v.ctrl <- trainControl(method = "repeatedcv", repeats = 1,number = 3, 
                       summaryFunction = twoClassSummary,
                       classProbs = TRUE,
                       allowParallel=T)
    
    xgb.grid <- expand.grid(nrounds = 10000,
                            eta = c(0.01,0.05,0.1),
                            max_depth = c(2,4,6,8,10,14))
    set.seed(45)
    xgb_tune <-train(target~.,
                     data = train,
                     method = "xgbTree",
                     trControl = cv.ctrl,
                     tuneGrid = xgb.grid,
                     verbose = TRUE,
                     metric = "LogLoss",
                     nthread = 3)
    

    列车中的错误(目标~,数据=列车,方法=“xgbTree”,trControl=cv.ctrl,: 未使用的参数(data=train,method=“xgbTree”,trControl=cv.ctrl,tuneGrid=xgb.grid,verbose=T,metric=“LogLoss”,nthread=3)

    structure(list(feature19 = c(0.58776, 0.40764, 0.4708, 0.67577, 0.41681, 0.5291, 0.33197, 0.24138, 0.49776, 0.58293), feature6 = c(0.48424, 0.48828, 0.58975, 0.33185, 0.6917, 0.53813, 0.76235, 0.7036,     0.33871, 0.51928), feature10 = c(0.61347, 0.65801, 0.69926, 0.23311,     0.8134, 0.55321, 0.72926, 0.663, 0.49206, 0.55531), feature20 = c(0.39615,     0.49085, 0.50274, 0.6038, 0.37487, 0.53582, 0.62004, 0.63819,     0.37858, 0.40478), feature7 = c(0.55901, 0.38715, 0.50705, 0.76004,     0.3207, 0.54697, 0.31014, 0.21932, 0.4831, 0.52253), feature4 = c(0.5379,     0.52526, 0.44264, 0.28974, 0.65142, 0.41382, 0.44205, 0.47272,     0.6303, 0.56405), feature16 = c(0.41849, 0.45628, 0.37617, 0.39334, 0.46727, 0.36297, 0.3054, 0.41256, 0.6302, 0.41892), feature2 = c(0.62194,  0.5555, 0.61301, 0.27452, 0.74148, 0.49785, 0.5215, 0.46492,     0.54834, 0.58106), feature21 = c(0.32122, 0.37679, 0.35889, 0.74368,     0.18306, 0.47027, 0.40567, 0.47801, 0.41617, 0.35244), feature12 = c(0.56532,     0.55707, 0.49138, 0.24911, 0.69341, 0.42176, 0.41445, 0.45535,     0.62379, 0.5523), target = c(1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L,     1L, 1L)), .Names = c("feature19", "feature6", "feature10", "feature20",     "feature7", "feature4", "feature16", "feature2", "feature21",     "feature12", "target"), row.names = c(NA, 10L), class = "data.frame")
    

    有人知道我是否需要重新处理xgbtree的数据吗? Thx u!

    1 回复  |  直到 7 年前
        1
  •  0
  •   aranglol    9 年前

    我意识到我在R/Caret/machine learning方面有点笨,但在不断检查我的问题的答案后,我看到了你的帖子,我设法让你的代码正常工作。我希望有一个知识更渊博的人能够完全回答你的问题,但与此同时,我所做的就是这样。

    首先,我将您的数据集输入R并尝试运行您的代码。我相信你的控制函数可能有一个输入错误,“cv”中缺少一个“c”,这可能会导致你在使用未使用的参数时出现问题。

    然而,在我解决了这个问题后,出现了多个错误和警告;首先,您使用的是twoClassSummary,但指定了logLoss(注意这里的语法,如果有任何变化,它不是logLoss)……相反,我将这个summaryFunction切换为mnlog,以正确调用logLoss函数,正如我读到的twoClassSummary使用AUC作为其度量。此外,我将训练集中的“target”变量替换为一个简单的字符变量,在本例中为“Y”或“N”。您可以下载csv文件 here .

    之后,我一直收到一个关于您的调优网格的错误,指出实际上您缺少xgBoost方法的调优参数,这些参数可以在caret(可用模型)的文档中找到。我只是为其余参数添加了默认值(其中大多数为1)。可以找到我使用的调谐网格 here .

    control = trainControl(method = "repeatedcv", repeats = 1, number = 3, 
                       summaryFunction = mnLogLoss,
                       classProbs = TRUE,
                       allowParallel=T)
    
    tune = train(x=set[,1:10], y=set[,11], method="xgbTree", trControl=control, 
    tuneGrid = xgb.grid, verbose=TRUE, metric="logLoss", nthread=3)
    

    输出如下所示:

    tune
    eXtreme Gradient Boosting 
    
    10 samples
    10 predictors
    2 classes: 'N', 'Y' 
    
    No pre-processing
    Resampling: Cross-Validated (3 fold, repeated 1 times) 
    Summary of sample sizes: 6, 8, 6 
    Resampling results across tuning parameters:
    
      eta   max_depth  logLoss  
      0.01   2         0.6914816
      0.01   4         0.6914816
      0.01   6         0.6914816
      0.01   8         0.6914816
      0.01  10         0.6914816
      0.01  14         0.6914816
      0.05   2         0.6848399
      0.05   4         0.6848399
      0.05   6         0.6848399
      0.05   8         0.6848399
      0.05  10         0.6848399
      0.05  14         0.6848399
      0.10   2         0.6765847
      0.10   4         0.6765847
      0.10   6         0.6765847
      0.10   8         0.6765847
      0.10  10         0.6765847
      0.10  14         0.6765847
    
    Tuning parameter 'nrounds' was held constant at a value of 10000
    Tuning parameter 'gamma' was held constant at a
     value of 0
    Tuning parameter 'colsample_bytree' was held constant at a value of 1
    Tuning parameter
     'min_child_weight' was held constant at a value of 1
    Tuning parameter 'subsample' was held constant at a value of 1
    logLoss was used to select the optimal model using  the smallest value.
    The final values used for the model were nrounds = 10000, max_depth = 2, eta 
    = 0.1, gamma = 0, colsample_bytree =
     1, min_child_weight = 1 and subsample = 1.
    

    我希望这对你有所帮助,这也是你所寻求的。如果我正确执行log loss命令,我会有点怀疑,因为最大深度似乎对log loss没有任何影响。我使用不同的指标AUC重新运行模型,结果表明,无论发生什么变化,都没有影响,科恩的Kappa也是如此。我猜这是因为只有十个样本,但希望有人能真正解释我做了什么,所以这不仅仅是一个代码转储。