1 Machine Learning Lecture 8: Ensemble Methods Moshe Koppel Slides adapted from Raymond J. Mooney and others
2 General Idea
3 Value of Ensembles When combing multiple independent and diverse decisions each of which is at least more accurate than random guessing, random errors cancel each other out, correct decisions are reinforced. Human ensembles are demonstrably better –How many jelly beans in the jar?: Individual estimates vs. group average. –Who Wants to be a Millionaire: Expert friend vs. audience vote.
4 Why does it work? Suppose there are 25 base classifiers –Each classifier has error rate, = 0.35 –Assume classifiers are independent –Probability that the ensemble classifier makes a wrong prediction: This value approaches 0 as the number of classifiers increases. This is just the law of higher numbers but in this context is sometimes called “Condorcet’s Jury Theorem”.
5 Generating Multiple Models Use a single, arbitrary learning algorithm but manipulate training data to make it learn multiple models. –Data1 Data2 … Data m –Learner1 = Learner2 = … = Learner m Different methods for changing training data: –Bagging: Resample training data –Boosting: Reweight training data –D ECORATE: Add additional artificial training data In W EKA, these are called meta-learners: they take a learning algorithm as an argument (base learner) Other approaches to generating multiple models: –vary some random parameter in learner, e.g., order of examples –vary choice of feature set: Random Forests
6 Bagging Create ensembles by repeatedly randomly resampling the training data (Brieman, 1996). Given a training set of size n, create m samples of size n by drawing n examples from the original data, with replacement. –Each bootstrap sample will on average contain 63.2% of the unique training examples, the rest are replicates. Combine the m resulting models using simple majority vote. Decreases error by decreasing the variance in the results due to unstable learners, algorithms (like decision trees) whose output can change dramatically when the training data is slightly changed.
7 Bagging Base learner = Single level binary tree (“stump”) True rule x.75 No stump perfect
8 Bagging Accuracy of ensemble classifier: 100%
9 Bagging- Final Points Works well if the base classifiers are unstable (i.e., pointless to try this with nearest neighbor) Increased accuracy because it reduces variance as compared to any individual classifier Multiple models can be learned in parallel
10 Boosting Originally developed by computational learning theorists to guarantee performance improvements on fitting training data for a weak learner that only needs to generate a hypothesis with a training accuracy greater than 0.5 (Schapire, 1990). Revised to be a practical algorithm, AdaBoost, for building ensembles that empirically improves generalization performance (Freund & Shapire, 1996). Examples are given weights. At each iteration, a new hypothesis is learned and the examples are reweighted to focus the system on examples that the most recently learned classifier got wrong.
11 Boosting: Basic Algorithm General Loop: Set all examples to have equal uniform weights. For t from 1 to T do: Learn a hypothesis, h t, from the weighted examples Decrease the weights of examples h t classifies correctly Base (weak) learner must focus on correctly classifying the most highly weighted examples while strongly avoiding over-fitting. During testing, each of the T hypotheses get a weighted vote proportional to their accuracy on the training data.
12 AdaBoost Pseudocode TrainAdaBoost(D, BaseLearn) For each example d i in D let its weight w i =1/|D| For t from 1 to T do: Learn a hypothesis, h t, from the weighted examples: h t =BaseLearn(D) Calculate the error, ε t, of the hypothesis h t as the total sum weight of the examples that it classifies incorrectly. If ε t > 0.5 then exit loop, else continue. Let β t = ε t / (1 – ε t ) Multiply the weights of the examples that h t classifies correctly by β t Rescale the weights of all of the examples so the total sum weight remains 1. Return H={h 1,…,h T } TestAdaBoost(ex, H) Let each hypothesis h t in H vote for ex’s classification with weight log(1/ β t ) Return the class with the highest weighted vote total.
13 AdaBoost Pseudocode TrainAdaBoost(D, BaseLearn) For each example d i in D let its weight w i =1/|D| For t from 1 to T do: Learn a hypothesis, h t, from the weighted examples: h t =BaseLearn(D) Calculate the error, ε t, of the hypothesis h t as the total sum weight of the examples that it classifies incorrectly. If ε t > 0.5 then exit loop, else continue. Let β t = ε t / (1 – ε t ) Multiply the weights of the examples that h t classifies correctly by β t Rescale the weights of all of the examples so the total sum weight remains 1. Return H={h 1,…,h T } TestAdaBoost(ex, H) Let each hypothesis h t in H vote for ex’s classification with weight log(1/ β t ) Return the class with the highest weighted vote total. Before reweighting the total weight of these is 1 – ε t, so now the total weight is ε t
14 AdaBoost Pseudocode TrainAdaBoost(D, BaseLearn) For each example d i in D let its weight w i =1/|D| For t from 1 to T do: Learn a hypothesis, h t, from the weighted examples: h t =BaseLearn(D) Calculate the error, ε t, of the hypothesis h t as the total sum weight of the examples that it classifies incorrectly. If ε t > 0.5 then exit loop, else continue. Let β t = ε t / (1 – ε t ) Multiply the weights of the examples that h t classifies correctly by β t Rescale the weights of all of the examples so the total sum weight remains 1. Return H={h 1,…,h T } TestAdaBoost(ex, H) Let each hypothesis h t in H vote for ex’s classification with weight log(1/ β t ) Return the class with the highest weighted vote total.
15 AdaBoost Pseudocode TrainAdaBoost(D, BaseLearn) For each example d i in D let its weight w i =1/|D| For t from 1 to T do: Learn a hypothesis, h t, from the weighted examples: h t =BaseLearn(D) Calculate the error, ε t, of the hypothesis h t as the total sum weight of the examples that it classifies incorrectly. If ε t > 0.5 then exit loop, else continue. Let β t = ε t / (1 – ε t ) Multiply the weights of the examples that h t classifies correctly by β t Rescale the weights of all of the examples so the total sum weight remains 1. Return H={h 1,…,h T } TestAdaBoost(ex, H) Let each hypothesis h t in H vote for ex’s classification with weight log(1/ β t ) Return the class with the highest weighted vote total. As ε t ½, weight 0; as ε t 0, weight
16 Learning with Weighted Examples Generic approach is to replicate examples in the training set proportional to their weights (e.g. 10 replicates of an example with a weight of 0.01 and 100 for one with weight 0.1). Most algorithms can be enhanced to efficiently incorporate weights directly in the learning algorithm so that the effect is the same (e.g. implement the WeightedInstancesHandler interface in W EKA ). For decision trees, for calculating information gain, when counting example i, simply increment the corresponding count by w i rather than by 1.
17 Toy Example
18 Final Classifier
19 Training Error
20 Experimental Results on Ensembles (Freund & Schapire, 1996; Quinlan, 1996) Ensembles have been used to improve generalization accuracy on a wide variety of problems. On average, Boosting provides a larger increase in accuracy than Bagging. Boosting on rare occasions can degrade accuracy. Bagging more consistently provides a modest improvement. Boosting is particularly subject to over-fitting when there is significant noise in the training data.
21 D ECORATE (Melville & Mooney, 2003) What if the training set is small, and therefore resampling and reweighting the training set has limited ability to generate diverse alternative hypotheses? Can generate multiple models by using all training data and adding fake training examples with made-up labels in order to force variation in learned models. Miraculously, this works.
22 Base Learner Overview of D ECORATE Training Examples Artificial Examples Current Ensemble C
23 C1 Base Learner Overview of D ECORATE Training Examples Artificial Examples Current Ensemble C
24 C1 C2Base Learner Overview of D ECORATE Training Examples Artificial Examples Current Ensemble C3
25 Another Approach: Random Forests Random forests (RF) are a combination of tree predictors Generate multiple trees by repeatedly choosing some random subset of all features Optionally also use random subset of examples as in bagging
26 Random Forests Algorithm Given a training set S For i = 1 to k do: Build subset S i by sampling with replacement from S Learn tree T i from S i At each node: Choose best split from random subset of F features Make predictions according to majority vote of the set of k trees.
27 Random Forests Like bagging, multiple models can be learned in parallel No need to get fancy; don’t bother pruning Designed for using decision trees as base learner, but can be generalized to other learning methods
28 Issues in Ensembles Can generate multiple classifiers by –Resampling training data –Reweighting training data –Varying learning parameters –Varying feature set Boosting can’t be run in parallel and is very sensitive to noise, but (in the absence of noise) seems very insensitive to overfitting Ability of ensemble methods to reduce variance depends on independence of learned classifiers