Forward that I'm fairly new to both xgboost and R.
I am using xgboost in R to perform a multinomial classification on my data dtrain
. The label I am using has six levels, so my code looks like this:
param1 <- list(objective = "multi:softprob"
, num_class = 6
, booster = "gbtree"
, eta = 0.5
, max.depth = 7
, min_child_weight = 10
, max_delta_step = 5
, subsample = 0.8
, colsample_bytree = 0.8
, lambda = 3 # L2
, alpha = 5 # L1
)
set.seed(2016)
xgbcv1 <- xgb.cv(params = param1, data = dtrain, nround = 3000, nfold = 3,
metrics = list("error", "auc"), maximize = T,
print_every_n = 10, early_stopping_rounds = 10)
This throws me the following error:
Error in xgb.iter.update(fd$bst, fd$dtrain, iteration - 1, obj) :
amalgamation/../src/objective/multiclass_obj.cc:75: Check failed:
label_error >= 0 && label_error < nclass SoftmaxMultiClassObj: label must be in [0, num_class), num_class=6 but found 6 in label.
So I tried setting num_class = 7
, which throws this error:
Error in xgb.iter.eval(fd$bst, fd$watchlist, iteration - 1, feval) :
amalgamation/../src/metric/elementwise_metric.cc:28: Check failed:
(preds.size()) == (info.labels.size()) label and prediction size not match, hint: use merror or mlogloss for multi-class classification
What's going on here? Does num_class
need to be greater than label_error
or equal to it?