1

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)
Peter
  • 179
  • 2
  • 9
  • 1
    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. – Oxbowerce Oct 26 '21 at 09:30
  • @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}? – Peter Oct 26 '21 at 12:27
  • 1
    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. – Oxbowerce Oct 26 '21 at 12:46

0 Answers0