Decision Tree
Show how data is split using features.
Features
Training Table
About This Simulation
This decision tree simulator builds a classification tree from a data table. It calculates the impurity of every possible split, picks the best one, and repeats until the tree is complete, showing all the working.
Features
- Enter your own training table or use the example
- Numeric features split at midpoints between adjacent values
- Categorical features split into one branch per value
- Entropy, information gain and Gini calculations for each split
- The finished tree drawn node by node
Explanation
A decision tree classifies data by asking a series of questions about its features. Each internal node tests one feature, each branch is an outcome of the test, and each leaf gives a class. The tree is built by repeatedly choosing the split that makes the groups purest.
How it works
- Compute the impurity of the current set of examples, for example entropy H = −Σ pᵢ log₂ pᵢ.
- For each feature (and each threshold for numeric features), split the data and compute the weighted impurity of the resulting groups.
- Information gain = impurity before the split − weighted impurity after. Choose the split with the highest gain.
- Create a child node for each branch and repeat the process on its subset of data.
- Stop when a node is pure (all one class), no features remain, or another stopping rule is met; the leaf predicts the majority class.
Why it matters
Decision trees are easy to interpret and are the building block of random forests and gradient-boosted trees, some of the most widely used machine learning models. Calculating entropy and information gain by hand is a common question in CSE440, CSE420 and CSE427.
Frequently Asked Questions
How is entropy calculated in a decision tree?
Entropy H(S) = −Σ pᵢ log₂ pᵢ, where pᵢ is the proportion of examples in class i. It is 0 for a pure node and 1 for a 50/50 split between two classes.
What is information gain?
The reduction in entropy from a split: Gain = H(parent) − Σ (|child| / |parent|) × H(child). The feature with the highest information gain is chosen.
What is the difference between entropy and Gini impurity?
Both measure how mixed the classes in a node are. Gini = 1 − Σ pᵢ² and is slightly faster to compute; entropy uses logarithms. They usually choose similar splits.
How are numeric features split?
The values are sorted and candidate thresholds are placed at the midpoints between adjacent distinct values. Each threshold gives a 'feature ≤ t' versus 'feature > t' split, and the best one is chosen.
Topics covered
- Decision Trees
- Entropy
- Information Gain
- Gini Impurity
- ID3 Algorithm
- Classification
Tags
- id3
- gini
- machine learning
Related Simulations
Artificial Intelligence
Minimax Algorithm
Show game tree evaluation for two-player games.
Artificial Intelligence
Alpha-Beta Pruning Simulator
Show branches skipped during minimax optimization.
Compiler Design
SLR Parser Simulator
Enter a context-free grammar and build its LR(0) automaton, FIRST and FOLLOW sets and SLR parsing table, then parse an input string step by step.
Compiler Design
Shift Reduce Parsing/Bottom Up Parsing Simulator
Enter a grammar, check whether it is ambiguous, then parse a string with shift and reduce actions step by step while the parse tree grows from the bottom up.

