Lecture: Lecture 10 - Classification
The problem
Classification predicts a categorical outcome from examples whose correct classes are already known. Spam detection, disease diagnosis and predicting whether a student passes are classification problems. Regression predicts a number, while clustering groups records without predefined labels.
The training set teaches the model. The test set estimates how well the learned pattern works on unseen labelled records. A model that merely memorizes training rows may have high training accuracy and poor generalization.
Decision-tree mechanism
A decision tree represents a sequence of tests. Internal nodes contain attribute tests, branches contain outcomes and leaves contain class labels.
Example for predicting whether a student is likely to pass:
Attendance >= 75%?
├── No -> At risk
└── Yes
Midterm >= 50%?
├── Yes -> Likely pass
└── No -> Check assignment completionTo classify a new student, start at the root, apply the test, follow the matching branch and stop at the first leaf.
Hunt’s induction algorithm
For the records reaching node t:
- If all records have one class, make
ta leaf. - Otherwise choose the best attribute test.
- Split the records into child subsets.
- Apply the same procedure recursively to each child.
- If a child is empty, use the default majority class.
The strategy is greedy. It chooses the best local split, so it need not produce the globally optimal tree.
Choosing a split
A good split creates child nodes with homogeneous class distributions. For a node with 3 records of class A and 1 of class B:
Gini = 1 - (3/4)^2 - (1/4)^2 = 0.375
A pure node has Gini 0. A two-class node split evenly has Gini 0.5. For a parent split into children, compute the weighted sum:
Gini_split = sum((child size / parent size) * child Gini)
Choose the lower value. Entropy has the same interpretation of disorder, but information gain chooses the split that produces the greatest reduction in entropy. Gain ratio penalizes splits that create many small partitions.
Nominal attributes can use one branch per value or group values into two sets. Continuous attributes can use a threshold such as income < 80K. The threshold is selected by comparing candidate cuts.
Overfitting and pruning
An underfit tree is too simple and performs badly on both training and test data. An overfit tree follows noise and accidental details. For example, a tree might create a special branch for one unusual student and fail on the next class.
Pre-pruning stops growth early when a node has too few records or a split does not improve impurity. Post-pruning grows a large tree, then replaces subtrees with majority-class leaves when validation performance improves. Pruning usually reduces complexity and improves generalization.
Common confusion
The tree is interpretable because its prediction can be traced, but interpretability does not guarantee causation. If attendance is a useful predictor of passing, the tree does not prove that attendance alone causes the result. It may partly represent motivation, support or prior preparation.
Retrieval questions
Why is the training set insufficient for judging a tree? A tree can memorize training records. Unseen test records are needed to estimate generalization.
What does a low Gini value mean? The node contains a relatively homogeneous class distribution.
Why can pruning help? It removes branches that fit noise or small samples and keeps patterns that generalize better.