6
$\begingroup$

The xgboost classifier states the use of parameter scale_pos_weight for 2-class problems.

I have a highly imbalanced dataset with 3 classes. Classes '1' and '-1' are very rare (~1% of dataset) and class '0' is very common.

How do I set this scale_pos_weight parameter in the xgboost classifier correctly for my classification problem?

$\endgroup$
1
  • $\begingroup$ Are you sure that the best way for handling the imbalanced dataset in your case is setting scale_pos_weight parameter? $\endgroup$ Commented Mar 14, 2019 at 8:31

2 Answers 2

1
$\begingroup$

For my multiclass classification problem with similar unbalanced data I used the output from sklearn compute_class_weight function:

https://scikit-learn.org/stable/modules/generated/sklearn.utils.class_weight.compute_class_weight.html

sklearn.utils.class_weight.compute_class_weight(class_weight, classes, y)
$\endgroup$
0
$\begingroup$

The parameter scale_pos_weight works for two classes (binary classification).

The parameter weight goes into the xgb.DMatrix function can be used for three or more classes. The weights can be computed like this:

weights = total_samples / (n_classes * class_samples * 1.0)
$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.