1 year ago

#244155

test-img

Mateo Quiguirí

R- Xgboost: Error in xgb.DMatrix unused argument

This is my first question here so I'm sorry if I'm not clear.

I was building an Xgboost model to forecast multiple time series. I've created the train and test xgb.DMatrix, also the xgb_trcontrol and xgb_grid tunning parameters, nevertheless when I try to build the model I get an error message like this:

Error in [.xgb.DMatrix(x, 0, , drop = FALSE) : unused argument (drop = FALSE)

Also, all the columns in the train and test matrix are numeric. Please find the code below:

    xgb_train <- base_proyecto[1:split_factor,]
    xgb_test <- base_proyecto[(split_factor+1):132,]
    #Transform train and test data to DMatrix form
    train_Dmatrix <- xgb_train %>% #Here I've ommited date, and target variable
      dplyr::select(-c(1,10)) %>% mutate(year=as.numeric(year),month=as.numeric(month)) %>% 
      as.matrix() %>% 
      xgb.DMatrix()
    
    pred_Dmatrix <- xgb_test %>%  #Here I've ommited date, and target variable
      dplyr::select(-c(1,10)) %>% mutate(year=as.numeric(year),month=as.numeric(month)) %>% 
      as.matrix() %>% 
      xgb.DMatrix()
    
    targets <- xgb_train$credito_total
    
    #Cross-validation
    xgb_trcontrol <- trainControl(
      method = "cv", 
      number = 5,
      allowParallel = TRUE, 
      verboseIter = FALSE, 
      returnData = FALSE
    )
    
    #Building parameters set
    xgb_grid <- base::expand.grid(
      list(
        nrounds = c(100,200),
        max_depth = c(10,15,20), 
        colsample_bytree = seq(0.5), 
        eta = 0.1,
        gamma = 0,
        min_child_weight = 1,  
        subsample = 1)
    )
    #Building the model (The error message pops up here)
    model_xgb <- train(
      train_Dmatrix,targets,
      trControl = xgb_trcontrol,
      tuneGrid = xgb_grid,
      method = "xgbTree",
      nthread = 1
    )

PD: My data looks like this

> head(base_proyecto)
  credito_total  google_q1 google_q2 google_q3  google_q4 inflacion tasa_activa tasa_pasiva precio_wti      fecha
1     -2.390521 -1.2273561 -2.056537  -1.11448 -1.2664245 0.2832895   1.3848000  -1.4575066  0.5764112 2010-10-01
2     -2.027531 -1.2273561 -2.056537  -1.11448 -1.2664245 0.3342099   1.3848000  -1.4575066  0.6711702 2010-11-01
3     -2.121730 -1.2273561 -2.056537  -1.11448 -1.2664245 1.0908061   0.8240173  -1.4904277  0.8905438 2010-12-01
4     -1.834393 -1.0333890 -1.337906  -1.11448 -1.2664245 1.6026221   0.6299002  -1.0459930  0.9052552 2011-01-01
5     -1.280232 -0.5484713 -1.158248  -1.11448  0.4406159 1.2168620  -0.1034311  -1.1118351  0.9013610 2011-02-01
6     -1.131422 -1.0333890  0.997645  -1.11448 -0.7786986 0.5394940   0.7593116  -0.9801508  1.4893860 2011-03-01
  year yday month
1 2010  274    10
2 2010  305    11
3 2010  335    12
4 2011    1     1
5 2011   32     2
6 2011   60     3

Any suggestions on how to fix this are welcome?

r

xgboost

xgbregressor

0 Answers

Your Answer

Accepted video resources