1

In trying to apply the xgb.create.features(model, data, ...) function included in the xgboost package in R and covered in the User Manual, I am running into an exception I do not understand. Here is a reproducible example:

library(xgboost)
data(mtcars)

X = as.matrix(mtcars[, -9])
Y = mtcars$am

dtrain = xgb.DMatrix(data = X, label = Y)

model = xgb.train(data = dtrain, 

                                     feval = performance_fun_F,

                                     verbose =0,  maximize = TRUE, 

                                     params = list(objective = "binary:logistic",

                                                   eta = 0.1,

                                                   max_depth = 6,

                                                   subsample = 0.8,

                                                   lambda = 0.1 ), 

                                    nrounds = 10)

dtrain1 = xgb.create.features(model, dtrain)

Error: not-yet-implemented method for cbind2(<xgb.DMatrix>, <dgCMatrix>).
 ->>  Ask the package authors to implement the missing feature.
Traceback:

1. xgb.create.features(model, dtrain)
2. cBind(data, sparse.model.matrix(~. - 1, cols))
3. base::cbind(..., deparse.level = deparse.level)
4. cbind(deparse.level, ...)
5. cbind2(..1, r)
6. cbind2(..1, r)
7. .bail.out.2(.Generic, class(x), class(y))
8. stop(gettextf("not-yet-implemented method for %s(<%s>, <%s>).\n ->>  Ask the package authors to implement the missing feature.", 
 .     fun, cl1[1L], cl2[1L]), call. = FALSE, domain = NA)
halfer
  • 19,824
  • 17
  • 99
  • 186
user8270077
  • 4,621
  • 17
  • 75
  • 140

1 Answers1

1

You should supply the matrix X to the xgb.create.features and not dtrain:

Example:

library(xgboost)

data(mtcars)
X = as.matrix(mtcars[, -9])
dtrain = xgb.DMatrix(data = X, label = Y)

model = xgb.train(data = dtrain, 
                  eval = "auc",
                  verbose =0,  maximize = TRUE, 
                  params = list(objective = "binary:logistic",
                                eta = 0.1,
                                max_depth = 6,
                                subsample = 0.8,
                                lambda = 0.1 ), 
                  nrounds = 10)

dtrain1 = xgb.create.features(model, X)
dtrain1 = xgb.DMatrix(data = dtrain1, label = Y)

and now:

bst <- xgb.train(data = dtrain1, 
                 eval = "auc",
                 verbose =0,  maximize = TRUE, 
                 params = list(objective = "binary:logistic",
                               eta = 0.1,
                               max_depth = 6,
                               subsample = 0.8,
                               lambda = 0.1 ), 
                 nrounds = 10)
missuse
  • 19,056
  • 3
  • 25
  • 47