Question on xgb.Dmatrix in xgboost?

Hi. I am trying to understand xgboost, and in particular the label parameter. It seems to me label should be the target variable, but I am misunderstanding something. Below includes a few rows of my data. What should label equal in xgb.DMatrix? Also, do I need to declare variables as factors? Thank you.


df <- data.frame(
age = c(28,31,48,35,30,23),
sex = c(1,0,0,1,0,0),
education = c(2,3,2,1,1,1),
marriage = c(0,0,0,0,1,1),
assets = c(3,4,3,2,2,3),
missed_payment = c(1,1,2,2,1,2),
credit_utilize = c(.191,.196,1,1,.374,.970),
default = c(0,0,1,1,1,1))
df <- as.matrix(df)

dtrain <- xgb.DMatrix(data = df, label = df$default)
bst <- xgboost(data = dtrain, max_depth = 2, eta = 1, nthread = 2, nrounds = 2, objective = "binary:logistic", verbose = 2)
pred <- predict(bst, df)

Error in df$default : $ operator is invalid for atomic vectors
Calls: xgb.DMatrix -> append
Execution halted

I found an answer to the label part of the question.

output_vector = trainData$default
dtrain <- xgb.DMatrix(data = trainData, label = output_vector)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.