CARET xgbtree警告:“ntree_limit”已弃用,请改用“iteration_range "

42fyovps  于 2023-03-20  发布在  其他
关注(0)|答案(1)|浏览(936)
cv <- trainControl(
  method = "cv",
  number = 5,
  classProbs = TRUE,
  summaryFunction = prSummary,
  seeds = set.seed(123))

turn_grid_xgb <- expand.grid(
  eta = c(0.1,0.3,0.5),
  max_depth = 5,
  min_child_weight = 1,
  subsample = 0.8,
  colsample_bytree = 0.8,
  nrounds = (1:10)*200,
  gamma = 0)

set.seed(123)
suppressWarnings({
  xgb_1 <- train(label~., data = baked_train, 
             method = "xgbTree",
             tuneGrid = turn_grid_xgb,
             trControl = cv,
             verbose = FALSE,
             metric = "F")

嗨,当我试图运行上面的代码时,在R控制台中显示了以下警告,有人知道如何摆脱它吗?我已经在块设置上尝试了suppressWarnings()warning = FALSE,它仍然存在。
谢谢!

WARNING: amalgamation/../src/c_api/c_api.cc:718: `ntree_limit` is deprecated, use `iteration_range` instead.
[02:15:13] WARNING: amalgamation/../src/c_api/c_api.cc:718: `ntree_limit` is deprecated, use `iteration_range` instead.
[02:15:13] WARNING: amalgamation/../src/c_api/c_api.cc:718: `ntree_limit` is deprecated, use `iteration_range` instead.
wljmcqd8

wljmcqd81#

要摆脱xgboost警告,您可以设置verbosity = 0,它将由caret::train传递给xgboost调用:

library(caret)
library(mlbench)
data(Sonar)

cv <- trainControl(
  method = "cv",
  number = 5,
  classProbs = TRUE,
  summaryFunction = prSummary,
  seeds = set.seed(123))

turn_grid_xgb <- expand.grid(
  eta = 0.1,
  max_depth = 5,
  min_child_weight = 1,
  subsample = 0.8,
  colsample_bytree = 0.8,
  nrounds = c(1,5)*200,
  gamma = 0)

set.seed(123)

xgb_1 <- train(Class~., data = Sonar, 
               method = "xgbTree",
               tuneGrid = turn_grid_xgb,
               trControl = cv,
               verbose = FALSE,
               metric = "F",
               verbosity = 0)

当前警告表示xgboost正在更改参数的名称,但插入符号仍提供旧名称。当前它可以工作,但在新的xgboost版本中,参数将被完全替换,如果插入符号函数代码在之前没有更新,则警告将被错误替换。

相关问题