biomodhub / biomod2

BIOMOD is a computer platform for ensemble forecasting of species distributions, enabling the treatment of a range of methodological uncertainties in models and the examination of species-environment relationships.
85 stars 22 forks source link

Tuned XGBOOST model Error - BIOMOD version 4.2-5 #430

Closed suicmezburak closed 6 months ago

suicmezburak commented 6 months ago

Hello, As the title suggests, after tuning the settings for the XGBoost model, the model is not working and is giving an error.

The sequence of code before encountering an error;

# Define individual models options
opt.d <- bm_ModelingOptions(
  data.type = "binary",
  models = c("XGBOOST"),
  strategy = "bigboss",
  bm.format = x_data,
  calib.lines = cv.k
  )

### tune parameters for XGBOOST
tuned.xgboost <- bm_Tuning(
  model = "XGBOOST", 
  tuning.fun = "xgbTree", 
  bm.options = opt.d@options$XGBOOST.binary.xgboost.xgboost,
  bm.format = x_data,
  calib.lines = cv.k
)

## Integrate tuned list to opt.d
user.val <- list()
user.val$XGBOOST.binary.xgboost.xgboost <- tuned.xgboost
# +Actually, I will add other models, but to keep the error code short, I removed them.

opt.d <- bm_ModelingOptions(
  data.type = "binary", 
  models = c("XGBOOST"), 
  strategy = "user.defined", 
  user.val = user.val, 
  bm.format = x_data, 
  calib.lines = cv.k
)

## Modelling
# by algorithm
x_model_output <- 
  BIOMOD_Modeling(
    bm.format = x_data,
    modeling.id = "AllModels",
    models = c("XGBOOST"),
    CV.strategy = "user.defined",
    CV.user.table = cv.k,
    CV.do.full.models = FALSE,
    OPT.user = opt.d,
    metric.eval = c("TSS", "ROC"),
    var.import = 3
  )

The error message:

-=-=-=--=-=-=- x_PA1_RUN1_XGBOOST 
Error in check.booster.params(params, ...) : 
  Same parameters in 'params' and in the call are not allowed. Please check your 'params' list.

*** Error in  XGBOOST , calibration failed
*** inherits(g.pred,'try-error')
   ! Note :  x_PA1_RUN1_XGBOOST failed!

-=-=-=--=-=-=- x_PA1_RUN2_XGBOOST 
Error in check.booster.params(params, ...) : 
  Same parameters in 'params' and in the call are not allowed. Please check your 'params' list.

*** Error in  XGBOOST , calibration failed
*** inherits(g.pred,'try-error')
   ! Note :  x_PA1_RUN2_XGBOOST failed!

-=-=-=--=-=-=- x_PA1_RUN3_XGBOOST 
Error in check.booster.params(params, ...) : 
  Same parameters in 'params' and in the call are not allowed. Please check your 'params' list.

*** Error in  XGBOOST , calibration failed
*** inherits(g.pred,'try-error')
   ! Note :  x_PA1_RUN3_XGBOOST failed!

### This error message persists for all PA and RUNs.

! All models failed

Based on the error message, as an example, I am sharing the configuration content for PA1_RUN1.

> opt.d@options[["XGBOOST.binary.xgboost.xgboost"]]@args.values[["_PA1_RUN1"]]
$missing
[1] NA

$params
list(nrounds = 50, max_depth = 1, eta = 0.4, gamma = 0, colsample_bytree = 0.6, 
    min_child_weight = 1, subsample = 0.5)

$nrounds
[1] 4

$verbose
[1] 1

$print_every_n
[1] 1

$save_name
[1] "xgboost.model"

$callbacks
list()

$max.depth
[1] 2

$eta
[1] 1

$nthread
[1] 2

$objective
[1] "binary:logistic"

The error indicates that there are duplicate parameters for XGBOOST in the settings. Is the reason for this that I created opt.d again after tuning the settings? The code was actually working, and I started getting errors without making any changes.

Thanks in advance, Burak

HeleneBlt commented 6 months ago

Hi !

Thanks for testing and your reproducible example. It seems some changes in Xgboost package went faster than expected.

I push some modifications into the GitHub version. Could you reinstall biomod2 and try again? 🙏

Thanks! Hélène

suicmezburak commented 6 months ago

indeed code worked this time, thanks!!