0
$\begingroup$

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', 
          'scale_pos_weight':9,
           'eval_metric': 'auc', 
           'nthread':25,
         'num_class':6}

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

!!!

$\endgroup$
  • 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$ – TwinPenguins Nov 6 '18 at 13:28
2
$\begingroup$

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.

| improve this answer | |
$\endgroup$
  • $\begingroup$ yes that was it, tkx $\endgroup$ – jeremy_rutman Nov 6 '18 at 14:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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