Repaso
Español
ML fundamentalsIntermediateML-30

What does class_weight="balanced" do in scikit-learn classifiers such as LogisticRegression?

Options

  1. It duplicates rows of the minority class
  2. It removes rows of the majority class
  3. It weights each class inversely to its frequency, so mistakes on the rare class cost more (Correct option)
  4. It sets the decision threshold to match the class ratio

Answer

It weights each class inversely to its frequency, so mistakes on the rare class cost more

Why

The data stays the same. Each sample gets a weight of n_samples / (n_classes × n_samples_of_its_class), so errors on rare examples count more in the loss.

This often gives results close to oversampling without copying rows.

It changes the model's probabilities, so recalibrate them if you need real probabilities.

Remember

Class weights make rare-class errors cost more.

Key terms

Practice this question in Repaso