xgbTree插入符号矩阵与否?

时间:2017-07-25 14:02:01

标签: r r-caret

我正在运行以下代码:

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)

错误很简单:

  

火车出错(目标〜。,数据=火车,方法=&#34; xgbTree&#34;,trControl = cv.ctrl,:     未使用的参数(data = train,method =&#34; xgbTree&#34;,trControl = cv.ctrl,tuneGrid = xgb.grid,verbose = T,metric =&#34; LogLoss&#34;,nthread = 3)< / p>

我的数据集

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的数据? 谢谢你!

1 个答案:

答案 0 :(得分:0)

我意识到我在R / Caret /机器学习方面有点像菜鸟,但是在经常检查我的问题的答案后我看到了你的帖子,我设法让你的代码正常工作。我希望知识渊博的人能够完全回答你的问题,但与此同时,我也是这样做的。

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

然而,在我解决了这个问题之后,出现了多个错误和警告;例如,你正在使用twoClassSummary但是指定了logLoss(注意这里的语法,它不是LogLoss以防万一)...而是我把这个summaryFunction切换到mnlog来正确调用logLoss函数,就像我从中读到的那样2ClassSummary使用AUC作为其指标。另外,我用训练集中的“目标”变量替换了一个简单的字符变量,在本例中为“Y”或“N”。您可以下载csv文件here

之后,我一直收到有关您的调优网格的错误,说明基本上您缺少xgBoost方法的调整参数,可以在插入符号文档(可用模型)中找到。我只是添加了其余参数的默认值(其中大多数是1)。我使用的调谐网格可以找到here

我用来实际训练xgb模型的最终代码如下:

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.

我希望这会有所帮助,而且正是你所寻求的。如果我正确地执行了日志丢失命令,我有点怀疑,因为它会显示最大深度字面上对日志丢失没有影响。我使用不同的度量标准AUC重新调整模型,结果显示无论改变什么都没有效果,与Cohen的Kappa相同。我猜这只是因为十个样本,但希望有人能够解释我做了什么,所以这不仅仅是代码转储。