Error with XGBoost setup

3.3k views Asked by At

I'm pretty new to R and having some trouble with the XGBoost function. This is the code I have so far:

test_rows <- sample.int(nrow(ccdata), nrow(ccdata)/3)
test <- ccdata[test_rows,]
train <- ccdata[-test_rows,]
table(test$default.payment.next.month)
table(train$default.payment.next.month)

bstSparse <- xgboost(data = train, label = train$default.payment.next.month, max.depth = 2, eta = 1, nthread = 2, nround = 2, objective = "binary:logistic")

And I'm getting the following error:

Error in xgb.get.DMatrix(data, label, missing, weight) : 
xgboost only support numerical matrix input,
         use 'data.matrix' to transform the data.
In addition: Warning message:
In xgb.get.DMatrix(data, label, missing, weight) :
 xgboost: label will be ignored.

If anyone has any advice, it would be greatly appreciated.

Many thanks

1

There are 1 answers

0
cousin_pete On

The error msg is your clue. XGBoost only accepts data in numeric format and as a matrix. It appears you are feeding in dataframes? Try as.matrix(test) and as.matrix(train). You can always check the nature of any object with str(object) to see what it is.