Decision Trees Some exercises

Similar documents
A Decision Stump. Decision Trees, cont. Boosting. Machine Learning 10701/15781 Carlos Guestrin Carnegie Mellon University. October 1 st, 2007

Introduction to Machine Learning CMU-10701

Name (NetID): (1 Point)

10701/15781 Machine Learning, Spring 2007: Homework 2

Midterm, Fall 2003

The AdaBoost algorithm =1/n for i =1,...,n 1) At the m th iteration we find (any) classifier h(x; ˆθ m ) for which the weighted classification error m

Lecture 8. Instructor: Haipeng Luo

Decision Trees. Machine Learning 10701/15781 Carlos Guestrin Carnegie Mellon University. February 5 th, Carlos Guestrin 1

Decision Trees. CSC411/2515: Machine Learning and Data Mining, Winter 2018 Luke Zettlemoyer, Carlos Guestrin, and Andrew Moore

Decision Trees: Overfitting

Classification and Regression Trees

Decision Trees. Machine Learning CSEP546 Carlos Guestrin University of Washington. February 3, 2014

Machine Learning, Midterm Exam

Machine Learning, Fall 2009: Midterm

Universität Potsdam Institut für Informatik Lehrstuhl Maschinelles Lernen. Decision Trees. Tobias Scheffer

Voting (Ensemble Methods)

Machine Learning Ensemble Learning I Hamid R. Rabiee Jafar Muhammadi, Alireza Ghasemi Spring /

CS 6375 Machine Learning

Final Exam, Machine Learning, Spring 2009

Boosting: Foundations and Algorithms. Rob Schapire

Chapter 14 Combining Models

Decision Tree Learning Lecture 2

Data Mining. CS57300 Purdue University. Bruno Ribeiro. February 8, 2018

Generative v. Discriminative classifiers Intuition

CS6375: Machine Learning Gautam Kunapuli. Decision Trees

ECE 5424: Introduction to Machine Learning

Notes on Machine Learning for and

CSE 417T: Introduction to Machine Learning. Final Review. Henry Chai 12/4/18

Name (NetID): (1 Point)

Classification: Decision Trees

Empirical Risk Minimization, Model Selection, and Model Assessment

FINAL EXAM: FALL 2013 CS 6375 INSTRUCTOR: VIBHAV GOGATE

CS229 Supplemental Lecture notes

Frank C Porter and Ilya Narsky: Statistical Analysis Techniques in Particle Physics Chap. c /9/9 page 331 le-tex

Decision Trees (Cont.)

FINAL: CS 6375 (Machine Learning) Fall 2014

Machine Learning, Fall 2011: Homework 5

Data Mining und Maschinelles Lernen

Statistics and learning: Big Data

2 Upper-bound of Generalization Error of AdaBoost

Learning Theory Continued

Machine Learning, Midterm Exam: Spring 2008 SOLUTIONS. Q Topic Max. Score Score. 1 Short answer questions 20.

10-701/ Machine Learning - Midterm Exam, Fall 2010

Learning Theory. Machine Learning CSE546 Carlos Guestrin University of Washington. November 25, Carlos Guestrin

MIDTERM SOLUTIONS: FALL 2012 CS 6375 INSTRUCTOR: VIBHAV GOGATE

Introduction to Machine Learning Midterm Exam Solutions

Learning Decision Trees

CIS519: Applied Machine Learning Fall Homework 5. Due: December 10 th, 2018, 11:59 PM

ECE 5984: Introduction to Machine Learning

CHAPTER-17. Decision Tree Induction

Stochastic Gradient Descent

Boosting. Ryan Tibshirani Data Mining: / April Optional reading: ISL 8.2, ESL , 10.7, 10.13

Learning with multiple models. Boosting.

Machine Learning

Introduction to Machine Learning Midterm Exam

COMS 4771 Lecture Boosting 1 / 16

Analysis of the Performance of AdaBoost.M2 for the Simulated Digit-Recognition-Example

Machine Learning, Fall 2012 Homework 2

Machine Learning, Midterm Exam: Spring 2009 SOLUTION

Decision Trees. Tirgul 5

CSCI-567: Machine Learning (Spring 2019)

The Boosting Approach to. Machine Learning. Maria-Florina Balcan 10/31/2016

Decision Trees. CS57300 Data Mining Fall Instructor: Bruno Ribeiro

Lecture 7: DecisionTrees

The Perceptron algorithm

Classification Trees

Decision Tree Learning

Useful Equations for solving SVM questions

Introduction to Machine Learning (67577) Lecture 3

Open Problem: A (missing) boosting-type convergence result for ADABOOST.MH with factorized multi-class classifiers

TDT4173 Machine Learning

Machine Learning

Linear Classifiers and the Perceptron

Decision Tree Learning

Information Gain, Decision Trees and Boosting ML recitation 9 Feb 2006 by Jure

Information Theory, Statistics, and Decision Trees

Learning theory. Ensemble methods. Boosting. Boosting: history

C4.5 - pruning decision trees

Qualifier: CS 6375 Machine Learning Spring 2015

Ensembles. Léon Bottou COS 424 4/8/2010

the tree till a class assignment is reached

Dan Roth 461C, 3401 Walnut

CSE 151 Machine Learning. Instructor: Kamalika Chaudhuri

Final. Introduction to Artificial Intelligence. CS 188 Spring You have approximately 2 hours and 50 minutes.

Introduction to Machine Learning Lecture 11. Mehryar Mohri Courant Institute and Google Research

Introduction to ML. Two examples of Learners: Naïve Bayesian Classifiers Decision Trees

Midterm 2 V1. Introduction to Artificial Intelligence. CS 188 Spring 2015

i=1 = H t 1 (x) + α t h t (x)

COMS 4721: Machine Learning for Data Science Lecture 13, 3/2/2017

Evaluation requires to define performance measures to be optimized

Lecture 3: Decision Trees

Midterm Exam Solutions, Spring 2007

Linear Discrimination Functions

BBM406 - Introduc0on to ML. Spring Ensemble Methods. Aykut Erdem Dept. of Computer Engineering HaceDepe University

Boos$ng Can we make dumb learners smart?

Active Learning: Disagreement Coefficient

Jeffrey D. Ullman Stanford University

Linear & nonlinear classifiers

MIDTERM: CS 6375 INSTRUCTOR: VIBHAV GOGATE October,

DECISION TREE LEARNING. [read Chapter 3] [recommended exercises 3.1, 3.4]

Transcription:

Decision Trees Some exercises 0.

. Exemplifying how to compute information gains and how to work with decision stumps CMU, 03 fall, W. Cohen E. Xing, Sample questions, pr. 4

. Timmy wants to know how to do well for ML exam. He collects those old statistics and decides to use decision trees to get his model. He now gets 9 data points, and two features: whether stay up late before exam (S) and whether attending all the classes (A). We already know the statistics is as below: Set(all) = [5+,4 ] Set(S+) = [3+, ],Set(S ) = [+, ] Set(A+) = [5+, ],Set(A ) = [0+,3 ] Suppose we are going to use the feature to gain most information at first split, which feature should we choose? How much is the information gain? You may use the following approximations: N 3 5 7 log N.58.3.8

[5+,4 ] S + [5+,4 ] A + 3. [3+, ] [+, ] [5+, ] [0+,3 ] H= H=0 H(all) not. = H[5+,4 ] not. = H ( ) 5 sim. = H 9 ( ) 4 def. = 5 9 9 log 9 5 + 4 9 log 9 4 = log 9 5 9 log 5 4 9 log 4 = log 3 5 9 log 5 8 9 = 8 9 +log 3 5 9 log 5 = 0.99076 H(all S) def. = 5 9 H[3+, ]+ 4 9 H[+, ] =... IG(all, S) def. = H(all) H(all S) = 0.0075 = 5 9 0.97095+ 4 9 = 0.98386 IG(all, A) def. = H(all) H(all A) = 0.55778 H(all A) def. = 6 9 H[5+, ]+ 3 9 H[0+,3 ] =... IG(all,S) < IG(all,A) H(all S) > H(all A) = 6 9 0.6500+ 4 9 0 = 0.433348

4. Exemplifying the application of the ID3 algorithm on a toy mushrooms dataset CMU, 00(?) spring, Andrew Moore, midterm example questions, pr.

5. You are stranded on a deserted island. Mushrooms of various types grow widely all over the island, but no other food is anywhere to be found. Some of the mushrooms have been determined as poisonous and others as not (determined by your former companions trial and error). You are the only one remaining on the island. You have the following data to consider: Example NotHeavy Smelly Spotted Smooth Edible A 0 0 0 B 0 0 C 0 0 D 0 0 0 0 E 0 0 F 0 0 G 0 0 0 H 0 0 0 0 U 0? V 0? W 0 0? You know whether or not mushrooms A through H are poisonous, but you do not know about U through W.

6. For the a d questions, consider only mushrooms A through H. a. What is the entropy of Edible? b. Which attribute should you choose as the root of a decision tree? Hint: You can figure this out by looking at the data without explicitly computing the information gain of all four attributes. c. What is the information gain of the attribute you chose in the previous question? d. Build a ID3 decision tree to classify mushrooms as poisonous or not. e. Classify mushrooms U, V and W using the decision tree as poisonous or not poisonous. f. If themushrooms Athrough H that youknow are not poisonous suddenly became scarce, should you consider trying U, V and W? Which one(s) and why? Or if none of them, then why not?

7. a. H Edible = H[3+,5 ] def. = 3 8 log 3 8 5 8 log 5 8 = 3 8 log 8 3 + 5 8 log 8 5 = 3 8 3 3 8 log 3+ 5 8 3 5 8 log 5 = 3 3 8 log 3 5 8 log 5 0.9544

8. b. [3+,5 ] [3+,5 ] [3+,5 ] [3+,5 ] NotHeavy 0 Smelly 0 Spotted 0 Smooth 0 0 0 0 0 [+, ] [+,3 ] [+,3 ] [+, ] [+,3 ] [+, ] [+, ] [+,3 ] Node Node

9. c. def. H 0/Smooth = 4 8 H[+, ]+ 4 8 H[+,3 ] = + = + ( 4 + 3 4 3 ) 4 log 3 = + ( 4 log 4 + 3 4 log ( 3 4 log 3 ) ) 4 3 = + 3 8 log 3 = 3 3 8 log 3 0.9056 IG 0/Smooth def. = H Edible H 0/Smooth = 0.9544 0.9056 = 0.0488

d. 0. H 0/NotHeavy def. = 3 8 H[+, ]+ 5 8 H[+,3 ] = 3 ( 8 3 log 3 + ) 3 log 3 + 5 ( 8 5 log 5 + 3 ) 5 log 5 3 = 3 ( 8 3 log 3+ 3 log 3 ) 3 + 5 ( 8 5 log 5 5 + 3 5 log 5 3 ) 5 log 3 = 3 ( log 8 3 ) + 5 ( log 3 8 5 3 5 log 3 ) 5 = 3 8 log 3 8 + 5 8 log 5 3 8 log 3 8 = 5 8 log 5 4 8 0.95 IG 0/NotHeavy def. = H Edible H 0/NotHeavy = 0.9544 0.95 = 0.003, IG 0/NotHeavy = IG 0/Smelly = IG 0/Spotted = 0.003 < IG 0/Smooth = 0.0488

Important Remark (in Romanian). În loc să fi calculat efectiv aceste câştiguri de informaţie, pentru a determina atributul cel mai,,bun, ar fi fost suficient să comparăm valorile entropiilor condiţionale medii H 0/Smooth şi H 0/NotHeavy : IG 0/Smooth > IG 0/NotHeavy H 0/Smooth < H 0/NotHeavy 3 3 8 log 3 < 5 8 log 5 3log 3 < 5log 5 4 6 < 5log 5+3log 3 6 <.6096+4.7548 (adev.) În mod alternativ, ţinând cont de formulele de la problema UAIC, 07 fall, S. Ciobanu, L. Ciortuz, putem proceda chiar mai simplu relativ la calcule (nu doar aici, ori de câte ori nu avem de-a face cu un număr mare de instanţe): H 0/Netedă < H 0/Uşoară 44 44 3 3 < 55 3 3 3 3 48 3 3 < 55 4 8 < 3 3 5 5 6 < 3 3 5 5 64 0 }{{} 04 < 7 5 5 }{{} >3 8 5 }{{} 000 (adev.)

. Node : Smooth = 0 [+, ] NotHeavy 0 [+, ] Smelly 0 [+, ] Spotted 0 [0+, ] [+, ] [+,0 ] [0+, ] [+, ] [+, ] 0 0

3. Node : Smooth = [+,3 ] NotHeavy 0 [+,3 ] Smelly 0 [+,3 ] Spotted 0 [+, ] [0+, ] [0+,3 ] [+,0 ] [+, ] [0+, ] Node 3 0 0 0

The resulting ID3 Tree 4. [3+,5 ] Smooth 0 [+, ] [+,3 ] Smelly Smelly 0 0 IF (Smooth = 0 AND Smelly = 0) OR (Smooth = AND Smelly = ) THEN Edibile; ELSE Edible; [+,0 ] [0+, ] [0+,3 ] [+,0 ] 0 0 Classification of test instances: U Smooth =, Smelly = Edible = V Smooth =, Smelly = Edible = W Smooth = 0, Smelly = Edible = 0

5. Exemplifying the greedy character of the ID3 algorithm CMU, 003 fall, T. Mitchell, A. Moore, midterm, pr. 9.a

6. Fie atributele binare de intrare A,B,C, atributul de ieşire Y şi următoarele exemple de antrenament: A B C Y 0 0 0 0 0 0 0 a. Determinaţi arborele de decizie calculat de algoritmul ID3. Este acest arbore de decizie consistent cu datele de antrenament?

7. Răspuns Nodul 0: (rădăcina) [+, ] A 0 [+, ] B 0 [+, ] C 0 [+, ] [+, ] [+, ] [+, ] [0+, ] [+, ] 0 Nod Se observă imediat că primii doi compaşi de decizie (engl. decision stumps) au IG = 0, în timp ce al treilea compas de decizie are IG > 0. Prin urmare, în nodul 0 (rădăcină) vom pune atributul C.

8. Nodul : Avem de clasificat instanţele cu C =, deci alegerea se face între atributele A şi B. [+, ] A 0 [+, ] B 0 [+, ] [+,0 ] [+, ] [+,0 ] Nod Cele două entropii condiţionale medii sunt egale: H /A = H /B = 3 H[+, ]+ 3 H[+,0 ] Aşadar, putem alege oricare dintre cele două atribute. Pentru fixare, îl alegem pe A.

9. Nodul : La acest nod nu mai avem disponibil decât atributul B, deci îl vom pune pe acesta. [+, ] C 0 Arborele ID3 complet este reprezentat în figura alăturată. [0+, ] 0 [+, ] A 0 Prin construcţie, algoritmul ID3 este consistent cu datele de antrenament dacă acestea sunt consistente (i.e., necontradictorii). În cazul nostru, se verifică imediat că datele de antrenament sunt consistente. [+, ] [+,0 ] B 0 [0+, ] [+,0 ] 0

0. b. Există un arbore de decizie de adâncime mai mică (decât cea a arborelui ID3) consistent cu datele de mai sus? Dacă da, ce concept (logic) reprezintă acest arbore? Răspuns: Din date se observă că atributul de ieşire Y reprezintă de fapt funcţia logică A xor B. Reprezentând această funcţie ca arbore de decizie, vom obţine arborele alăturat. 0 [+, ] [+, ] A [+, ] Acest arbore are cu un nivel mai puţin decât arborele construit cu algoritmul ID3. Prin urmare, arborele ID3 nu este optim din punctul de vedere al numărului de niveluri. B 0 0 [0+, ] [+,0 ] [+,0 ] [0+, ] 0 0 B

. Aceasta este o consecinţă a caracterului greedy al algoritmului ID3, datorat faptului că la fiecare iteraţie alegem,,cel mai bun atribut în raport cu criteriul câştigului de informaţie. Se ştie că algoritmii de tip greedy nu grantează obţinerea optimului global.

. Exemplifying the application of the ID3 algorithm in the presence of both categorical and continue attributes CMU, 0 fall, Eric Xing, Aarti Singh, HW, pr..

3. As of September 0, 800 extrasolar planets have been identified in our galaxy. Supersecret surveying spaceships sent to all these planets have established whether they are habitable for humans or not, but sending a spaceship to each planet is expensive. In this problem, you will come up with decision trees to predict if a planet is habitable based only on features observable using telescopes. a. In nearby table you are given the data from all 800 planets surveyed so far. The features observed by telescope are Size ( Big or Small ), and Orbit ( Near or Far ). Each row indicates the values of the features and habitability, and how many times that set of values was observed. So, for example, there were 0 Big planets Near their star that were habitable. Size Orbit Habitable Count Big Near Yes 0 Big Far Yes 70 Small Near Yes 39 Small Far Yes 45 Big Near No 30 Big Far No 30 Small Near No Small Far No 55 Derive and draw the decision tree learned by ID3 on this data (use the maximum information gain criterion for splits, don t do any pruning). Make sure to clearly mark at each node what attribute you are splitting on, and which value corresponds to which branch. By each leaf node of the tree, write in the number of habitable and inhabitable planets in the training data that belong to that node.

Answer: Level 4. H(374/800) [374+,46 ] Size H(374/800) [374+,46 ] Orbit B S N F [90+,60 ] [84+,66 ] [59+,4 ] [5+,85 ] H(9/35) H(9/5) H(47/00) H(43/00) H(Habitable Size) = 35 80 H = 35 80 H(Habitable Orbit) = 3 8 H ( 47 00 ( ) 9 + 45 ( ) 9 35 80 H 5 45 0.9946 + 0.9759 = 0.984 80 ) + 5 ( ) 43 8 H 00 IG(Habitable; Size) = 0.08 IG(Habitable; Orbit) = 0.0067 = 3 8 0.9974+ 5 8 0.9858 = 0.990

5. The final decision tree [374+,46 ] Size B [90+,60 ] Orbit S [84+,66 ] Orbit N F N F [0+,30 ] [70+,30 ] [39+, ] [45+,55 ] + +

6. b. For just 9 of the planets, a third feature, Temperature (in Kelvin degrees), has been measured, as shown in the nearby table. Redo all the steps from part a on this data using all three features. For the Temperature feature, in each iteration you must maximize over all possible binary thresholding splits (such as T 50 vs. T > 50, for example). Size Orbit Temperature Habitable Big Far 05 No Big Near 05 No Big Near 60 Yes Big Near 380 Yes Small Far 05 No Small Far 60 Yes Small Near 60 Yes Small Near 380 No Small Near 380 No According to your decision tree, would a planet with the features (Big, Near, 80) be predicted to be habitable or not habitable? Hint: You might need to use the following values of the entropy function for a Bernoulli variable of parameter p: H(/3) = 0.98, H(/5) = 0.9709, H(9/5) = 0.9759, H(43/00) = 0.9858, H(6/35) = 0.9946, H(47/00) = 0.9974.

7. Answer Binary threshold splits for the continuous attribute Temperature: 05 3.5 60 30 380 Temperature

Answer: Level 8. H(4/9) [4+,5 ] H(4/9) [4+,5 ] H(4/9) [4+,5 ] H(4/9) [4+,5 ] Size Orbit T<=3.5 T<=30 B S F N Y N Y N [+, ] H= [+,3 ] H(/5) [+, ] H(/3) [3+,3 ] H= > > [0+,3 ] H=0 > = [4+, ] H(/3) [3+,3 ] H= [+, ] H(/3) ( ) H(Habitable Size) = 4 9 + 5 ( ) 87 9 H = 4 5 9 + 5 IG(Habitable; Size) = H 0.9838 0.9709 = 0.9838 400 9 H(Habitable Temp 3.5) = ( ) = 0.9969 0.9838 3 H = 0.98 = 0.6 = 0.007 3 3 IG(Habitable; Temp 3.5) = 0.3788

Answer: Level 9. H(/3) [4+, ] Size H(/3) [4+, ] Orbit H(/3) [4+, ] T<=30 B S F N Y N [+,0 ] + H=0 [+, ] H= [+,0 ] + H=0 [3+, ] H(/5) [3+,0 ] + H=0 [+, ] H(/3) >= > > > Note: The plain lines indicate that both the specific conditional entropies and their coefficients (weights) in the average conditional entropies satisfy the indicated relationship. (For example, H(/5) > H(/3) and 5/6 > 3/6.) The dotted lines indicate that only the specific conditional entropies satisfy the indicated relationship. (For example, H(/) = > H(/5) but 4/6 < 5/6.)

The final decision tree: 30. [4+,5 ] T<=3.5 Y N [0+,3 ] [4+, ] T<=30 Y N [3+,0 ] [+, ] c. According to your decision tree, would a planet with the features (Big, Near, 80) be predicted to be habitable or not habitable? Answer: habitable. + Size B [+,0 ] S [0+, ] +

3. Exemplifying the application of the ID3 algorithm on continuous attributes, and in the presence of a noise. Decision surfaces; decision boundaries. The computation of the LOOCV error CMU, 00 fall, Andrew Moore, midterm, pr. 3

3. Suppose we are learning a classifier with binary input values Y = 0 and Y =. There is one real-valued input X. The training data is given in the nearby table. Assume that we learn a decision tree on this data. Assume that when the decision tree splits on the real-valued attribute X, it puts the split threshold halfway between the attributes that surround the split. For example, using information gain as splitting criterion, the decision tree would initially choos to split at X = 5, which is halfway between X = 4 and X = 6 datapoints. X Y 0 0 3 0 4 0 6 7 8 8.5 0 9 0 Let Algorithm DT be the method of learning a decision tree with only two leaf nodes (i.e., only one split). Let Algorithm DT be the method of learning a decision tree fully, with no prunning. a. What will be the training set error for DT and respectively DT on our data? b. What will be the leave-one-out cross-validation error (LOOCV) for DT and respectively DT on our data?

33. training data: 0 3 4 5 6 7 8 9 0 discretization / decision thresholds: 3 4 6 7 8 9 0 5 8.5 8.75 compact representation of the ID3 tree: X X ID3 tree: [5,5+] X<5 Da [4,0+] 0 0 Nu [,5+] X<8.5 Da Nu 3 4 5 6 7 8 9 0 decision surfaces : 0 + + 5 8.5 8.75 X X [0,3+] [,+] X<8.75 Da [,0+] [0,+] 0 Nu

34. Level 0: [5,5+] [5,5+] [5,5+] X<5 X<8.5 X<8.75 Da Nu Da Nu Da Nu ID3: IG computations [4,0+] [,5+] < [4,3+] < = [,+] [5,3+] [0,+] Level : [,5+] X<8.5 [,5+] X<8.75 Da Nu Da Nu [0,3+] IG: 0.9 [,+] [,3+] IG: 0.09 [0,+] Decision "surfaces": + 5 8.5 8.75 +

ID3, LOOCV: Decision surfaces LOOCV error: 3/0 X=,,3: X=4: X=6: X=7: X=8: X=8.5: X=9: X=0: 4.5 + + 8.5 8.75 5 7.75 8.75 + + 5 8.5 8.75 5.5 5 + + 8.5 + 5 8.5 8.75 + 5 8.5 + 8.75 9.5 5 8.5 8.75 + + + + + + + + 35.

36. DT [5,5+] X<5 Da [4,0+] Nu [,5+] 0 Decision "surfaces": + 5

DT, LOOCV IG computations 37. Case : X=,, 3, 4 Da [3,0+] [4,5+] X<5 /4.5 X<8.5 X<8.75 Nu Da Nu Da Nu [,5+] < [3,3+] [4,5+] < = [,+] [4,3+] [4,5+] [0,+] Case : X=6, 7, 8 [5,4+] [5,4+] [5,4+] X<5 /5.5 X<8.5 /7.75 X<8.75 Da Nu Da Nu Da Nu [4,0+] [,4+] [4,+] [,+] [5,+] [0,+] < = < =

DT, CVLOO IG computations (cont d) [4,5+] 38. Case 3: X=8.5 Da X<5 Nu [4,0+] [0,5+] Case : X=9, 0 [5,4+] [5,4+] [5,4+] X<5 X<8.5 X<8.75 /9.5 Da Nu Da Nu Da Nu [4,0+] [,4+] [4,3+] [,+] [5,3+] [0,+] < < = CVLOO error: /0

39. Applying ID3 on a dataset with two continuous attributes: decision zones Liviu Ciortuz, 07

40. Consider the training dataset in the nearby figure. X and X are considered countinous attributes. Apply the ID3 algorithm on this dataset. Draw the resulting decision tree. X 4 3 Make a graphical representation of the decision areas and decision boundaries determined by ID3. 0 0 3 4 5 X

4. Solution Level : [4+,5 ] [4+,5 ] [4+,5 ] [4+,5 ] [4+,5 ] X < 5/ X < 9/ X < 3/ X < 5/ X < 7/ Y N Y N Y N Y N Y N [+,0 ] [+,5 ] [+,4 ] [+, ] [+, ] [3+,4 ] [3+, ] [+,3 ] [4+, ] [0+,3 ] H(/7) H(/3) H(/3) H= H(3/7) H(/5) H(/4) H(/3) IG=0.09 H=0 > H=0 IG=0.39 > IG=0.378 = < H[Y. ] = 7/9 H(/7) H[Y. ] = 5/9 H(/5) + 4/9 H(/4) H[Y. ] = /3 H(/3)

Level : [4+, ] X < 5/ [4+, ] [4+, ] [4+, ] X < 4 X < 3/ X < 5/ 4. Y N Y N Y N Y N Notes: [+,0 ] H=0 IG=0.5 H[Y. ] = /3 [+, ] H= = = [+, ] H= IG=0.5 > [+,0 ] H=0 [+, ] [3+, ] H= H(/4) IG=0.04 H[Y. ] = /3 + /3 H(/4) > [3+, ] [+,0 ] H(/5) H=0 IG=0.09 H[Y. ] = 5/6 H(/5). Split thresholds for continuous attributes must be recomputed at each new iteration, because they may change. (For instance, here above, 4 replaces 4.5 as a threshold for X.). In the current stage, i.e., for the current node in the ID3 tree you may choose (as test) either X < 5/ or X < 4. 3. Here above we have an example of reverse relationships between weighted and respectively un-weighted specific entropies: H[+, ] > H[3+, ] but 4 6 H[+, ] < 5 6 H[3+, ].

43. The final decision tree: [4+,5 ] X < 7/ X Decision areas: Y N [4+, ] [0+,3 ] X < 5/ Y N [+,0 ] [+, ] 4 3 + + B X < 4 S + [+,0 ] [0+, ] + 0 0 3 4 5 X

44. Exemplifying pre- and post-puning of decision trees using a threshold for the Information Gain CMU, 006 spring, Carlos Guestrin, midterm, pr. 4 [adapted by Liviu Ciortuz]

45. Starting from the data in the following table, the ID3 algorithm builds the decision tree shown nearby. V W X Y 0 0 0 0 0 0 0 0 0 0 X 0 V 0 0 W 0 W 0 0 a. One idea for pruning such a decision tree would be to start at the root, and prune splits for which the information gain (or some other criterion) is less than some small ε. This is called topdown pruning. What is the decision tree returned for ε = 0.000? What is the training set error for this tree?

Answer We will first augment the given decision tree with informations regarding the data partitions (i.e., the number of positive and, respectively, negative instances) which were assigned to each test node during the application of ID3 algorithm. The information gain yielded by the attribute X in the root node is: H[3+; ] /5 0 4/5 = 0.97 0.8 = 0.7 > ε. Therefore, this node will not be eliminated from the tree. The information gain for the attribute V (in the lefthand side child of the root node) is: H[+; ] / / = = 0 < ε. [+; ] So, the whole left subtree will be cut off and replaced by a decision node, as shown nearby. The training error produced by this tree is /5. [+; ] [3+; ] X V 0 0 [+; ] W W 0 0 0 0 [+;0 ] [0+; ] [+;0 ] [+;0 ] [0+; ] X 0 0 46.

47. b. Another option would be to start at the leaves, and prune subtrees for which the information gain (or some other criterion) of a split is less than some small ε. In this method, no ancestors of children with high information gain will get pruned. This is called bottom-up pruning. What is the tree returned for ε = 0.000? What is the training set error for this tree? Answer: The information gain of V is IG(Y;V) = 0. A step later, the information gain of W (for either one of the descendent nodes of V) is IG(Y;W) =. So bottom-up pruning won t delete any nodes and the tree [given in the problem statement] remains unchanged. The training error is 0.

48. c. Discuss when you would want to choose bottom-up pruning over top-down pruning and vice versa. Answer: Top-down pruning is computationally cheaper. When building the tree we can determine when to stop (no need for real pruning). But as we saw top-down pruning prunes too much. On the other hand, bottom-up pruning is more expensive since we have to first build a full tree which can be exponentially large and then apply pruning. The second problem with bottom-up pruning is that supperfluous attributes may fullish it (see CMU, CMU, 009 fall, Carlos Guestrin, HW, pr..4). The third problem with it is that in the lower levels of the tree the number of examples in the subtree gets smaller so information gain might be an inappropriate criterion for pruning, so one would usually use a statistical test instead.

49. Exemplifying χ -Based Pruning of Decision Trees CMU, 00 fall, Ziv Bar-Joseph, HW, pr..

50. In class, we learned a decision tree pruning algorithm that iteratively visited subtrees and used a validation dataset to decide whether to remove the subtree. However, sometimes it is desirable to prune the tree after training on all of the available data. One such approach is based on statistical hypothesis testing. After learning the tree, we visit each internal node and test whether the attribute split at that node is actually uncorrelated with the class labels. We hypothesize that the attribute is independent and then use Pearson s chi-square test to generate a test statistic that may provide evidence that we should reject this null hypothesis. If we fail to reject the hypothesis, we prune the subtree at that node.

5. a. At each internal node we can create a contingency table for the training examples that pass through that node on their paths to the leaves. The table will have the c class labels associated with the columns and the r values the split attribute associated with the rows. Each entry O i,j in the table is the number of times we observe a training sample with that attribute value and label, where i is the row index that corresponds to an attribute value and j is the column index that corresponds to a class label. In order to calculate the chi-square test statistic, we need a similar table of expected counts. The expected count is the number of observations we would expect if the class and attribute are independent. Derive a formula for each expected count E i,j in the table. Hint: What is the probability that a training example that passes through the node has a particular label? Using this probability and the independence assumption, what can you say about how many examples with a specific attribute value are expected to also have the class label?

5. b. Given these two tables for the split, you can now calculate the chi-square test statistic r c χ (O i,j E i,j ) = i= j= with degrees of freedom (r )(c ). You can plug the test statistic and degrees of freedom into a software package a or an online calculator b to calculate a p-value. Typically, if p < 0.05 we reject the null hypothesis that the attribute and class are independent and say the split is statistically significant. The decision tree given on the next slide was built from the data in the table nearby. For each of the 3 internal nodes in the decision tree, show the p-value for the split and state whether it is statistically significant. How many internal nodes will the tree have if we prune splits with p 0.05? a Use -chicdf(x,df) in MATLAB or CHIDIST(x,df) in Excel. b (https://en.m.wikipedia.org/wiki/chi-square distribution#table of.cf.87 value vs p-value. E i,j

53. Input: X X X 3 X 4 Class 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [3,0+] [4,+] X [0,+] [4,8+] X 4 0 [,+] X 0 [0,6+] [,0+] 0

54. Idea While traversing the ID3 tree [usually in bottom-up manner], remove the nodes for which there is not enough ( significant ) statistical evidence that there is a dependence between the values of the input attribute tested in that node and the values of the output attribute (the labels), supported by the set of instances assigned to that node.

O X4 Class = 0 Class = X 4 = 0 4 X 4 = 0 6 Contingency tables N= P(X 4 = 0) = 6 =, P(X 4 = ) = P(Class = 0) = 4 = 3, P(Class = ) = 3 P(X = 0 X 4 = 0) = 3 6 = 55. O X X 4 =0 Class = 0 Class = X = 0 3 0 X = N=6 P(X = X 4 = 0) = P(Class = 0 X 4 = 0) = 4 6 = 3 P(Class = X 4 = 0) = 3 P(X = 0 X 4 = 0,X = ) = 3 O X X 4 =0,X = Class = 0 Class = X = 0 0 N=3 P(X = X 4 = 0,X = ) = 3 X = 0 P(Class = 0 X 4 = 0,X = ) = 3 P(Class = X 4 = 0,X = ) = 3

56. The reasoning that leads to the computation of the expected number of observations P(A = i,c = j) = P(A = i) P(C = j) c k= P(A = i) = O r i,k k= and P(C = j) = O k,j N N P(A = i,c = j) indep. = ( c k= O i,k)( r k= O k,j) N E[A = i,c = j] = N P(A = i,c = j)

Expected number of observations 57. E X4 Class = 0 Class = X 4 = 0 4 X 4 = 4 E X X 4 Class = 0 Class = X = 0 X = E X X 4,X = Class = 0 Class = X = 0 X = 3 3 4 3 3 E X4 (X 4 = 0,Class = 0) : N =, P(X 4 = 0) = şi P(Class = 0) = 3 N P(X 4 = 0,Class = 0) = N P(X 4 = 0) P(Class = 0) = 3 =

χ Statistics r c χ (O i,j E i,j ) = i= j= E i,j 58. χ X 4 = (4 ) + (0 ) + ( 4) 4 + (6 4) 4 = +++ = 6 χ X X 4 = (3 ) =0 χ X X 4 =0,X = = ( 0 3 + ( ) + (0 ) + ( ) = 3 ) ( ) ( 4 ) 3 3 + + + 4 3 3 3 p-values: 0.043, 0.0833, and respectively 0.0833. ( 0 ) 3 3 = 4 9 7 4 = 3 The first one of these p-values is smaller than ε, therefore the root node (X 4 ) cannot be prunned.

Chi Squared Pearson test statistics 59. p value 0.0 0. 0.4 0.6 0.8.0 k = k = k = 3 k = 4 k = 6 k = 9 0 4 6 8 χ Pearson s cumulative test statistic

60. Output (pruned tree) for 95% confidence level 0 X 4 0

6. The AdaBoost algorithm: The convergence in certain conditions to 0 of the training error CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr..-5 CMU, 009 fall, Carlos Guestrin, HW, pr. 3. CMU, 009 fall, Eric Xing, HW3, pr. 4..

Consider m training examples S = {(x,y ),...,(x m,y m )}, where x X and y {,}. Suppose we have a weak learning algorithm A which produces a hypothesis h : X {, } given any distribution D of examples. AdaBoost is an iterative algorithm which works as follows: Begin with a uniform distribution D (i) = m, i =,...,m. At each round t =,...,T, run the weak learning algorithm A on the distribution D t and produce the hypothsis h t ; Note: Since A is a weak learning algorithm, the produced hypothesis h t at round t is only slightly better than random guessing, say, by a margin γ t : 6. ε t = err Dt (h t ) = Pr x Dt [y h t (x)] = γ t. [If at a certain iteration t < T the weak classifier A cannot produce a hypothesis better than random guessing (i.e., γ t = 0) or it produces a hypothesis for which ε t = 0, then the AdaBoost algorithm should be stopped.] update D t+ (i) = Z t D t (i) e α ty i h t (x i ) for i =,...,m, not. where α t = ln ε t, and Z t is the normalizer. ε t ( T ) In the end, deliver H = sign t= α th t as the learned hypothesis, which will act as a weighted majority vote.

63. We will prove that the training error err S (H) of AdaBoost decreases at a very fast rate, and in certain cases it converges to 0. Important Remark The above formulation of the AdaBoost algorithm states no restriction on the h t hypothesis delivered by the weak classifier A at iteration t, except that ε t < /. However, in another formulation of the AdaBoost algorithm (in a more general setup; see for instance MIT, 006 fall, Tommi Jaakkola, HW4, problem 3), it is requested / reccommended that hypothesis h t be chosen by (approximately) maximizing the [criterion of] weighted training error on a whole class of hypotheses like, for instance, decision trees of depth (decision stumps). In this problem we will not be concerned with such a request, but we will comply with it for instance in problem CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr.6, when showing how AdaBoost works in practice.

64. a. Show that the [particular] choice of α t = ln ε t implies err Dt+ (h t ) = /. ε t ( ) e b. Show that D T+ (i) = m T t= Z y i f(x i t ), where f(x) = T t= α th t (x). c. Show that err S (H) T t= Z t, where err S (H) not. = m m i= {H(x i ) y i } is the traing error produced by AdaBoost. d. Obviously, we would like to minimize test set error produced by AdaBoost, but it is hard to do so directly. We thus settle for greedily optimizing the upper bound on the training error found at part c. Observe that Z,...,Z t are determined by the first t iterations, and we cannot change them at iteration t. A greedy step we can take to minimize the trainingset errorbound onroundtisto minimize Z t. Prove that the value of α t that minimizes Z t (among all possible values for α t ) is indeed α t = ln ε t (see the previous slide). ε t e. Show that T t= Z t e T t= γ t. f. From part c and d, we know the training error decreases at exponential rate with respect to T. Assume that there is a number γ > 0 such that γ γ t for t =,...,T. (This is called empirical γ-weak learnability.) How many rounds are needed to achieve a training error ε > 0? Please express in big-o notation, T = O( ).

Solution 65. a. If we define the correct set C = {i : y i h t (x i ) 0} and the mistake set M = {i : y i h t (x i ) < 0}, we can write: err Dt+ (h t ) = Z t = m m i= D t+ (i) {yi h t (x i )} = i M i=d t (i)e αtyiht(xi) = i CD t (i)e αt + i M ε e α t = e ln t ε t = e ln Z t = ( ε t ) ε t ε t εt ε t +ε t err Dt+ (h t ) = Z t ε t e α t = Note that ε t ε t > 0 because ε t (0, /). D t (i)e α t = Z t Z t i M D t (i) e α t = ε t e α t Z t }{{} ε t D t (i)e α t = ( ε t ) e α t +ε t e α t () ε t ( ε t ) ε t εt εt = and e α t = ε t e α = t ε t εt = ε t ( ε t ) () ε t εt = ε t

b. We will expand D t (i) recursively: 66. D T+ (i) = Z T D T (i)e α T y i h T (x i ) = D T (i) Z T e α T y i h T (x i ) = D T (i) e α T y i h T (x i ) e α T y i h T (x i ) Z T Z T. = D (i) T t= Z t e T t= α t y i h t (x i ) = m T t= Z t e y i f(x i ). c. We will make use of the fact that exponential loss upper bounds the 0- loss, i.e. {x<0} e x : m err S (H) = m i= {yi f(x i )<0} m e y i f(x i ) = m D T+ (i) m m m i= i= ( m ) ( T ) T = D T+ (i) Z t = Z t. i= } {{ } t= t= T Z t = t= m T D T+ (i) i= t= Z t

d. We will start from the equation 67. Z t = ε t e α t +( ε t ) e α t, which has been proven at part a. Note that the right-hand side is constant with respect to ε t (the error produced by h t, the hypothesis produced by the weak classifier A at the current step). Then we will proceed as usually, computing the partial derivative w.r.t. ε t : α t ( εt e α t +( ε t ) e α t ) = 0 ε t e α t ( ε t ) e α t = 0 ε t (e α t ) = ε t e α t = ε t ε t α t = ln ε t ε t Note that ε t ε t > (and therefore α t > 0) because ε t (0, /). It can also be immediately shown that α t = ln ε t ε t α t = ln ε t ε t. is indeed the value for which we reach the minim of the expression ε t e α t +( ε t ) e α t, and therefore of Z t too: ε t e α t ( ε t ) e α t > 0 e α t ε t ε t > 0 α t > ln ε t ε t > 0.

e. Making use of the relationship () proven at part a, and using the fact that x e x for all x R, we can write: T T T ( )( ( )) T Z t = ε t ( ε t ) = γ t γ t = 4γt t= t= T t= e 4γ t = T t= t= (e γ t) = T t= e γ t = e T t= γ t. t= 68. f. From the result obtained at parts c and d, we get: Therefore, err S (H) e T t= γ t e Tγ err S (H) < ε if Tγ < lnε Tγ > lnε Tγ > ln ε T > γ ln ε ( Hence we need T = O γ ln ). ε Note: It follows that err S (H) 0 as T.

69. Exemplifying the application of AdaBoost algorithm CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr..6

70. Consider the training dataset in the nearby figure. Run T = 3 iterations of AdaBoost with decision stumps (axis-aligned separators) as the base learners. Illustrate the learned weak hypotheses h t in this figure and fill in the table given below. (For the pseudo-code of the AdaBoost algorithm, see CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr..-5. Please read the Important Remark that follows that pseudo-code!) X 4 3 0 0 x x x 3 x 6 x 7 x 4 x 5 x 8 x 9 3 4 5 X t ε t α t D t () D t () D t (3) D t (4) D t (5) D t (6) D t (7) D t (8) D t (9) err S (H) 3 Note: The goal of this exercise is to help you understand how AdaBoost works in practice. It is advisable that after understanding this exercise you would implement a program / function that calculates the weighted training error produced by a given decision stump, w.r.t. a certain probabilistic distribution (D) defined on the training dataset. Later on you will extend this program to a full-fledged implementation of AdaBoost.

7. Solution Unlike the graphical reprezentation that we used until now for decision stumps (as trees of depth ), here we will work with the following analitical representation: for a continuous attribute X taking values x R and for any threshold s R, we can define two decision stumps: sign(x s) = { if x s if x < s and sign(s x) = { if x s if x < s. For convenience, in the sequel we will denote the first decision stump with X s and the second with X < s. According to the Important Remark that follows the AdaBoost pseudo-code [see CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr..-5], at each iteration (t) the weak algorithm A selects the/a decision stump which, among all decision stumps, has the minimum weighted training error w.r.t. the current distribution (D t ) on the training data.

Notes 7. When applying the ID3 algorithm, for each continous attribute X, we used a threshold for each pair of examples (x i,y i ), (x i+,y i+ ), with y i y i+ < 0 such that x i < x i+, but no x j Val(X) for which x i < x j < x i+. We will proceed similarly when applying AdaBoost with decision stumps and continous attributes. [In the case of ID3 algorithm, there is a theoretical result stating that there is no need to consider other thresholds for a continuous attribute X apart from those situated beteen pairs of successive values (x i < x i+ ) having opposite labels (y i y i+ ), because the Information Gain (IG) for the other thresholds (x i < x i+, with y i = y i+ ) is provably less than the maximal IG for X. LC: A similar result can be proven, which allows us to simplify the application of the weak classifier (A) in the framework of the AdaBoost algorithm.] Moreover, we will consider also a threshold from the outside of the interval of values taken by the attribute X in the training dataset. [The decision stumps corresponding to this outside threshold can be associated with the decision trees of depth 0 that we met in other problems.]

73. Iteration t = : Therefore, at this stage (i.e, the first iteration of AdaBoost) the thresholds for the two continuous variables (X and X ) correspondingto the two coordinates of the training instances (x,...,x 9 ) are, 5, and 9 for X, and, 3, 5 and 7 for X. One can easily see that we can get rid of the outside threshold for X, because the decision stumps corresponding to this threshold act in the same as the decision stumps associated to the outside threshold for X. The decision stumps corresponding to this iteration together with their associated weighted training errors are shown on the next slide. When filling those tabels, we have used the equalities err Dt (X s) = err Dt (X < s) and, similarly, err Dt (X s) = err Dt (X < s), for any threshold s and every iteration t =,,... These equalities are easy to prove.

s err D (X < s) err D (X s) s err D (X < s) err D (X s) 4 9 5 9 4 9 5 9 5 9 7 9 3 9 + 3 9 = 4 9 5 9 9 4 9 + 9 = 3 3 5 9 + 9 = 3 3 7 9 7 9 74. It can be seen that the minimal weighted training error (ε = /9) is obtained ( for) the 7 decision stumps X < 5/ and X < 7/. Therefore we can choose h = sign X as best hypothesis at iteration t = ; the corresponding separator is the line X = 7. The h hypothesis wrongly classifies the instances x 4 and x 5. Then γ = 9 = 5 8 and α = ln ε ε = ln ( ) : 7 9 9 = ln 0.66

75. Now the algorithm must get a new distribution (D ) by altering the old one (D ) so that the next iteration concentrates more on the misclassified instances. D (i) = D (i)(e α Z } {{} ) y i h (x i ) Z = 9 for i {,,3,6,7,8,9}; 7 /7 Z 9 7 for i {4,5}. Remember that Z is a normalization factor for D. So, ( Z = ) 7 7 9 7 + = 4 = 0.835 9 Therefore, D (i) = 9 4 9 9 4 9 7 = 4 7 = 4 for i {4,5}; for i {4,5}. X 4 3 0 0 /4 x x /4 /4 /4 /4 x 3 x x 6 7 x /4 x 4 8 /4 /4 x 5 3 4 5 x /4 9 + X h

76. Note ( ) 7 If, instead of sign X we would have taken, as hypothesis h, the decision stump sign ( ) 5 X, the subsequent calculus would have been slightly different (although both decision stumps have the same minimal weighted training error, 9 ): x 8 and x 9 would have been allocated the weights 4, while x 4 şi x 5 would have been allocated the weights 4. (Therefore, the output of AdaBoost may not be uniquely determined!)

Iteration t = : 77. s err D (X < s) err D (X s) s err D (X < s) err D (X s) 4 4 0 4 4 4 0 4 5 4 4 3 4 + 3 4 = 3 8 5 8 9 4 + 4 + 4 = 4 3 4 5 4 + 4 = 8 4 6 4 7 4 = Note: According to the theoretical result presented at part a of CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr..-5, computing the weighted error rate of the decision stump [corresponding to the test] X < 7/ is now superfluous, because this decision stump has been chosen as optimal hypothesis at the previous iteration. (Nevertheless, we had placed it into the tabel, for the sake of a thorough presentation.)

( ) 5 Now the best hypothesis is h = sign X ; the corresponding separator is the line X = 5. 78. ε = P D ({x 8,x 9 }) = 4 = 7 = 0.43 γ = 7 = 5 4 ( ε = ln = ln ) : 7 7 = ln 6 = 0.896 α ε D 3 (i) = D (i) (e α Z }{{} ) y i h (x i ) = / 6 = 4 Z Z 4 Z 6 for i {,,3,6,7}; 6 for i {4,5}; 4 6 for i {8,9}. Z D (i) D (i) 6 Z 6 if h (x i ) = y i ; otherwise

79. Z = 5 4 + 6 4 6 + 6 = 5 4 4 6 + 6 + 6 7 = + 4 6 = 4 4 6 = 6 7 0.7 D 3 (i) = 7 6 4 7 6 4 7 6 6 = 4 6 = 7 48 4 6 = 4 for i {,,3,6,7}; for i {4,5}; for i {8,9}. X h 4 /4 3 x /4 x + /4 /4 /4 x 3 x 6 x 7 7/48 /4 x 4 x 8 7/48 /4 x x 5 9 + h 0 0 3 4 5 X

80. Iteration t = 3: s err D3 (X < s) err D3 (X s) s err D3 (X < s) err D3 (X s) 7 5 4 + 4 = 7 5 5 4 4 3 7 48 + 4 + 4 = 3 48 5 48 9 4 + 7 48 + 4 = 4 3 4 = 8 5 7 48 + 4 = 3 3 7 7 48 = 7 4 7 4

8. ( The new best hypothesis is h 3 = sign X 9 ) ; the corresponding separator is the line X = 9. ε 3 = P D3 ({x,x,x 7 }) = 4 + 4 = 3 4 = 8 X h h 3 + + 4 x 3 x 6 3 x x 7 + h γ 3 = 8 = 3 8 α 3 = ln ε3 ε 3 = ln ( ) : 8 8 = ln 7 = 0.973 0 x x 4 x 5 x 8 x 9 0 3 4 5 X

8. Finally, after filling our results in the given table, we get: t ε t α t D t () D t () D t (3) D t (4) D t (5) D t (6) D t (7) D t (8) D t (9) err S (H) /9 ln 7/ /9 /9 /9 /9 /9 /9 /9 /9 /9 /9 /4 ln 6 /4 /4 /4 /4 /4 /4 /4 /4 /4 /9 3 /8 ln 7 /4 /4 /4 7/48 7/48 /4 /4 /4 /4 0 Note: The following table helps ( you understand how err S (H) was computed; remember that H(x i ) def. T ) = sign t= α t h t (x i ). t α t x x x 3 x 4 x 5 x 6 x 7 x 8 x 9 0.66 + + + + + + 0.896 + + 3 0.973 + + + H(x i ) + + + +

83. Remark: One can immediately see that the [test] instance (, 4) will be classified by the hypothesis H learned by AdaBoost as negative (since α +α α 3 = 0.66+ 0.896 0.973 < 0). After making other similar calculi, we can conclude that the decision zones and the decision boundaries produced by AdaBoost for the given training data will be as indicated in the nearby figure. X h h 3 4 3 0 0 x x x x 3 6 x 4 x 5 3 4 5 x 7 x 8 x 9 X h Remark: The execution of AdaBoost could continue (if we would have taken initially T > 3...), although we have obtained err S (H) = 0 at iteration t = 3. By elaborating the details, we would see that for t = 4 we would obtain as optimal hypothesis X < 7/ (which has already been selected at iteration t = ). This hypothesis produces now the weighted training error ε 4 = /6. Therefore, α 4 = ln 5, and this will be added to α = ln 7/ in the new output H. In this way, the confidence in the hypothesis X < 7/ would be strenghened. So, we should keep in mind that AdaBoost can select several times a certain weak hypothesis (but never at consecutive iterations, cf. CMU, 05 fall, E. Xing, Z. Bar- Joseph, HW4, pr..).

84. Seeing AdaBoost as an optimization algorithm, w.r.t. the [inverse] exponential loss function CMU, 008 fall, Eric Xing, HW3, pr. 4.. CMU, 008 fall, Eric Xing, midterm, pr. 5.

85. At CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr..-5, part d, we have shown that in AdaBoost, we try to [indirectly] minimize the training error err S (H) by sequentially minimizing its upper bound T t= Z t, i.e. at each iteration t ( t T) we choose α t so as to minimize Z t (viwed as a function of α t ). Here you will see that another way to explain AdaBoost is by sequentially minimizing the negative exponential loss: E def. = m i= exp( y i f T (x i )) not. = m T exp( y i α t h t (x i )). (3) i= t= That is to say, at the t-th iteration ( t T) we want to choose besides the appropriate classifier h t the corresponding weight α t so that the overall loss E (accumulated up to the t-th iteration) is minimized. Prove that this [new] strategy will lead to the same update rule for α t used in AdaBoost, i.e., α t = ln ε t ε t. Hint: You can use the fact that D t (i) exp( y i f t (x i )), and it [LC: the proportionality factor] can be viewed as constant when we try to optimize E with respect to α t in the t-th iteration.

Solution 86. At the t-th iteration, we have ( ( m m t ) ) E = exp( y i f t (x i )) = exp y i α t h t (x i ) y i α t h t (x i ) = i= i= t = m exp( y i f t (x i )) exp( y i α t h t (x i )) i= m i= D t (i) exp( y i α t h t (x i )) not. = E (see CMU, 05 fall, Z. Bar-Joseph, E. Xing, HW4, pr..-5, part b) Further on, we can rewrite E as E = m i=d t (i) exp( y i α t h t (x i )) = i CD t (i)exp( α t )+ i M D t (i)exp(α t ) = ( ε t ) e α t +ε t e α t, (4) where C is the set of examples which are correctly classified by h t, and M is the set of examples which are mis-classified by h t.

87. The relation (4) is identical with the expression () from part a of CMU, 05 fall, Ziv Bar-Joseph, Eric Xing, HW4, pr..-5 (see the solution). Therefore, E will reach its minim for α t = ln ε t ε t.

88. AdaBoost algorithm: the notion of [voting] margin; some properties CMU, 06 spring, W. Cohen, N. Balcan, HW4, pr. 3.3

Despite that model complexity increases with each iteration, AdaBoost does not usually overfit. The reason behind this is that the model becomes more confident as we increase the number of iterations. The confidence can be expressed mathematically as the [voting] margin. Recall that after the algorithm AdaBoost terminates with T iterations the [output] classifier is ( T ) 89. H T (x) = sign t= α t h t (x). Similarly, we can define the intermediate weighted classifier after k iterations as: ( k ) H k (x) = sign t= α t h t (x). As its output is either or, it does not tell the confidence of its judgement. Here, without changing the decision rule, let ( k ) H k (x) = sign t= ᾱ t h t (x), where ᾱ t = α t k t = α t so that the weights on each weak classifier are normalized.

90. Define the margin after the k-th iteration as [the sum of] the [normalized] weights of h t voting correctly minus [the sum of] the [normalized] weights of h t voting incorrectly. Margin k (x) = ᾱ t ᾱ t. t:h t (x)=y t:h t (x) y a. Let f k (x) not. = k t=ᾱth t (x). Show that Margin k (x i ) = y i f k (x i ) for all training instances x i, with i =,...,m. b. If Margin k (x i ) > Margin k (x j ), which of the samples x i and x j will receive a higher weight in iteration k +? Hint: Use the relation D k+ (i) = m k t= Z exp( y i f k (x i )) which was proven t at CMU, 05 fall, Z. Bar-Joseph, E. Xing, HW4, pr...

9. Solution a. We will prove the equality starting from its right hand side: k y i f k (x i ) = y i ᾱ t h t (x i ) = t= = Margin k (x i ). k ᾱ t y i h t (x i ) = t= t:h t (x i )=y i ᾱ t t:h t (x i ) y i ᾱ t b. According to the relationship already proven at part a, Margin k (x i ) > Margin k (x j ) y i f k (x i ) > y j f k (x j ) y i f k (x i ) < y j f k (x j ) exp( y i f k (x i )) < exp( y j f k (x j )). Based on the given Hint, it follows that D k+ (i) < D k+ (j).

9. Important Remark It can be shown mathematically that boosting tends to increase the margins of training examples see the relation (3) at CMU, 008 fall, Eric Xing, HW3, pr. 4.., and that a large margin on training examples reduces the generalization error. Thus we can explain why, although the number of parameters of the model created by AdaBoost increases with at every iteration therefore complexity rises, it usually doesn t overfit.

93. AdaBoost: a sufficient condition for γ-weak learnability, based on the voting margin CMU, 06 spring, W. Cohen, N. Balcan, HW4, pr. 3..4

94. At CMU, 05 fall, Z. Bar-Joseph, E. Xing, HW4, pr..5 we encountered the notion of empirical γ-weak learnability. When this condition γ γ t for def. all t, where γ t = ε t, with ε t being the weighted training error produced by the weak hypothesis h t is met, it ensures that AdaBoost will drive down the training error quickly. However, this condition does not hold all the time. In this problem we will prove a sufficient condition for empirical weak learnability [to hold]. This condition refers to the notion of voting margin which was presented in CMU, 06 spring, W. Cohen, N. Balcan, HW4, pr. 3.3. Namely, we will prove that if there is a constant θ > 0 such that the [voting] margins of all training instances are lower-bounded by θ at each iteration of the AdaBoost algorithm, then the property of empirical γ-weak learnability is guaranteed, with γ = θ/.

[Formalisation] 95. Suppose we are given a training set S = {(x,y ),...,(x m,y m )}, such that for some weak hypotheses h,...,h k from the hypothesis space H, and some nonnegative coefficients α,...,α k with k j= α j =, there exists θ > 0 such that y i ( k α j h j (x i )) θ, (x i,y i ) S. j= Note: according to CMU, 06 spring, W. Cohen, N. Balcan, HW4, pr. 3.3, y i ( k j= α j h j (x i )) = Margin k (x i ) = f k (x i ), where f k (x i ) not. = k α j h j (x i ). j= Key idea: We will show that if the condition above is satisfied (for a given k), then for any distribution D over S, there exists a hypothesis h l {h,...,h k } with weighted training error at most θ over the distribution D. It will follow that when the condition above is satisfied for any k, the training set S is empirically γ-weak learnable, with γ = θ.

96. a. Show that if the condition stated above is met there exists a weak hypothesis h l from {h,...,h k } such that E i D [y i h l (x i )] θ. Hint: Taking expectation under the same distribution does not change the inequality conditions. b. Show that the inequality E i D [y i h l (x i )] θ is equivalent to Pr i D [y i h l (x i )] θ, meaning that the weighted training error of h l is at most θ, and therefore γ t θ.

Solution 97. a. Since y i ( k j= α jh j (x i )) θ y i f k (x i ) θ for i =,...,m, it follows (according to the Hint) that E i D [y i f k (x i )] θ where f k (x i ) not. = k α j h j (x i ). (5) On the other side, E i D [y i h l (x i )] θ def. m i= y ih l (x i ) D(i) θ. Suppose, on contrary, that E i D [y i h l (x i )] < θ, that is m i= y ih l (x i ) D(i) < θ for l =,...,k. Then m i= y ih l (x i ) D(i) α l < θ α l for l =,...,k. By summing up these inequations for l =,...,k we get ( k m k m k ) k y i h l (x i ) D(i) α l < θ α l y i D(i) h l (x i )α l < θ α l l= i= l= i= j= l= m y i f k (x i ) D(i) < θ, (6) i= because k j= α j = şi f k (x i ) not. = k l= α lh l (x i ). The inequation (6) can be written as E i D [y i f k (x i )] < θ. Obviously, it contradicts the relationship (5). Therefore, the previous supposition is false. In conclusion, there exist l {,...,k} such that E i D [y i h l (x i )] θ. l=

98. Solution (cont d) b. We already said that E i D [y i h l (x i )] θ m i= y ih l (x i ) D(i) θ. Since y i {,+} and h l (x i ) {,+} for i =,...,m and l =,...,k, we have m y i h l (x i ) D(i) θ i= D(x i ) D(x i ) θ ( ε l ) ε l θ i:y i =h l (x i ) i:y i h l (x i ) ε l θ ε l θ ε l θ def. Pr i D [y i h l (x i )] θ.

99. AdaBoost: Any set of consistently labelled instances from R is empirically γ-weak learnable by using decision stumps Stanford, 06 fall, Andrew Ng, John Duchi, HW, pr. 6.abc

00. At CMU, 05, Z. Bar-Joseph, E. Xing, HW4, pr..5 we encountered the notion of empirical γ-weak learnability. When this condition γ γ t for all t, where γ t def. = ε t, with ε t being the weighted training error produced by the weak hypothesis h t is met, it ensures that AdaBoost will drive down the training error quickly. In this problem we will assume that our input attribute vectors x R, that is, they are one-dimensional, and we will show that [LC] when these vectors are consitently labelled, decision stumps based on thresholding provide a weaklearning guarantee (γ).

Decision stumps: analytical definitions / formalization 0. Thresholding-based decision stumps can be seen as functions indexed by a threshold s and sign +/, such that φ s,+ (x) = { if x s if x < s and φ s, (x) = { if x s if x < s. Therefore, φ s,+ (x) = φ s, (x). Key idea for the proof We will show that given a consistently labelled training set S = {(x,y ),...,(x m,y m )}, with x i R and y i {,+} for i =,...,m, there is some γ > 0 such that for any distribution p defined on this training set there is a threshold s R for which error p (φ s,+ ) γ or error p(φ s, ) γ, where error p (φ s,+ ) and error p (φ s, ) denote the weighted training error of φ s,+ and respectively φ s,, computed according to the distribution p.

0. Convention: In our problem we will assume that our training instances x,...x m R are distinct. Moreover, we will assume (without loss of generality, but this makes the proof notationally simpler) that x > x >... > x m. a. Show that, given S, for each threshold s R there is some m 0 (s) {0,,...,m} such that m error p (φ s,+ ) def. = p i {yi φ s,+ (x i )} = m 0 (s) m y i p i y i p i i= i= i=m 0 (s)+ }{{} not.: f(m 0 (s)) and m error p (φ s, ) def. = p i {yi φ s, (x i )} = m m 0 (s) y i p i y i p i i= i=m 0 (s)+ i= }{{} not.: f(m 0 (s)) Note: Treat sums over empty sets of indices as zero. Therefore, 0 i= a i = 0 for any a i, and similarly m i=m+ a i = 0.

03. b. Prove that, given S, there is some γ > 0 (which may depend on the training set size m) such that for any set of probabilities p on the training set (therefore p i 0 and m i= p i = ) we can find m 0 {0,...,m} so as f(m 0 ) γ, where f(m 0 ) not. = m 0 y i p i m y i p i, i= i=m 0 (s)+ Note: γ should not depend on p. Hint: Consider the difference f(m 0 ) f(m 0 ). What is your γ?

04. c. Based on your answers to parts a and b, what edge can thresholded decision stumps guarantee on any training set {x i,y i } m i=, where the raw attributes x i R are all distinct? Recall that the edge of a weak classifier φ : R {,} is the constant γ (0,/) such that error p (φ) def. = m p i {φ(xi ) y i } γ. i= d. Can you give an upper bound on the number of thresholded decision stumps required to achieve zero error on a given training set?

Solution 05. a. We perform several algebraic steps. Let sign(t) = if t 0, and sign(t) = otherwise. Then {φs,+ (x) y} = {sign(x s) y} = {y sign(x s) 0}, where the symbol { } denotes the well known indicator function. Thus we have error p (φ s,+ ) def. = = m m p i {yi φ s,+ (x i )} = p i {yi sign(x i s) 0} i= i= p i {yi = } + i:x i s i:x i <s p i {yi =} Thus, if we let m 0 (s) be the index in {0,...,m} such that x i s for i m 0 (s) and x i < s for i > m 0 (s), which we know must exist because x > x >..., we have error p (φ s,+ ) def. = m p i {yi φ s,+ (x i )} = i= m 0 (s) i= p i {yi = } + m i=m 0 (s)+ p i {yi =}.

06. Now we make a key observation: we have {y= } = y because y {,}. and {y=} = +y, Consequently, error p (φ s,+ ) def. = m 0 (s) m p i {yi φ s,+ (x i )} = i= = p i y i + i= = m 0 (s) p i y i i= i=m 0 (s)+ m 0 (s) i= m p i +y i m p i y i. i=m 0 (s)+ p i {yi = } + = The last equality follows because m i= p i =. m p i i= m i=m 0 (s)+ m 0 (s) i= p i y i + p i {yi =} The case for φ s, is symmetric to this one, so we omit the argument. m i=m 0 (s)+ p i y i

Solution (cont d) 07. b. For any m 0 {,...,m} we have f(m 0 ) f(m 0 ) = m 0 i= y i p i m i=m 0 + y i p i m 0 i= y i p i + m i=m 0 y i p i = y m0 p m0. Therefore, f(m 0 ) f(m 0 ) = y m0 p m0 = p m0 for all m 0 {,...,m}. Because m i= p i =, there must be at least one index m 0 with p m 0 m. Thus we have f(m 0 ) f(m 0 ), and so it must be the case that at least m one of f(m 0 ) m or f(m 0 ) m holds. Depending on which one of those two inequations is true, we would then return m 0 or m 0. (Note: If f(m 0 ) m and m 0 =, then we have to consider an outside threshold, s > x.) Finally, we have γ = m.