1
$\begingroup$

I have 3 classes and my weights are
Class 1: 1
Class 2: 0.333
Class 3: 0.167

How do I input them into the scale_pos_weight parameter?

I know for a binary classification, we input it like below:

model = XGBClassifier(scale_pos_weight=99)
$\endgroup$
3
  • 1
    $\begingroup$ You don't, as the scale_pos_weight arugment is meant for binary classification instead of multi-class classification. You can however use the weight argument to specify a column to use to weigh each observation, see also the answers to this question. $\endgroup$
    – Oxbowerce
    Oct 26, 2021 at 9:30
  • $\begingroup$ @Oxbowerce: Ok. But from the linked question. It is still not stated clearly how I should specify the inputs for the sample_weight. Should I input as a dictionary? sample_weight={1:1,2:0.333, 3:0.167}? $\endgroup$
    – Peter
    Oct 26, 2021 at 12:27
  • 1
    $\begingroup$ You can either use the xgboost.DMatrix with the weight argument, where each observation (not just each class) needs a weight, as seen in the first answer. The second option would be to use the weight argument directly in XGBClassifier, in this case you also have to have a weight for each observation as shown in the second answer. $\endgroup$
    – Oxbowerce
    Oct 26, 2021 at 12:46

0

Your Answer

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

Browse other questions tagged or ask your own question.