1
$\begingroup$

I have two classes : 1 and 2

The output of model.predict_proba() -> [0.333,0.6667]

The output of model.predict() -> 1

This is happening for around 200 test values out of the test data of 10 lac. For all other records, both the functions' output don't conflict. Even if the probability of class 2 is higher, predict function gives final class as 1.

What could be the reason for the output of model.predict() and model.predict_proba() not syncing with each other for those 200 records?

$\endgroup$
  • $\begingroup$ I think xgboost requires that binary targets (or label in the DMatrix) are 0 or 1 - have you done this? $\endgroup$ – bradS Jul 25 at 11:48
  • $\begingroup$ @bradS This doesn't make a difference here. However, when i run the model explicitly on one of the records in those 200 records, it gives correct results i.e the class with higher probability value is given by model.predict() . This model is called at production where a lot of requests are passed to it one after the other and in only a few cases (200 out of 10 lakh) this happens. $\endgroup$ – Manasvi Duggal Jul 25 at 12:11
  • $\begingroup$ Ok. Have you tried to look at those particular 200 observations to see if they have anything in common? E.g. all have a similar value for one feature, have outliers in some features. Also, I'm not sure what you mean by "10 lakh"... is that a number? $\endgroup$ – bradS Jul 25 at 16:33
  • $\begingroup$ @bradS Yes, the code was run on 10,00,000 records. I couldn't find anything in common for those 200 observations. Is it because too many requests are being sent to predict() that for few 200 observations, it is giving abnormal results or something? $\endgroup$ – Manasvi Duggal Jul 26 at 7:55
0
$\begingroup$

If you have two classes i.e you're doing binary classification, you should specify the target labels as 0 or 1 (neg/pos). The predict_proba() method returns estimated probabilities that a sample is in class 1.

"In the binary classification case, '1' is used to indicate positive samples, and '0' is used to indicate negative samples. We also support probability values in [0,1] as label, to indicate the probability of the instance being positive." - https://github.com/dmlc/xgboost/tree/master/demo/binary_classification

$\endgroup$

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.