Tree-based methods. Patrick Breheny. December 4. Recursive partitioning Bias-variance tradeoff Example Further remarks

Similar documents
the tree till a class assignment is reached

Classification and Regression Trees

Learning Decision Trees

CS6375: Machine Learning Gautam Kunapuli. Decision Trees

CS 6375 Machine Learning

SF2930 Regression Analysis

Classification: Decision Trees

Decision Trees. Each internal node : an attribute Branch: Outcome of the test Leaf node or terminal node: class label.

Decision Tree Learning

Artificial Intelligence Decision Trees

Supervised Learning! Algorithm Implementations! Inferring Rudimentary Rules and Decision Trees!

Decision Trees Part 1. Rao Vemuri University of California, Davis

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

Decision Tree Analysis for Classification Problems. Entscheidungsunterstützungssysteme SS 18

Algorithms for Classification: The Basic Methods

Learning Decision Trees

Decision Trees. Tirgul 5

Statistical Consulting Topics Classification and Regression Trees (CART)

Model comparison. Patrick Breheny. March 28. Introduction Measures of predictive power Model selection

Generalization to Multi-Class and Continuous Responses. STA Data Mining I

Statistics and learning: Big Data


Dan Roth 461C, 3401 Walnut

Induction of Decision Trees

Decision trees. Special Course in Computer and Information Science II. Adam Gyenge Helsinki University of Technology

Decision Support. Dr. Johan Hagelbäck.

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

Classification and regression trees

Machine Learning 2nd Edi7on

Informal Definition: Telling things apart

Introduction to Machine Learning CMU-10701

Decision Trees. Gavin Brown

Regression tree methods for subgroup identification I

Decision Tree And Random Forest

The Solution to Assignment 6

Decision Trees. CS57300 Data Mining Fall Instructor: Bruno Ribeiro

Lecture 7: DecisionTrees

Machine Learning 3. week

2018 CS420, Machine Learning, Lecture 5. Tree Models. Weinan Zhang Shanghai Jiao Tong University

Bagging. Ryan Tibshirani Data Mining: / April Optional reading: ISL 8.2, ESL 8.7

Decision Trees. Danushka Bollegala

Machine Learning & Data Mining

Machine Learning Recitation 8 Oct 21, Oznur Tastan

Decision Trees. Data Science: Jordan Boyd-Graber University of Maryland MARCH 11, Data Science: Jordan Boyd-Graber UMD Decision Trees 1 / 1

EECS 349:Machine Learning Bryan Pardo

Knowledge Discovery and Data Mining

Data Mining Classification: Basic Concepts and Techniques. Lecture Notes for Chapter 3. Introduction to Data Mining, 2nd Edition

CS145: INTRODUCTION TO DATA MINING

UVA CS 4501: Machine Learning

Decision Tree Learning Mitchell, Chapter 3. CptS 570 Machine Learning School of EECS Washington State University

Decision Tree Learning

Jeffrey D. Ullman Stanford University

Ensemble Methods. Charles Sutton Data Mining and Exploration Spring Friday, 27 January 12

Announcements Kevin Jamieson

CART Classification and Regression Trees Trees can be viewed as basis expansions of simple functions. f(x) = c m 1(x R m )

Lecture 24: Other (Non-linear) Classifiers: Decision Tree Learning, Boosting, and Support Vector Classification Instructor: Prof. Ganesh Ramakrishnan

Regression and Classification Trees

Decision Trees.

Classification: Rule Induction Information Retrieval and Data Mining. Prof. Matteo Matteucci

Imagine we ve got a set of data containing several types, or classes. E.g. information about customers, and class=whether or not they buy anything.

Lecture 3: Decision Trees

University of Alberta

Mining Classification Knowledge

Random Forests. These notes rely heavily on Biau and Scornet (2016) as well as the other references at the end of the notes.

Growing a Large Tree

( D) I(2,3) I(4,0) I(3,2) weighted avg. of entropies

Apprentissage automatique et fouille de données (part 2)

Tutorial 6. By:Aashmeet Kalra

Decision Tree Learning

Machine Learning and Data Mining. Decision Trees. Prof. Alexander Ihler

Decision Trees.

Mining Classification Knowledge

Ensemble Methods and Random Forests

Decision Trees. CS 341 Lectures 8/9 Dan Sheldon

Inteligência Artificial (SI 214) Aula 15 Algoritmo 1R e Classificador Bayesiano

Reminders. HW1 out, due 10/19/2017 (Thursday) Group formations for course project due today (1 pt) Join Piazza (

Decision Trees Entropy, Information Gain, Gain Ratio

Artificial Intelligence

Data classification (II)

Data Mining Classification: Basic Concepts, Decision Trees, and Model Evaluation

Two-sample Categorical data: Testing

Administrative notes. Computational Thinking ct.cs.ubc.ca

Information Theory & Decision Trees

day month year documentname/initials 1

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

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

Decision Tree Learning Lecture 2

Decision trees COMS 4771

Chapter 10 Logistic Regression

Classification Using Decision Trees

Semiparametric Regression

CLUe Training An Introduction to Machine Learning in R with an example from handwritten digit recognition

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

Bayesian Learning. Artificial Intelligence Programming. 15-0: Learning vs. Deduction

Decision-Tree Learning. Chapter 3: Decision Tree Learning. Classification Learning. Decision Tree for PlayTennis

Classification II: Decision Trees and SVMs

Data Mining Classification Trees (2)

Symbolic methods in TC: Decision Trees

Decision Tree Learning

Oliver Dürr. Statistisches Data Mining (StDM) Woche 11. Institut für Datenanalyse und Prozessdesign Zürcher Hochschule für Angewandte Wissenschaften

Transcription:

Tree-based methods Patrick Breheny December 4 Patrick Breheny STA 621: Nonparametric Statistics 1/36

Introduction Trees Algorithm We ve seen that local methods and splines both operate locally either by using kernels to introduce local weights or by using piecewise basis functions Either way, the kernels/basis functions were prespecified i.e., the basis functions are defined and weights given to observations regardless of whether they are needed to improve the fit or not Another possibility is to use the data to actively seek partitions which improve the fit as much as possible This is the main idea behind tree-based methods, which recursively partition the sample space into smaller and smaller rectangles Patrick Breheny STA 621: Nonparametric Statistics 2/36

Trees Algorithm To see how this works, consider a linear regression problem with a continuous response y and two predictors x 1 and x 2 We begin by splitting the space into two regions on the basis of a rule of the form x j s, and modeling the response using the mean of y in the two regions The optimal split (in terms of reducing the residual sum of squares) is found over all variables j and all possible split points s The process is then repeated in a recursive fashion for each of the two sub-regions Patrick Breheny STA 621: Nonparametric Statistics 3/36

Partitioning illustration Trees Algorithm x 2 x 1 Patrick Breheny STA 621: Nonparametric Statistics 4/36

The regression model Trees Algorithm This process continues until some stopping rule is applied For example, letting {R m } denote the collection of rectangular partitions, we might continue partitioning until R m = 1 The end result is a piecewise constant model over the partition {R m } of the form f(x) = m c m I(x R m ) where c m is the constant term for the mth region (i.e., the mean of y i for those observations x i R m ) Patrick Breheny STA 621: Nonparametric Statistics /36

Trees Trees Algorithm The same model can be neatly expressed in the form of a binary tree The regions {R m } are then referred to as the terminal nodes of the tree The non-terminal nodes are referred to as interior nodes The splits are variously referred to as splits, edges, or branches Patrick Breheny STA 621: Nonparametric Statistics 6/36

Trees Algorithm Equivalent tree for example partition x1< 7 x2>=3 R x1< 2 R4 R1 x1< R2 R3 Patrick Breheny STA 621: Nonparametric Statistics 7/36

Trees and interpretability Trees Algorithm The ability to represent the model as a tree is the key to its interpretability and popularity With more than two explanatory variables, the earlier partition diagram becomes difficult to draw, but the tree representation can be extended to any dimension Trees are one of the most easily interpreted statistical methods: no understanding of statistics or even mathematics are required to follow them, and, to some extent, they mimic the way that human beings naturally think about things and make decisions Patrick Breheny STA 621: Nonparametric Statistics 8/36

Artificial example Trees Algorithm I know what the weather is like outside... should I play? outlook sunny overcast rainy humidity yes windy <= 7 > 7 false true yes no yes no Patrick Breheny STA 621: Nonparametric Statistics 9/36

Algorithms vs. models Trees Algorithm Tree-based methods are not statistical models in the traditional sense there is no distribution, no likelihood, no design matrix, none of the things we usually associate with modeling The thinking behind them is really more algorithmic, and treats the mechanism by which the data were generated as unknown and unknowable Admittedly, this is a bit foreign; however, in the words of Leo Breiman, one of the key pioneers of tree-based methods, The statistical community has been committed to the almost exclusive use of data models. This commitment has led to irrelevant theory, questionable conclusions, and has kept statisticians from working on a large range of interesting current problems. Patrick Breheny STA 621: Nonparametric Statistics 1/36

Regression trees Trees Algorithm We now turn to some of the details involved in fitting trees, and begin with the case where our outcome is continuous (such trees are referred to as regression trees) First, note that if we adopt the least squares criterion as our objective, then our estimate for c m is simply the average of the y i s in that region: ĉ m = i y ii(x R m ) i I(x R m) Our task is then to find the optimal splitting variable j and split point s that bring about the largest drop in the residual sum of squares Patrick Breheny STA 621: Nonparametric Statistics 11/36

Regression tree algorithm Trees Algorithm For a given splitting variable j, this amounts to finding the value of s that minimizes (y i ĉ 1 ) 2 + (y i ĉ 2 ) 2 i:x j s i:x j >s This may seem like a burdensome task, but if x j has been sorted already, it can be done rather quickly (Homework) Thus, we simply have to perform the above search for each variable j and then pick the best (j, s) pair for our split Having made this split, we then perform the whole process again on each of the two resulting regions, and so on Patrick Breheny STA 621: Nonparametric Statistics 12/36

Categorical predictors Trees Algorithm In the preceding, we assumed that our predictors were continuous The exact same approach works for ordinal predictors For unordered categorical (i.e. nominal) predictors with q categories, there are 2 q 1 1 possible splits This actually makes things easier when q is small, but causes two problems when q is large: The number of calculations grows prohibitive The algorithm favors variables with a large number of possible splits, as the more choices we have, the better chance we can find one that seems to fit the data well Patrick Breheny STA 621: Nonparametric Statistics 13/36

What size tree? Hypothesis testing Cost-complexity pruning How large should our tree be? A small tree might be too simple, while a large tree might overfit the data There are two main schools of thought on this matter: The decision of whether to split or not should be based on a hypothesis test of whether the split significantly improves the fit or not Tree size is a tuning parameter, and we can choose it using methods such as cross-validation Patrick Breheny STA 621: Nonparametric Statistics 14/36

Hypothesis-testing approach Hypothesis testing Cost-complexity pruning The hypothesis-testing approach is straightforward: Carry out an appropriate hypothesis test for each variable If the lowest p-value is significant after adjusting for the number of comparisons, partition the data using the optimal split for the variable with the lowest p-value When no significant variables can be found, stop growing the tree Patrick Breheny STA 621: Nonparametric Statistics /36

Pruning Hypothesis testing Cost-complexity pruning The upside of this approach, of course, is that you get p-values for each split, and they are guaranteed to be significant Furthermore, it alleviates the problem alluded to earlier, whereby explanatory variables with a large number of possible splits are more likely to be selected One downside, however, is that a seemingly unimportant split might lead to a very important split later on An alternative is to grow a large tree, and then use a model-selection criterion to prune the tree back to its optimal size Patrick Breheny STA 621: Nonparametric Statistics 16/36

Rules for growing trees Hypothesis testing Cost-complexity pruning Some common rules for when to stop growing a tree are: When the number of terminal nodes exceeds some cutoff When the number of observations in the terminal nodes reaches some cutoff When the depth of the tree reaches a certain level Denote this tree, the largest tree under consideration, as T Patrick Breheny STA 621: Nonparametric Statistics 17/36

Node impurity Hypothesis testing Cost-complexity pruning Now consider a subtree T that can be obtained by pruning T that is, by collapsing any number of its internal nodes Let T denote the number of terminal nodes in tree T, and index those nodes with m, with node m representing region R m We now define the node impurity measure: Q m (T ) = 1 N m i:x i R m (y i ĉ m ) 2, where N m is the number of observations in node m Patrick Breheny STA 621: Nonparametric Statistics 18/36

Cost-complexity pruning Hypothesis testing Cost-complexity pruning Finally, we define the cost-complexity criterion: C α (T ) = m N m Q m (T ) + α T The tuning parameter α behaves like the other regularization parameters we have seen, balancing stability (tree size) with goodness of fit For any given α, there is a tree T α which minimizes the above criterion As the notation suggests, with α = we get T, the full tree α itself is usually chosen via cross-validation Patrick Breheny STA 621: Nonparametric Statistics 19/36

Cotinine data To get a sense of how trees and their implementations in R work, we now turn to an example involving second hand smoke exposure in children Cotinine is a metabolite of nicotine, and is found in elevated levels in people exposed to second-hand smoke Measurement of cotinine requires lab tests, which cost time and money It is easier, of course, to simply ask parents about the extent of second hand smoke that their children are exposed to but how accurate are their answers? Patrick Breheny STA 621: Nonparametric Statistics 2/36

Cotinine data (cont d) To assess the correspondence (or lack thereof) between self-reported exposure and cotinine levels, the following variables were recorded: SmokerTime: Time spent with smokers (Daily/Intermittent/None) TSHours: Hours/day spent with a smoker Nsmokers: Number of smokers who live in the household PPD: Packs per day smoked by the household PctOut: Percentage of time spent smoking that is done outdoors SHS: Self-reported second-hand smoke exposure (None/Mild/Moderate/Heavy) Patrick Breheny STA 621: Nonparametric Statistics 21/36

Tree packages in R In R, there are two primary packages one can use to fit tree-based models: rpart, which is based on cost-complexity pruning party, which is based on hypothesis test-based stopping The party package has considerably better tools for plotting and displaying trees, but thankfully, we can use these plotting tools to plot trees fit using rpart as well Patrick Breheny STA 621: Nonparametric Statistics 22/36

Usage In rpart, the model-fitting function is rpart: fit <- rpart(cotinine~., data=shs) In party, the model-fitting function is ctree: fit <- ctree(cotinine~., data=shs) Patrick Breheny STA 621: Nonparametric Statistics 23/36

Cost-complexity pruning In party, the algorithm stops automatically when further splits no longer significantly improve the fit In rpart, one still has to prune the tree after it has been grown Thankfully, rpart carries out cross-validation for you and stores the results in fit$cptable α is referred to as cp, and the cross-validation error is xerror Patrick Breheny STA 621: Nonparametric Statistics 24/36

Cost-complexity pruning.12.43.21.3.36 In sample Cross validated Relative error.6.7.8.9 1. 1.1 1.2 1.3 Relative error.6.7.8.9 1. 1.1 1.2 1.3 1 2 3 4 6 7 Size of tree 1 2 3 4 6 7 Size of tree alpha <- fit$cptable[which.min(fit$cptable[,"xerror"]),"cp"] fit <- prune(fit,alpha) Patrick Breheny STA 621: Nonparametric Statistics 2/36

Original and pruned trees SHS SHS Mild, None Heavy, Moderate SmokerTime TSHours Mild, None Heavy, Moderate Intermittent, None Daily SmokerTime TSHours TSHours PctOut < 1.7 >= 1.7 >=.7<.7 Intermittent, NoneDaily >=.7 <.7 PctOut >= 8 < 8 2 n = 89 2 n = 26 2 n = 9 2 n = 11 >= 8 < 8 2 2 2 2 2 n = 74 n = 8 2 n = 7 2 n = 7 2 n = 19 2 n = 9 2 2 n = 11 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 1 Patrick Breheny STA 621: Nonparametric Statistics 26/36

Plotting trees rpart comes with its own plotting method: plot(fit) text(fit) However, the end result is not particularly beautiful The plotting functions in party are much nicer; thankfully, you can use party s tools to plot rpart objects using the package partykit: require(partykit) plot(as.party(fit)) Patrick Breheny STA 621: Nonparametric Statistics 27/36

Plotting trees (cont d) SHS=Mild,None SHS Mild, None Heavy, Moderate SmokerTime TSHours Intermittent, NoneDaily >=.7 <.7 n = 89 n = 26 n = 9 n = 11 2 2 2 2 2 2 2 2 SmokerTime=Intermittent,None TSHours>=.7 1 1 1 1 1.228 3.433.61 1.36 Patrick Breheny STA 621: Nonparametric Statistics 28/36

rpart vs. ctree SHS PPD p <.1 2 > 2 Mild, None Heavy, Moderate SHS p <.1 SmokerTime TSHours Moderate {Mild, None} Intermittent, NoneDaily >=.7 <.7 SmokerTime p =. n = 89 n = 26 n = 9 n = 11 2 2 2 2 Daily{Intermittent, None} 2 2 2 2 2 n = 11 2 n = 26 2 n = 89 2 n = 9 2 2 2 2 1 1 1 1 1 1 1 1 Patrick Breheny STA 621: Nonparametric Statistics 29/36

Classification trees Classification trees Pros and cons of tree-based methods Tree-based methods can be extended to categorical outcomes as well; these are referred to as classification trees The main idea is the same: we recursively partition the sample space, fitting a very simple model in each partition In the case of classification, our model is to simply use the observed proportions, estimating Pr(G = k x) by ˆπ mk I(x R m ), m Patrick Breheny STA 621: Nonparametric Statistics 3/36

Node impurity Classification trees Pros and cons of tree-based methods Besides the model being fit at each node, the only other difference is the criterion used for splitting and pruning There are three commonly used measures of node impurity Q m (T ) for classification trees: Misclassification error: Gini index: Deviance: 1 N m I(y i arg max kˆπ mk ) i R m ˆπ mk (1 ˆπ mk ) k k ˆπ mk log(ˆπ mk ) All three are similar, but the Gini index and deviance are differentiable, and thus easier to optimize numerically Patrick Breheny STA 621: Nonparametric Statistics 31/36

Assumption-free Classification trees Pros and cons of tree-based methods Perhaps the primary advantage of tree-based methods is that they are virtually assumption-free Consequently, they are very simple to fit and interpret, since no time or effort has to go into making, checking, or explaining assumptions Furthermore, they are capable of discovering associations, such as higher-order interactions, that would otherwise go utterly unsuspected Patrick Breheny STA 621: Nonparametric Statistics 32/36

Missing data Classification trees Pros and cons of tree-based methods In addition, trees have a rather elegant option for handling missing data besides the usual options of discarding or imputing observations For a given split, we can find surrogate splits, which best mimic the behavior of the original split Then, when sending an observation down the tree, if the splitting variable is missing, we simply use the surrogate split instead Patrick Breheny STA 621: Nonparametric Statistics 33/36

Instability of trees Classification trees Pros and cons of tree-based methods The primary disadvantage of trees is that they are rather unstable (i.e., have high variance) In other words, small change in the data often results in a completely different tree something to keep in mind while interpreting trees One major reason for this instability is that if a split changes, all the splits under it are changes as well, thereby propagating the variability A related methodology, random forests, uses the bootstrap to grow a large number of trees and then averages across them in order to stabilize the tree-based approach, although obviously there is a cost as far as interpretation is concerned Patrick Breheny STA 621: Nonparametric Statistics 34/36

Classification trees Pros and cons of tree-based methods Difficulty in capturing additive structure In addition, trees have a difficult time capturing simple additive structures:..2.4.6.8 1. 2 2 4 6 x y Patrick Breheny STA 621: Nonparametric Statistics 3/36

Concluding remarks Classification trees Pros and cons of tree-based methods In some sense, the weaknesses of tree-based methods are precisely the strengths of linear models, and vice versa For this reason, I personally have often found the two methods to be useful complements to each other For example, when embarking on an extensive analysis using a linear or generalized linear model, it doesn t hurt to check your results against a regression tree If you find that the regression tree chooses a very different set of important variables and achieves a much better R 2, you may want to reconsider the additive model Patrick Breheny STA 621: Nonparametric Statistics 36/36