Decision Trees interview question

Machine LearningDecision Treesbasic

What does the Gini impurity of a decision-tree node measure?

  1. AThe chance a random sample from the node is mislabelled if labels are drawn from the node's class mix.
  2. BThe Gini coefficient of inequality applied to the node's feature values, showing how unevenly they spread.
  3. CThe share of the node's samples that belong to the majority class, so a higher value means a purer node.
  4. DThe expected number of bits needed to encode the class label of a sample drawn at random from the node.
Show the answer and explanation

Correct answer: A, The chance a random sample from the node is mislabelled if labels are drawn from the node's class mix.

Explanation Decision Trees

Gini impurity of a node with class proportions p₁ … p_K is

Gini = 1 − Σ p_k² = Σ p_k(1 − p_k)

It is the probability that a randomly drawn sample is misclassified when it is given a random label drawn from the node's own class distribution. It is 0 for a pure node and grows as the classes become more mixed.

Why the other descriptions are wrong:

  • The Gini coefficient of income inequality is a different quantity; tree impurity is computed from class labels, not feature values.
  • The majority-class share is a purity measure (1 minus the misclassification error); Gini impurity moves in the opposite direction, higher means less pure.
  • The expected number of bits to encode the label is entropy, the other common split criterion.

Interview tip: give the formula 1 − Σ p² and the two anchors: 0 for a pure node, 0.5 for a 50/50 binary node.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More Machine Learning questions

  1. Which statement correctly contrasts bagging and boosting?
  2. What is the "naive" assumption in Naive Bayes?
  3. Which description matches the standard k-means (Lloyd's) algorithm?
  4. What does precision measure for a binary classifier?
  5. How does k-fold cross-validation work?