Playground / Decision Tree (ID3)

Grow a decision tree by information gain

Decision Tree (ID3)

Interactive lab

Try it: Decision Tree (ID3)

How ID3 grows a decision tree greedily: label the node by majority vote, compute the gain of every remaining attribute, split on the best one, and recurse until the node is pure or no attributes are left — then classify a new row by walking the tree.

How it works

  1. Start with one root leaf holding every row and give it the majority label.
  2. If all rows agree, or no attributes are left, the node stays a leaf.
  3. Otherwise compute Gain(S, i) = C(S) - sum over values v of |S_v|/|S| · C(S_v) for each remaining attribute (C = entropy, training error or Gini).
  4. Split on the attribute with the largest gain and repeat on every child with that attribute removed.
  5. Classify a query by following its attribute values from the root to a leaf.

Default run (15 steps): ID3 starts with one root leaf holding all 14 rows (9 Yes / 5 No); its majority label is Yes. Impurity measure: entropy. … The query reaches the leaf Humidity = Normal: prediction Play = Yes.

Simplified: A fixed 4-attribute categorical table (at most 14 rows) with a Yes/No label. A value with no rows becomes a leaf with the parent's majority label, and a tied majority keeps the parent's label; real trees also prune.

Educational simulation

Loading the simulation…