10
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")

Hi, when I was trying to run the above code, the following warnings are shown in the R console. Does anyone know how to get rid of it? I have tried suppressWarnings() , warning = FALSE on the chunk setting, and it is still there.

thx!!

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.

1 Answer 1

8

To get rid of xgboost warnings you can set verbosity = 0 which will be passed on by caret::train to the xgboost call:

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)

The current warning means xgboost is changing the name of an argument, but caret is still supplying the old name. Currently it works but with new xgboost versions the argument will be completely replaced, if carets function code is not updated by then the warning will be replaced by an error.

5
  • Is the warning message perhaps something that needs to be addressed? Or can it simply be ignored?
    – User2321
    Jul 5, 2022 at 5:15
  • 2
    the current warning means xgboost is changing the name of an argument, but caret is still supplying the old name. Currently it works but with new xgboost versions the argument will be completely replaced, if carets function code is not updated by then the warning will be replaced by an error.
    – missuse
    Jul 5, 2022 at 5:26
  • Thanks @missuse - I recognized the reason for the warning but just wanted to suppress it for now - this was very helpful! Apr 19, 2023 at 21:57
  • But I didn't use ntree_limit argument, how come the message reminds me that? Jul 4, 2023 at 6:50
  • Caret probably uses it internally with this method
    – missuse
    Jul 5, 2023 at 10:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.