18.6 Decision Trees

20210103

Representation Method Measure
Tree Recursive Partitioning Information Gain

To build a decision tree we typically use rpart::rpart().

mtype <- "rpart"
mdesc <- "decision tree"

ds %>%
  select(all_of(vars)) %>%
  slice(tr) %>%
  rpart(form, ., method="class", control=rpart.control(maxdepth=3)) %T>%
  print() ->
model
## n= 145946 
## 
## node), split, n, loss, yval, (yprob)
##       * denotes terminal node
## 
##  1) root 145946 31010 No (0.7875242 0.2124758)  
##    2) humidity_3pm< 71.5 122254 16843 No (0.8622295 0.1377705) *
##    3) humidity_3pm>=71.5 23692  9525 Yes (0.4020344 0.5979656)  
##      6) humidity_3pm< 82.5 12923  5906 No (0.5429854 0.4570146)  
##       12) rainfall< 2.05 8400  3098 No (0.6311905 0.3688095) *
##       13) rainfall>=2.05 4523  1715 Yes (0.3791731 0.6208269) *
##      7) humidity_3pm>=82.5 10769  2508 Yes (0.2328907 0.7671093) *

Chapter 20 covers decision trees in detail whilst Chapter 14 uses decision trees as the model builder to demonstrate the model template. Examples of decision tree induction are available through the rain, iris, and pyiris packages from MLHub.



Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0