【问题标题】:Custom Xgboost Hyperparameter tuning自定义 Xgboost 超参数调优
【发布时间】:2017-04-29 19:53:43
【问题描述】:

我使用以下代码来调整我的 Xgboost 实现的参数,改编自 here

searchGridSubCol <- expand.grid(subsample = c(0.5, 0.75, 1), 
                                colsample_bytree = c(0.6, 0.8, 1))
ntrees <- 100

#Build a xgb.DMatrix object
#DMMatrixTrain <- xgb.DMatrix(data = yourMatrix, label = yourTarget)

rmseErrorsHyperparameters <- apply(searchGridSubCol, 1, function(parameterList){

  #Extract Parameters to test
  currentSubsampleRate <- parameterList[["subsample"]]
  currentColsampleRate <- parameterList[["colsample_bytree"]]

  xgboostModelCV <- xgb.cv(data = as.matrix(train), nrounds = ntrees, nfold = 5, showsd = TRUE, label = traintarget,
                           metrics = "rmse", verbose = TRUE, "eval_metric" = "rmse",
                           "objective" = "reg:linear", "max.depth" = 15, "eta" = 2/ntrees,                               
                           "subsample" = currentSubsampleRate, "colsample_bytree" = currentColsampleRate)

  xvalidationScores <- as.data.frame(xgboostModelCV)
  #Save rmse of the last iteration
  rmse <- tail(xvalidationScores$test.rmse.mean, 1)

  return(c(rmse, currentSubsampleRate, currentColsampleRate))

})

但是,我在存储 XGBoostModelCV 时收到以下错误:

 Error in as.data.frame.default(xgboostModelCV) : 
  cannot coerce class ""xgb.cv.synchronous"" to a data.frame

谁能向我解释导致此错误的原因以及我该如何解决?

【问题讨论】:

  • 帮助说 xgb.cv 的返回属于 xgb.cv.synchronous 类,所以它很可能不是数据框,建议 print(xgboostModelCV, verbose=TRUE) 并寻找可能感兴趣的结构。应该有类似xgboostModelCV$evaluation_logxgboostModelCV$best_iteration
  • 我发现了问题,在我删除 as.dataframe 时使用的 xgboost 版本中它工作正常
  • 不,不固定
  • 有没有人如何修复上面的代码?

标签: r xgboost


【解决方案1】:

以上问题应通过以下方式解决:

xvalidationScores <- xgboostModelCV
#Save rmse of the last iteration
rmse <- tail(xvalidationScores$evaluation_log$test_rmse_mean, 1)

【讨论】:

    猜你喜欢
    • 2020-06-10
    • 1970-01-01
    • 2020-09-10
    • 2020-01-31
    • 2021-09-29
    • 2021-06-02
    • 2017-09-24
    • 2021-12-15
    • 2021-02-11
    相关资源
    最近更新 更多