I am working on a multi-class classification task for 24 classes using XGBoost. I am training the model as follows:

param = {'max_depth': max_depth, 'eta': learning_rate, 'silent': 1, 'objective': 'multi:softmax', 'num_class': 24}
bst = xgb.train(param, dtrain, num_round)
bst = xgb.Booster({'nthread': 4})
predictions = bst.predict(dval)

I am getting the predictions as this array:

[ 0.5  0.5  0.5 ...,  0.5  0.5  0.5]

I don't know why it's predicting all classes as 0.5 instead of one of the indices in 0 to 23. Do I need to use any other objective parameter?

  • 2
    $\begingroup$ What is the line bst = xgb.Booster({'nthread': 4}) for? $\endgroup$ – tagoma Nov 26 '17 at 21:16

I do not know python API, but I guess with the following line you overwrite the trained object with a freshly created booster object (0.5 is a default prediction)

bst = xgb.Booster({'nthread': 4})
| improve this answer | |
  • $\begingroup$ Worked! I thought this would train using 4 threads. $\endgroup$ – Hellboy Nov 27 '17 at 14:34

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.