I was trying an xgboost from python with a multiclass single-label problem and assumed the label can be an integer indicating my class (as opposed to eg one-hot) .

params = {'eta': 0.1,
#          'objective': 'binary:logistic', 
          'objective': 'multi:softmax', 
           'eval_metric': 'auc', 

dtrain = xgb.DMatrix(df_train_x,label= df_train_y)
dvalid = xgb.DMatrix(df_val_x,label= df_val_y)
watchlist = [(dtrain, 'train'), (dvalid, 'valid')]
model = xgb.train(params, dtrain, 500,watchlist, maximize=True, verbose_eval=50,early_stopping_rounds=20)

However I hit an error

(1353150 vs. 225525) label size predict size not match

and I note that my sample size is 225525 , number of classes is 6 , and 6*225525 is 1353150 so it appears that xgb is looking for one-hot ... however when i use one hot I get an error hinting that one-hot can't be used -

dtrain = xgb.DMatrix(df_train_x,label= df_train_y)
ValueError: DataFrame for label cannot have multiple columns


  • 2
    $\begingroup$ Maybe not related, but why you are using AUC for Multiclass evaluation? mlogloss or merror looks more suitable. Maybe because of this evaluation xgb is trying to make the problem to binary and multiply the num. of classes to your sample size. And yes you not need One-Hot-Encoding, that is for sure. $\endgroup$ Commented Nov 6, 2018 at 13:28

1 Answer 1


As Majid stated in the comment, using AUC is causing this error as normally ROC curves are calculated for binary classification. Try removing the eval_metric line and your code will run properly. That or removing the watchlist and early stopping options.

The eval metrics you need to use for multiclass are either merror or mlogloss which are the only ones specific for multiclass in the xgboost documentation.

  • $\begingroup$ yes that was it, tkx $\endgroup$ Commented Nov 6, 2018 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.