Growing trees with tree and rpart

There are no big differences between growing trees with tree or rpart. Both work in similar ways and both depend on the dtree package, more or less. As the time-cost of growing trees is often too small, I can't see a reason not to try both, hence explaining how to grow trees using both.

The following shows how to recursively grow a decision-tree model using the tree package:

if(!require(tree)){install.packages('tree')}library(tree)tree_tree <- tree(vote ~ . ,                  data = dt_Chile[-i_out,],                  method = 'class',                  mindev = 0) 

The very first couple of lines are performing a check-install on the tree package and then loading and attaching the whole package. After these two lines, an object called tree_tree is being created. ...

Get Hands-On Data Science with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.