Chapter 4
Classification & Decision Trees
Classification as a two-step process, supervised vs unsupervised algorithms, decision tree structure and induction (Hunt's algorithm, ID3), splitting, information gain and rule extraction.
From: Topic 4a - Introduction to Decision Tree, Topic 4c - Decision Tree: Info Gain, Topic 4 - Decision Tree: Classification part 2
Classification concepts (4a, 4 part 2)
- A two-step process: a learning step builds the model (classifier), then a classification step uses it to predict class labels.
- Model construction: each tuple belongs to a predefined class (the class label attribute); the training set builds the model as rules, a decision tree or a formula.
- Model usage: estimate accuracy on a test set (independent of the training set, otherwise overfitting), then classify new data whose labels are unknown.
- Accuracy = correctly classified test samples / total test samples.
- Example tasks: tumour cells benign or malignant; card transactions legitimate or fraudulent; protein structures; news categories.
- Methods in the course: decision tree induction, Bayes classification, neural networks, k-NN, rule-based classification.
| Supervised | Unsupervised | |
|---|---|---|
| Labels | Training data comes with class labels | Class labels are unknown |
| Task | Classification: new data classified from the training set | Clustering: establish whether classes or clusters exist |
| Continuous target | Regression (linear, polynomial), decision trees, random forest | Clustering: k-means, DIANA |
| Categorical target | Classification: decision trees, k-NN, logistic regression, Naïve Bayes, SVM | Association: Apriori, FP-Growth; hidden Markov model |
Decision trees (4c)
- J. Ross Quinlan developed ID3 (Iterative Dichotomiser) in the late 70s / early 80s, later expanded to C4.5 and CART.
- A flowchart-like tree: each internal node tests an attribute, each branch is an outcome of the test, and each leaf holds a class label. The topmost node is the root.
- More than one tree can fit the same data (e.g. splitting on Refund first or Marital Status first).
Basic induction algorithm (greedy)
- Build the tree top-down, recursively, divide-and-conquer. Start with all training examples at the root.
- Attributes are categorical (continuous ones are discretized in advance).
- Partition the examples recursively on attributes chosen by a heuristic or statistical measure (e.g. information gain).
- Stop when all samples at a node belong to the same class, no attributes are left (use majority voting for the leaf), or no samples are left.
- Hunt's algorithm (Hunt et al., 1966) is the basis of ID3, C4.5 and CART. If the records at node t (Dt) all share class yt, t is a leaf labelled yt; if Dt is empty, t is a leaf with the default class; otherwise split with an attribute test and recurse.
- Design issues: how to specify the test condition, how to find the best split, and when to stop splitting.
| Attribute type | Splitting |
|---|---|
| Nominal | Multi-way (one partition per value) or binary (two subsets, e.g. {Family, Luxury} vs {Sports}) |
| Ordinal | Multi-way or binary, but binary groups must keep the order: {Small, Medium} vs {Large} is fine, {Small, Large} vs {Medium} is not |
| Continuous | Discretize to an ordinal attribute (static once, or dynamic by equal-interval/equal-frequency bucketing or clustering), or a binary decision A < v vs A ≥ v (more compute-intensive) |
Choosing the best split: information gain (4c)
- A node is pure (homogeneous) if it holds only one class; otherwise impure (heterogeneous).
- Compare the parent's impurity before splitting with the children's weighted impurity after. The larger the difference (gain), the better the split.
- ID3/C4.5 pick the attribute with the highest information gain.
Info(D) = −Σ pᵢ log₂(pᵢ)
Entropy: expected information to classify a tuple in D
Info_A(D) = Σ |Dⱼ|/|D| × Info(Dⱼ)
Information still needed after splitting on A into v partitions
Gain(A) = Info(D) − Info_A(D)
buys_computer example (4c, slides 15–18)
- 14 tuples: 9 yes, 5 no. Info(D) ≈ 0.940.
- age = youth has 5 samples (2 yes, 3 no); Info_age(D) ≈ 0.694, so Gain(age) ≈ 0.246.
- Gain(income) ≈ 0.029, Gain(student) ≈ 0.151, Gain(credit_rating) ≈ 0.048.
- age has the highest gain, so it becomes the root. ID3 in Weka gives: youth → student? (no → no, yes → yes); middle → yes; senior → credit_rating? (fair → yes, excellent → no).
| Measure | Bias |
|---|---|
| Information gain | Biased towards multivalued attributes |
| Gain ratio | Prefers unbalanced splits where one partition is much smaller |
| Gini index | Biased to multivalued attributes; struggles when the number of classes is large; favours equal-sized, pure partitions |
Rule extraction (4c, slide 19)
- One rule per path from the root to a leaf.
- Each attribute-value pair along the path forms a conjunction (AND); the leaf holds the class prediction.
- Rules are mutually exclusive and exhaustive, and easier to understand than a large tree.
- From the tree above: IF age = youth AND student = no THEN buys_computer = no; IF age = middle THEN yes; IF age = senior AND credit_rating = excellent THEN no.
Applying the model (4 part 2, slide 11): start at the root and follow the branches matching the test record, e.g. Refund = No, Marital Status = Married → assign Cheat = “No”.