Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Plotting decision trees in R with rpart

I'm working on a project and I need to be able to make some decision trees based on a dataset I've imported into R. Using the rpart package, I'd like to be able to create a pair of decision trees, one using the gini split criteria and the other using the entropy split criteria. I'd also like to be able to adjust the maximum tree depth if possible. Does anybody know how to do this? I'd greatly appreciate any help!

like image 546
Hoser Avatar asked Feb 23 '13 19:02

Hoser


People also ask

What does rpart plot do in R?

This function combines and extends plot. rpart and text. rpart in the rpart package. It automatically scales and adjusts the displayed tree for best fit.

What is rpart used for in R?

Rpart is a powerful machine learning library in R that is used for building classification and regression trees. This library implements recursive partitioning and is very easy to use.


1 Answers

According to the R manual here, rpart() can be set to use the gini or information (i.e. entropy) split using the parameter:

parms = list(split = "gini"))

or

parms = list(split = "information"))

... respectively.

You can also add parameters for rpart.control (see here) including maxdepth, for which the default is 30.

like image 71
Simon Avatar answered Sep 20 '22 16:09

Simon