What is the difference between class_weight='balanced' and class_weight='balanced_subsample' in a Random Forest?

Quick Overview

Compare the balanced and balanced_subsample class weight options of a scikit-learn Random Forest. It tests how inverse-frequency class weights are computed, how bootstrap sampling changes the class balance seen by each tree, and when the choice matters for imbalanced classification.

What is the difference between class_weight='balanced' and class_weight='balanced_subsample' in a Random Forest?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: easy

Interview Round: Other

What is the difference between `class_weight='balanced'` and `class_weight='balanced_subsample'` in a Random Forest (scikit-learn's `RandomForestClassifier`)? ```hint Think about the bootstrap Each tree is trained on its own bootstrap sample. Ask which class counts each option uses to compute its weights, and how much those counts can vary from tree to tree. ``` ### What a Strong Answer Covers - The weighting formula the two options share and what the weights change inside each tree. - Which class counts each option uses, and what that means for the class balance of an individual tree. - The setting in which the two options behave identically. - When the difference matters in practice and how to choose between them. - How both differ from methods that resample the data, such as a Balanced Random Forest. ### Follow-up Questions - How do class weights change the probabilities returned by `predict_proba`, and what would you do if you need calibrated probabilities? - When would you prefer undersampling the majority class per tree over reweighting? - How do `class_weight` and an explicit `sample_weight` passed to `fit` combine?

Overview: Compare the balanced and balanced_subsample class weight options of a scikit-learn Random Forest. It tests how inverse-frequency class weights are computed, how bootstrap sampling changes the class balance seen by each tree, and when the choice matters for imbalanced classification.

General logo
General
Nov 25, 2026
easyMachine Learning EngineerOtherMachine Learning
0
0

What is the difference between class_weight='balanced' and class_weight='balanced_subsample' in a Random Forest (scikit-learn's RandomForestClassifier)?

What a Strong Answer Covers Guidance

  • The weighting formula the two options share and what the weights change inside each tree.
  • Which class counts each option uses, and what that means for the class balance of an individual tree.
  • The setting in which the two options behave identically.
  • When the difference matters in practice and how to choose between them.
  • How both differ from methods that resample the data, such as a Balanced Random Forest.

Follow-up Questions Guidance

  • How do class weights change the probabilities returned by predict_proba , and what would you do if you need calibrated probabilities?
  • When would you prefer undersampling the majority class per tree over reweighting?
  • How do class_weight and an explicit sample_weight passed to fit combine?