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= 151934 
## 
## node), split, n, loss, yval, (yprob)
##       * denotes terminal node
## 
##  1) root 151934 32635 No (0.7852028 0.2147972)  
##    2) humidity_3pm< 71.5 126755 17523 No (0.8617569 0.1382431) *
##    3) humidity_3pm>=71.5 25179 10067 Yes (0.3998173 0.6001827)  
##      6) humidity_3pm< 82.5 13577  6219 No (0.5419459 0.4580541)  
##       12) wind_gust_speed< 42 8259  2998 No (0.6370021 0.3629979) *
##       13) wind_gust_speed>=42 5318  2097 Yes (0.3943212 0.6056788) *
##      7) humidity_3pm>=82.5 11602  2709 Yes (0.2334942 0.7665058) *

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