How does the class_weight='balanced' option work in logistic regression, and what problem does it solve?

Quick Overview

Asks how the balanced class weight setting changes logistic regression training on imbalanced data and why you would use it. Tests the weight formula, its effect on the decision threshold, recall and precision, and what it does to the meaning of predicted probabilities.

How does the class_weight='balanced' option work in logistic regression, and what problem does it solve?

Role: Data Scientist

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How does the `class_weight='balanced'` option work in logistic regression, and what problem does it solve? ```hint Count the total weight per class Work out the weight scikit-learn assigns to each class with 950 negatives and 50 positives, then multiply each weight by its class count. What do you notice? ``` ```hint Think about the intercept If reweighting mostly moves the intercept, what happens to the predicted probabilities, and what happens to the ranking of examples? ``` ### What a Strong Answer Covers - Why unweighted log-loss favors the majority class on imbalanced data - The weight formula and what it equalizes across classes - How the weighted loss changes the fitted model and the precision and recall at a fixed threshold - The effect on predicted probabilities and how to correct or recalibrate them - Alternatives such as threshold tuning, resampling or custom cost weights ### Follow-up Questions - Would you expect ROC AUC to change much after switching to balanced weights? Why? - How would you convert a balanced model's predicted probability back to the real base rate? - When would you pass a custom weight dictionary instead of `'balanced'`?

Overview: Asks how the balanced class weight setting changes logistic regression training on imbalanced data and why you would use it. Tests the weight formula, its effect on the decision threshold, recall and precision, and what it does to the meaning of predicted probabilities.

Nov 25, 2026
mediumData ScientistOtherMachine Learning
0
0

How does the class_weight='balanced' option work in logistic regression, and what problem does it solve?

What a Strong Answer Covers Guidance

  • Why unweighted log-loss favors the majority class on imbalanced data
  • The weight formula and what it equalizes across classes
  • How the weighted loss changes the fitted model and the precision and recall at a fixed threshold
  • The effect on predicted probabilities and how to correct or recalibrate them
  • Alternatives such as threshold tuning, resampling or custom cost weights

Follow-up Questions Guidance

  • Would you expect ROC AUC to change much after switching to balanced weights? Why?
  • How would you convert a balanced model's predicted probability back to the real base rate?
  • When would you pass a custom weight dictionary instead of 'balanced' ?