How do class weights work in logistic regression, and when do you use them?
mediumAnswer
- 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 .
- 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
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
- When should you use PR-AUC instead of ROC-AUC?
- How do you handle class imbalance in a dataset?
- Why is the base rate of the positive class critical to know?
- Why do we use cross-entropy (log loss) instead of MSE for classification?
- One-vs-Rest, One-vs-One, and softmax — how do you choose for multi-class?
- Write out the softmax function and its main property.