1
$\begingroup$

i have a multiclass classification problem with 3 classes [-1,0,1] . i'd like to use eval_set in xgboost. but it fails with error:

rank_metric.cc:88: Check failed: preds.size() == info.labels_.size() (270 
vs. 90) label size predict size not match'

when i run

modelfit=model.fit(Xtrain,ytrain) 

it runs fine

modelfit=model.fit(Xtrain,ytrain,eval_set = [(Xtest, ytest)]) 

generates above error

i tried all eval_metric available for multiclass and they all generate same error.

model is following:

xgb.XGBClassifier(n_jobs = -1,objective = 'multi:softmax',
            num_class=3, eval_metric = 'mlogloss',           
tree_method='approx', scale_pos_weight=1,
        **{'subsample':0.5,'colsample_bylevel':1, 'colsample_bytree': 
 1, 'gamma':0, 'learning_rate':0.3,'max_delta_step': 0, 'max_depth': 10, 
'min_child_weight': 1, 'n_estimators': 10, 'reg_alpha': 0, 'reg_lambda': 
0})

ipdb> modelfit.predict(Xtest)
  array([-1., -1., -1., -1., -1., -1., -1.,  1., -1., -1., -1.,  1.,  1.,
 1., -1.,  1.,  0., -1.,  1.,  1.,  1., -1., -1.,  1.,  1.,  1.,
 1.,  1.,  1.,  0.,  0., -1., -1., -1., -1., -1., -1., -1., -1.,
-1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.,
-1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1., -1.,
-1., -1., -1., -1., -1., -1., -1.,  1., -1., -1., -1., -1., -1.,
 0.,  1.,  1.,  1.,  1.,  1.,  1., -1., -1., -1., -1., -1.])
 ipdb> len(modelfit.predict(Xtest))
90
ipdb> len(ytest)
90
ipdb> ytest
array([-1., -1., -1., -1., -1., -1., -1.,  0., -1.,  1.,  0.,  1.,  0.,
 1.,  0.,  1.,  0.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,
 1.,  1., -1., -1., -1., -1., -1., -1., -1., -1.,  0.,  0.,  1.,
 1.,  0.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  0.,  0.,  1.,  0.,
 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0., -1.,
-1., -1., -1.,  0.,  0.,  0.,  1.,  1.,  1.,  1.,  0.,  0.,  0.,
 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])

as can be seen from debugger output , len of predict(Xtest) and ytest are both 90. why xgboost generates the error?

$\endgroup$

1 Answer 1

1
$\begingroup$

This looks like a bug in the 0.80 version.

It works when upgraded to xgboost 0.82.

$\endgroup$

Your Answer

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

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