2
$\begingroup$

I'm using xgboost multi-class classifier to predict a collection of things likely to fail. I want to run that prediction, and report anything that the classifier identifies with probability > 75%. However if I use xgb.predict_proba(), the sum of the results in the array add up to 1. So, if there are a lot of things likely to fail, they will all have tiny percentages in the result array.

Looking at the predict_proba code, I can see where the array is getting normalized. However I can't figure out how to prevent this.

In the end, I think my code would look something like this (except with the pre-normalized probabilities):

probas = xgb.predict_proba(single_element_dataframe)

for class_name in xgb.classes_:
    class_index = np.where(xgb.classes_ == class_name)
    proba = probas[0][class_index]
    if proba > 0:
        print(f"{class_name}: {proba}")

Any ideas?

$\endgroup$
1
  • 2
    $\begingroup$ If you are trying to using the classifier to classify multiple things that can fail at the same time it's probably better to use a separate model for each of the classes since the model assumes that only one class can be true at a time. Because of this the values are normalized to get the percentage for each class. $\endgroup$
    – Oxbowerce
    Jul 20, 2021 at 8:31

1 Answer 1

3
$\begingroup$

Currently you're doing multiclass classification: find the most likely among N classes. Each class $C$ probability indicates how likely class $C$ is for the instance as opposed to any other class. This is why the probabilities sum to 1: in this setting, there is only one "correct" class, so two classes cannot both have high probability.

Based on your description you should use multi-label classification: find all the classes that apply to the instances among N classes. In this case each class $C$ probability indicates how likely this instance has class $C$ as opposed to not having class $C$ (i.e. independently from any other class). Naturally the consequence is that the probabilities don't sum to one, since they are independent of each other.

Note: multi-label classification is exactly the same as training a binary model for every class independently.

$\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.