Decision tree classifier – sorting data with yes/no questions
Computer ScienceData, AI & Machine LearningAges 17–18
How do you mainly use this simulation?
Use it with your class: students open it from a link or a QR code, with no account needed.
Two-class data on a plane defined by two features (weather and going outside, apple or lemon, passing a test). The computer builds a decision tree by choosing, at each node, the question "feature ≤ threshold?" that reduces Gini impurity or entropy the most, or students click to cut regions themselves and preview the impurity drop. The plane is split into rectangles and the tree is drawn below; change the maximum depth to compare accuracy on training and test data and see overfitting clearly. In Your own rules, students write up to three if-then rules, refine their thresholds on a training batch, test each version on a fresh batch and record its accuracy.
Lesson: Machine learning: decision trees, Gini impurity and entropy, training and test data, overfitting
What it shows
A decision tree classifies an example by asking a chain of yes/no questions, each comparing one feature with a threshold, so the feature plane is split into rectangles. The data come from a hidden rule plus randomly flipped labels (noise). The computer greedily picks the cut that lowers Gini impurity or entropy the most; deeper trees fit the training data better but can memorise noise. In Your own rules you write the model yourself: if-then rules with limits, tuned on a training batch and tested on fresh batches the rules have never seen.
How to use
In Computer-built tree, move Maximum depth from 1 to 8 and compare training and test accuracy. In Your own questions, choose Vertical cut or Horizontal cut and click a region to split it. In Your own rules, set the limits and the class of each rule, watch the training accuracy, then press Test on a fresh batch and record to save each version with its accuracy.
Parameters you can change
- Data set Go outside? (temperature, humidity), Apple or lemon? (mass, redness of skin), Pass the test? (hours of revision, practice score)
- Number of data points 40–200 points
- Noise (share of flipped labels) 0–30 %
- Maximum tree depth 1–8
- Splitting criterion Gini impurity, Entropy (information gain)
- Show test data
- Screen Decision tree, Your own rules
Questions to explore
- Why does training accuracy keep rising with depth while test accuracy does not?
- Why does the "Pass the test?" data set, with its diagonal boundary, need so many questions?
- What does the first question chosen at the root tell you about the data?