How do class weights change the impurity calculation at a node under class imbalance?

Quick Overview

Asks how class weights change Gini impurity or entropy at a decision tree node when one class is rare. It tests whether you can compute weighted class proportions, follow how weights shift split selection and leaf predictions, and see what weighting does to predicted probabilities.

How do class weights change the impurity calculation at a node under class imbalance?

Role: Machine Learning Engineer

Category: Machine Learning

Difficulty: medium

Interview Round: Other

How do class weights change the impurity calculation at a node under class imbalance? Assume a classification tree that picks splits by Gini impurity or entropy, trained on data where one class is much rarer than the other. ```hint Start from the proportions Gini and entropy are functions of the class proportions at the node. Ask what those proportions are computed from once each sample carries a weight. ``` ```hint Work a small node Take a node with 90 negatives and 10 positives, give the positives a larger weight, and compute Gini before and after. ``` ### What a Strong Answer Covers - How weighted class proportions are computed and plugged into Gini or entropy - How the weights enter the gain through the child node sizes, and what that does to split selection - How leaf predictions and minimum-leaf stopping rules behave once samples are weighted - What weighting does to predicted probabilities and how to correct for it ### Follow-up Questions - How does training with class weights compare with oversampling the minority class to the same ratio? - If you need calibrated probabilities from a weighted tree, how would you recover them? - How would you choose the weights if the "balanced" heuristic is not a good fit for the problem? - Why can `min_samples_leaf` and `min_weight_fraction_leaf` produce different trees on the same weighted data?

Overview: Asks how class weights change Gini impurity or entropy at a decision tree node when one class is rare. It tests whether you can compute weighted class proportions, follow how weights shift split selection and leaf predictions, and see what weighting does to predicted probabilities.

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

How do class weights change the impurity calculation at a node under class imbalance?

Assume a classification tree that picks splits by Gini impurity or entropy, trained on data where one class is much rarer than the other.

What a Strong Answer Covers Guidance

  • How weighted class proportions are computed and plugged into Gini or entropy
  • How the weights enter the gain through the child node sizes, and what that does to split selection
  • How leaf predictions and minimum-leaf stopping rules behave once samples are weighted
  • What weighting does to predicted probabilities and how to correct for it

Follow-up Questions Guidance

  • How does training with class weights compare with oversampling the minority class to the same ratio?
  • If you need calibrated probabilities from a weighted tree, how would you recover them?
  • How would you choose the weights if the "balanced" heuristic is not a good fit for the problem?
  • Why can min_samples_leaf and min_weight_fraction_leaf produce different trees on the same weighted data?