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= 192787 
## 
## node), split, n, loss, yval, (yprob)
##       * denotes terminal node
## 
##  1) root 192787 41266 No (0.7859503 0.2140497)  
##    2) humidity_3pm< 72.5 163203 23032 No (0.8588751 0.1411249) *
##    3) humidity_3pm>=72.5 29584 11350 Yes (0.3836533 0.6163467)  
##      6) humidity_3pm< 82.5 15378  7234 No (0.5295877 0.4704123)  
##       12) wind_gust_speed< 42 9292  3508 No (0.6224709 0.3775291) *
##       13) wind_gust_speed>=42 6086  2360 Yes (0.3877752 0.6122248) *
##      7) humidity_3pm>=82.5 14206  3206 Yes (0.2256793 0.7743207) *

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