EasyDeepLearn

How do you handle class imbalance in XGBoost / LightGBM?

medium

Answer

  • Set scaleposweight  =  negatives  /  positives\mathrm{scale}_{\mathrm{pos}}\mathrm{weight}\; = \;\mathrm{negatives}\; / \;\mathrm{positives} (for binary) so gradients from the minority class are up-weighted.
  • Alternatively use isunbalance=true\mathrm{is}_{\mathrm{unbalance}} = \mathrm{true} in LightGBM.
  • This adjusts the loss weighting without changing the data.
  • Combine with a probability-based threshold tuned on validation for the actual decision.
  • If you also need calibrated probabilities, apply post-hoc calibration since scaleposweight\mathrm{scale}_{\mathrm{pos}}\mathrm{weight} distorts them.
Check yourself — multiple choice
  • Duplicate the minority class rows
  • Set scaleposweight\mathrm{scale}_{\mathrm{pos}}\mathrm{weight} (or  isunbalance)(\mathrm{or}\;\mathrm{is}_{\mathrm{unbalance}}) and tune the decision threshold on validation
  • Change the tree-splitting algorithm
  • Drop the majority class

scaleposweight\mathrm{scale}_{\mathrm{pos}}\mathrm{weight} rescales gradients — tune the decision threshold on validation.

#xgboost#lightgbm#imbalance

Practise Supervised Learning

215 interview questions in this topic.

Related questions