EasyDeepLearn

How do class weights work in logistic regression, and when do you use them?

medium

Answer

  • Class weights re-weight the log-loss contributions of each class so the minority class carries more penalty when misclassified.
  • 'balanced' in scikit-learn sets weightc  =  nsamples  /  (nclasses    nc)\mathrm{weight}_{c}\; = \;n_{\mathrm{samples}}\; / \;(n_{\mathrm{classes}}\; \cdot \;n_{c}).
  • Effect: pushes the decision boundary toward the majority class and improves recall on the minority class, at the cost of precision.
  • Use when the positive class is rare and false negatives are more costly than false positives.
Check yourself — multiple choice
  • Class weights re-scale the features
  • They re-weight per-class contributions to the loss, boosting minority-class recall
  • They replace threshold tuning
  • They only apply to trees

classweight\mathrm{class}_{\mathrm{weight}} rescales the loss per class ⇒ better minority-class recall (usually) at some precision cost.

#logistic-regression#imbalance

Practise Supervised Learning

215 interview questions in this topic.

Related questions