How to get predict_proba() by a model trained with xgb.train()

import xgboost as xgb
train = xgb.DMatrix(X_train, y_train)
test  = xgb.DMatrix(X_test, y_test)
bst = xgb.train(params, train, max_rounds, evals=[(test, 'validation_0')], verbose_eval=True)

I am using xgboost for two-class (0, 1) classification.
I can get predicted labels by bst.predict(), where bst is the name of my model.
However, I need probability of each class, which is usually given by predict_proba() for other classification algorithms.
But I cannot find bst.predict_proba(), as shown in the scheenshot below.

Could you please advise me?
Thank you so much…

The predict() function should give you the probability for class 1. Did you set objective = ‘binary:logistic’?

1 Like

Thank you so much!
I set the following parameters only; others are default.

Now, along with the above parameters, if I set objective = ‘binary:logistic’ , then the predict() function should give me the probability of class 1. Do you mean like this?

Yes, you should set objective in params.

1 Like

Got it; thanks a lot
Now I changed it as below.

Then, how may I get the predicted labels? is it like applying a threshold of 0.5 (above means 1, below means 0)?

Yes, you can apply the 0.5 threshold to obtain class labels.