How does a decision tree solve the XOR problem where a linear classifier fails?
Quick Overview
Explain how a decision tree classifies XOR data that no linear classifier can separate. Tests why a single line fails, how nested splits capture a feature interaction, and what a greedy impurity criterion sees at the root split.
How does a decision tree solve the XOR problem where a linear classifier fails?
Role: Machine Learning Engineer
Category: Machine Learning
Difficulty: easy
Interview Round: Other
How does a decision tree solve the XOR problem where a linear classifier fails?
Take the four points (0,0), (0,1), (1,0), (1,1) with labels 0, 1, 1, 0.
```hint Look at one region at a time
After one axis-aligned split, what does the remaining problem look like inside each half?
```
```hint Check the first split's gain
Compute the Gini impurity of the children for a root split on either feature. What does a greedy learner see?
```
### What a Strong Answer Covers
- Why no single linear boundary separates the XOR classes.
- The depth-2 tree, and how its nested splits encode the interaction between the two features.
- What a greedy impurity criterion sees at the root, and why common libraries still build the tree.
- Settings or data conditions under which the tree can fail to find the clean solution.
- How a linear model could be made to solve XOR.
### Follow-up Questions
- Can gradient boosting with depth-1 stumps learn XOR? Why or why not?
- Suppose the label is the parity of 5 binary features hidden among 50 noise features. How would a greedy tree behave?
- What is the smallest neural network that solves XOR, and how does it compare with the tree?
Overview: Explain how a decision tree classifies XOR data that no linear classifier can separate. Tests why a single line fails, how nested splits capture a feature interaction, and what a greedy impurity criterion sees at the root split.